我想在数据库中插入2个值,我想给每个$ userid一个$ teamid,以便用户连接到一个团队。
但每当我运行它时,我都不会在数据库中看到它。
<?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
}
?>
当我输入7到userid时,我从查询中得到的回声,在teamid中输入2:
INSERT INTO team_users(userid,teamid)VALUES('7','2')
答案 0 :(得分:1)
更改此
$query ="INSERT INTO team_users (userid, teamid, ) VALUES ('$userid','$teamid')";
^----remove the , here
到
$query ="INSERT INTO team_users (userid, teamid ) VALUES ('$userid', '$teamid')";