2014-06-19 93 views
-4

我想在數據庫中插入2個值,我想給每個$ userid一個$ teamid,以便用戶連接到一個團隊。在sql中插入錯誤

但是每當我運行它,我都不會在數據庫中看到它。

<?php 
if(isset($_POST['submit'])) 

{ 
$db = mysql_connect("localhost","root","usbw"); 
mysql_select_db("the red socks",$db) or die ("fout: openen db mislukt"); 

$userid = $_POST['userid']; 
$teamid = $_POST['teamid']; 

$query = "INSERT INTO team_users (userid, teamid,) VALUES ('$userid', '$teamid')"; 
echo $query; 
$result = mysql_query($query); 
echo $result; 
} 
else 
{ 
?> 
<form method='post' action=''> 
<table> 
<tr><td>invoegen<br></td></tr> 
<tr><td>User ID</td></tr> 
<tr><td><input name='userid'></td></tr> 
<tr><td>Team ID</td></tr> 
<tr><td><input name='teamid'></td></tr> 
<tr><td><input name='submit' type='submit' value='inloggen'> 
<input type='reset' name='reset'value='wissen'></td></tr> 
</table> 
</form> 
<?php 
} 
?> 

回波餘從查詢得到當我在teamid鍵入7成用戶ID和2:

INSERT INTO team_users(用戶ID,teamid,)VALUES( '7', '2')

+1

爲什麼SQL-Server標記? – Frazz

+0

你有一個,在你之前)...如果你做了'mysql_query(...)或死(mysql_error())'''你可能看到了錯誤信息。 –

+0

刪除最後一個逗號'(userid,teamid,)' –

回答

1

改變這種

$query ="INSERT INTO team_users (userid, teamid,) VALUES ('$userid','$teamid')"; 
               ^----remove the , here 

$query ="INSERT INTO team_users (userid, teamid) VALUES ('$userid', '$teamid')";