我有两个表: word(id,word,meaning) 和 userword(id,wordid,userid) 在他们两个 id 是自动递增的。在一个表单中,我从用户那里得到单词和含义,然后我想把这个单词插入到这些表中。插入单词效果很好,但要插入用户词,我必须从单词中获取 wordid,然后插入用户词,但它在这里不起作用是我的表单:
<form action="InsertWord.php" method="post">
<input name="word" id="word" type="text" maxlength="255" />
<label for="user">:word</label></br></br>
<input name="meaning" id="mean" type="text" maxlength="255" />
<label for="pass">:meaning</label></br></br>
<input type="submit" value="insert" /></br></br>
</form>
和 InsertWord.php:
<?php
session_start();
$con = mysql_connect("localhost", "root", "")
or die(mysql_error());
if (!$con) {
die('Could not connect to MySQL: ' . mysql_error());
}
mysql_select_db("project", $con)
or die(mysql_error());
if(isset($_POST["word"]) && isset($_POST["meaning"]))
{
$word = $_POST["word"];
$meaning = $_POST['meaning'];
$user= $_SESSION['userid'];
mysql_query("INSERT INTO words (word,meaning) values ('".$word."','".$meaning."')") or die(mysql_error());
$qwordid = mysql_query("SELECT id FROM words WHERE word='$word'") or die(mysql_error());
$fwordid = mysql_fetch_array($qwordid);
$wordid= $fwordid['id'];
mysql_query("INSERT INTO userword (user_id,word_id) values ('".$user."','".$wordid."')") or die(mysql_error());
//HEADER('LOCATION: InsertIntoUserword.php');
}
else
die('wrong!');
?>
因为我插入单词然后数据库没有刷新它对用户词不起作用我该怎么办?