我試圖tomake形式將數據添加到我的資料庫,並即時得到一個錯誤將數據添加到MySQL數據庫
「無法輸入數據:您的SQL語法錯誤;檢查手冊這對應於您的MySQL服務器版本的正確語法使用附近')VALUES('s','d','f','g','h')'在第1行「
這裏是使用
<html>
<head>
<title>Add New Record in MySQL Database</title>
</head>
<body>
<?php
if(isset($_POST['add']))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn)
{
die('Could not connect: ' . mysql_error());
}
if(! get_magic_quotes_gpc())
{
$make = addslashes ($_POST['make']);
$model = addslashes ($_POST['model']);
$value = addslashes ($_POST['value']);
$bcosts = addslashes ($_POST['bcosts']);
}
else
{
$make = $_POST['make'];
$model = $_POST['model'];
$value = $_POST['value'];
$bcosts = $_POST['bcosts'];
}
$rcosts = $_POST['rcosts'];
$sql="INSERT INTO referb (make,model,rcosts,bcosts,value,) VALUES ('$make','$model','$rcosts','$bcosts','$value')";
mysql_select_db('ely');
$retval = mysql_query($sql, $conn);
if(! $retval)
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
}
else
{
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">make</td>
<td><input name="make" type="text" id="make"></td>
</tr>
<tr>
<td width="100">model</td>
<td><input name="model" type="text" id="model"></td>
</tr>
<tr>
<td width="100">repair costs</td>
<td><input name="rcosts" type="text" id="rcosts"></td>
</tr>
<tr>
<td width="100">paid costs</td>
<td><input name="bcosts" type="text" id="bcosts"></td>
</tr>
<tr>
<td width="100">value</td>
<td><input name="value" type="text" id="value"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="add" type="submit" id="add" value="Add">
</td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
我非常新手因此爲什麼我問笑碼IM不要擔心,這會不會成爲一個活的網站:)
只是爲了確保你知道:http://stackoverflow.com/questions/12859942/why-shouldnt -i-use-mysql-functions-in-php –
非常感謝您的支持 - 我是極度新手,並試圖與之交手,我更喜歡手中的方法。似乎還有更多關於這種方式的樣本和教程,然後是新的方法。你提到的方式有沒有簡單的跟隨教程? –