我正在尝试根据某些条件将数据插入到新表中。 Iam从现有表中获取此数据,然后将其存储在变量中。并使用这些变量,将其插入新表中。数据存储在变量中,但插入查询不起作用。 if和else循环也都被执行了。 - >
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM creg";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
echo "id: " . $row["id"]. " - Name: " . $row["c_fname"]. " " . $row["post"]. " " . $row["c_qualification"]. $row["c_moname"]. " ". $row["c_WorkEx"]. "<br>";
$id=$row['id'];
$timestamp=$row['timestamp'];
$post=$row["post"];
$qual=$row["c_qualification"];
$c_fname=$row['c_fname'];
$c_lname=$row['c_lname'];
$c_mname=$row['c_mname'];
$c_moname=$row['c_moname'];
$c_gender=$row['c_gender'];
$c_email=$row['c_email'];
$c_DOB=$row['c_DOB'];
$c_contact=$row['c_contact'];
$c_address=$row['c_address'];
$c_workex=$row['c_WorkEx'];
$servername = "localhost";
if($qual=="B.E." && $post=="Diploma teacher")
{
echo "The trial echo";echo "<br>";
echo $c_workex ,$c_fname, $c_lname;
mysql_query("INSERT INTO eligible (id ,c_fname, c_lname, c_mname, c_moname, c_gender, c_email, c_DOB, c_contact, c_address, c_qualification, c_workex, c_post)
VALUES ('$id','$timestamp','$c_fname','$c_lname','$c_mname','$c_moname','$c_gender','$c_email','$c_DOB','$c_contact','$c_address','$qual','$c_workex','$post')");
}
else
{
echo "Error";
}
}
}
else
{
echo "0 results";
}
$conn->close();
?>
答案 0 :(得分:1)
我注意到了这个错误:
(id ,c_fname, c_lname, c_mname, c_moname, c_gender, c_email, c_DOB, c_contact, c_address, c_qualification, c_workex, c_post)
VALUES ('$id','$timestamp','$c_fname','$c_lname','$c_mname','$c_moname','$c_gender','$c_email','$c_DOB','$c_contact','$c_address','$qual','$c_workex','$post')
现在$timestamp
是额外的,您指定的列数不等于变量数...
答案 1 :(得分:0)