简体   繁体   English

错误:字段列表中的未知列

[英]Error: Unknown column in field list

While running the below script it shows the errorError: Unknown column 'email' in 'field list'. 运行以下脚本时,它会在“字段列表”中显示errorError:未知列'email'。

  <?php
  include("connect.php");

  if($loggedin == '1')
  die("You can't register another account while you're logged in.");

  if(isset($_POST['submit']))
  {

  $uname = trim($_POST['username']);

 if($_POST["regkey"]!="171717")
 die("Invalid Registration Key. <br> <a href= register.php>Back</a>");

 if($_POST["pass"]!=$_POST["pass2"])
 die("Passwords do not match. <br> <a href= register.php>Back</a>");

 // Make sure all forms were filled out.

 if((!isset($_POST['username'])) || (!isset($_POST['pass']))
 || ($uname == '') || ($_POST['pass'] == ''))
 die("Please fill out the form completely. <br><br>
 <a href=register.php>Continue</a>");


 $check = @mysql_query("SELECT id FROM players WHERE username = '$uname'");
 $check = @mysql_num_rows($check);

 if($check > 0)
 die("Sorry, that username has already been taken. Please try again.
 <br><br>
 <a href=register.php>Continue</a>");


 $pass = md5($_POST['pass']);

 $date = date("m/d/y");


 $newPlayer = @mysql_query("INSERT INTO players (username, password,   

registered,callname,email) VALUES   ('$uname','$pass','$date','$_POST

[callname]','$_POST[email]')") or die("Error: ".mysql_error());

echo 'You have been registered! You may now <a href=index.php>Log in</a>.';


}
else
{

// A simple example of a form.

echo '
<center>
<form action=register.php method=post>
<p>Registration is currently<b> NOT OPEN.</b><br>
 You must have a valid Registration key to register.</p>
 <table border="2">
 <tr>
<td>Username:</td><td><input type="text" name="username" size="20px"</input>
</td>
</tr>
<tr>
<td>Callname:</td><td><input type="text" name="callname" size="20px"</input>
</td>
</tr>
<tr>
<td>Password:</td><td><input type="password" name="pass" size="20px"</input>
</td>
</tr>
<tr>
<td>Re-type Password:</td><td><input type="password" name="pass2" size="20px"</input>  
</td>  </tr>
<tr>
<td>Email:</td><td><input type="text" name="email" size="20px"</input></td>
</tr>
<tr><td>Registration Key:</td><td><input type="text" name="regkey" size="20px"></input>                                                                                         

 </td>    </tr>
 </table>
 <input type="submit" name="submit" value="Submit"></input>
 </form>';

 }


 ?>

I'm very new to PHP and can't figure out why I'm getting this Error. 我是PHP的新手,无法弄清楚为什么我会收到此错误。 Shouldn't the $_POST get that value from the form? $ _POST不应该从表单中获取该值吗? Thanks for reading. 谢谢阅读。

It means your players table does not contain an email column. 这意味着您的players表不包含email列。 You will need to add this column to your table for this script to work. 您需要将此列添加到表中才能使此脚本生效。

So the incorrect part in your code is 所以代码中的错误部分是

$newPlayer = @mysql_query("INSERT INTO players(username, password, registered, callname, email)
                           VALUES('$uname', '$pass', '$date', '$_POST[callname]', '$_POST[email]')") or die("Error: ".mysql_error());
  1. Add an email field in your player table. 在播放器表格中添加email字段。
  2. Chances are there you misspelled email in the player. 有可能你在播放器中拼错了email
$sql = "INSERT INTO user_registration (u_name,s_father,s_schoolname,s_rollno,s_class)
VALUES ($name,$father,$school,$rollno,$class)";

Error: INSERT INTO user_registration (u_name,s_father,s_schoolname,s_rollno,s_class) VALUES (Azhar, hassan, Chulli_payaan,1008,10th) Unknown column 'Azhar' in 'field list' 错误:INSERT INTO user_registration(u_name,s_father,s_schoolname,s_rollno,s_class)VALUES(Azhar,hassan,Chulli_payaan,1008,10th)'字段列表'中的未知列'Azhar'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM