我是新手
下面是我的 HTML PHP 表单
<div id="user">
<form name="booksInput" action="theGamer.php" method="post">
<p>This Section is to add new USer Record in DB</p>
User F Name: <input type="text" name="Fuser">
User L Name: <input type="text" name="Luser">
<?php
$con=mysql_connect("localhost","root","","library");
mysql_select_db("library",$con);
$sqlb = "SELECT * FROM books";
$queryb = mysql_query($sqlb);
while ($resultsb[] = mysql_fetch_object ( $queryb ));
?>
Book Name:<select name="bID">
<?php foreach ( $resultsb as $optionb ) { ?>
<option value="<?php echo $optionb->bID; ?>"><?php echo $optionb->book;?></option>
<?php } ?>
</select><br>
<?php
$con=mysql_connect("localhost","root","","library");
mysql_select_db("library",$con);
$sqlc = "SELECT * FROM country";
$queryc = mysql_query($sqlc);
while ( $resultsc[] = mysql_fetch_object ( $queryc ) );
array_pop($resultsc);
?>
Country Name:<select name="cID">
<?php foreach ( $resultsc as $optionc ) : ?>
<option value="<?php echo $optionc->cID; ?>"><?php echo $optionc->country;?>/option
<?php endforeach; ?>
</select>
<input type="submit" value="Submit" name="subUser">
</form>
</div>
现在,当提交按钮名称sunUser
被按下时theGamer.php
,代码theGamer.php
如下
<?php
$con=mysql_connect("localhost","root","","library");
function insertBook()
{
global $con;
mysql_select_db("library",$con);
$book=mysql_real_escape_string($_POST['books']);
$sql="INSERT INTO books (bID, book) VALUES ('','$book')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error($con));
}`
echo "1 record added";
}
function insertCountry()
{
global $con;
mysql_select_db("library",$con);
$country=mysql_real_escape_string($_POST['country']);
$sql="INSERT into country (cID, country) VALUES ('','$country')";
if (mysql_query($sql,$con))
{
echo "1 record added";
}
else{die('Error: ' . mysql_error($con));}
}
function insertUser()
{
$con=mysql_connect("localhost","root","","library");
mysql_select_db("library",$con);
$Fuser=mysql_real_escape_string($_POST['Fuser']);
$Luser=mysql_real_escape_string($_POST['Luser']);
$bID=mysql_real_escape_string($_POST['bID']);
$cID=mysql_real_escape_string($_POST['cID']);
$sql="INSERT INTO user (userid, uFname,uLname, bID, CID ) VALUES
('','$Fuser','$Luser','bID','cID')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error($con));
}
echo "1 record added";
}
//Code for Knowing which button is pressed
if(isset($_POST['subBooks']))
{
insertBook();
}
if(isset($_POST['subCountry']))
{
insertCountry();
}
if(isset($_POST['subUser']))
{
insertUser();
}
?>
它给出了这个错误 Parse error: parse error, Expecting T_STRING
or T_VARIABLE
or T_NUM_STRING
inC:\wamp\www\library\theGamer.php
在第 20 行,而第 20 行有 np 关注,因为subUser
按钮被按下并且 if 语句必须u=insertuser
运行,为什么它在第 20 行给出错误
问候阿普