Php功能不运行

时间:2013-07-28 07:54:51

标签: php mysql

我是新手

下面是我的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();
 } 
?> 

它给出了这个错误 解析错误:解析错误,在第20行的T_STRING中预期T_VARIABLET_NUM_STRINGC:\wamp\www\library\theGamer.php,因为subUser按钮,第20行有np关注按下并且if语句必须转到u=insertuser函数,为什么它在第20行给出错误

此致 鸭

1 个答案:

答案 0 :(得分:0)

$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));
}`   <---  Here is a rogue quote..

如果StackOverflow发现此问题,则语法高亮显示。你是否也使用带荧光笔的编辑器?

由于代码现在无效,PHP无法解析文件并将失败。您实际上并不执行这段代码并不重要,因为整个文件都已被解析。这与解析代码和代码执行后发生的运行时错误不同。在您的情况下,错误发生在任何PHP代码执行之前。