添加外键后的数据库错误&电话号码没有输入数据库

时间:2015-05-02 22:35:55

标签: php mysql database

这是我的注册表格代码

我只是通过外键将数据库usernames链接到images_tbl。 现在的问题是我使用images_id作为F-Key,现在数据无法输入数据库,导致失败错误。如果我添加一个变量,如下所示          

</head>

<body>
<form name="form1" method="post" action="register.php">
<table align="center" border="1" width="40%">
<tr>
<td>Enter your First Name: </td><td><input type="text" name="fname"></td>
</tr>
<td>Enter your Last Name: </td><td><input type="text" name="lname"></td>
</tr>
<td>Enter your Username: </td><td><input type="text" name="username"></td>
</tr>
<td>Enter your Password: </td><td><input type="password" name="password">    </td>
</tr>
<td>Adtitle: </td><td><input type="text" name="adtitle"></td>
</tr>
<td>Description: </td><td><input type="text" name="description"></td>
</tr>
<td>Email ID: </td><td><input type="text" name="emailid"></td>
</tr>


<?php
error_reporting(E_ALL ^ E_DEPRECATED);
if (isset($_POST["submit"])){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$username = $_POST['username'];
$password = $_POST['password'];
$adtitle = $_POST['adtitle'];
$description = $_POST['description'];
$emailid = $_POST['emailid'];

这里是

$images_id = $_POST['images_id'];

然后它显示一个未定义的变量。电话号码也一样。 它显示连接数据库失败。 如果有任何新列添加到数据库中。

$con = mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('chatbox') or die("cannot select DB");

$query=mysql_query("SELECT * FROM usernames WHERE username='".$username."' AND password='".$password."'");
$numrows=mysql_num_rows($query);
if($numrows==0) /*user doesn't belong to the db*/
{
$sql="INSERT INTO usernames(fname,lname,username,password,adtitle,description,emailid) VALUES ('$fname','$lname','$username','$password','$adtitle','$description','$emailid')";

$result=mysql_query($sql);

if($result)
{
echo "Account Successfully Created";
echo "Login <a href='index.php'> here </a><br>";
}
else
{
echo "Failure!";
}
}
else {
echo "That username already exists! Please try again with another.";
}   
}


?>


<tr>
<td colspan="2"><input type="submit" name="submit" value="Register"></td>
</tr>
<td>
<iframe src="saveimage.php" height="300px" />
</td>
</table>
</form>
</body>

</html>

0 个答案:

没有答案