我是新手PHP函數不運行
下面是我的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>
現在當按鈕nameing 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();
}
?>
它給出了這個錯誤 解析錯誤:解析錯誤,期待T_STRING
或T_VARIABLE
或C:\wamp\www\library\theGamer.php
在線20 T_NUM_STRING
wheras行號20有關於因爲subUser
按鈕被按下,if語句一定要去u=insertuser
功能爲什麼它給人錯誤在第20行
問候 鴨
NP關注
[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並被正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到[**警告**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 –
您錯誤信息中解釋了您'E_DOESNT_WORK'的原因。 –
看看stackexchange的語法高亮顯示對你的代碼做了什麼。這應該給你提示有什麼不對。 – Oswald