mysql unknown column查询错误:未知列

时间:2017-06-18 03:00:14

标签: php html mysql database mysqli

所以我试图通过使用表单并填充它来将数据更新到我的数据库中。 问题是它出现了这个错误:

  

查询错误:未知列' customer_id'在' where子句'

我不确定为什么。我的数据库中没有任何内容称为客户ID

这是我的表格代码



<form method="post" action="code/update_cust.php">
 
<h2 id="input_form_heading">Client Update Form:</h2>    

    
<h3>Enter your details into the form and when you are ready click the submit button </h3>

<?php
// Read the values passed in the URL and store in the variable C_num
$C_num = $_GET['id'];
$query = "SELECT * FROM client WHERE C_num='$C_num'"; // run a select query to return the existing data for the record
$results = mysqli_query($conn, $query );
if(!$results) { // capture any errors
echo ("Query error: " . mysqli_error($conn));
}

else {
// fetch and store the results for later use if no errors
while ($row = mysqli_fetch_array($results)) {
$C_num =$row['C_num'];
$C_Firstname = $row['C_Firstname'];
$C_Lastname = $row['C_Lastname'];
$Unitnum = $row['Unitnum'];
$Housenum = $row['Housenum'];
$C_Street = $row['C_Street'];
$C_Suburb = $row['C_Suburb'];
$C_City = $row['C_City'];
$C_Postcode = $row['C_Postcode'];
$C_State = $row['C_State'];
$C_Phone = $row['C_Phone'];
$C_Email = $row['C_Email'];
}


?>
       	<p>Client Number:</p><input type="text" name="cnum" value="<?=$C_num?>"><br>
        <p>First Name:</p><input type="text" name="cfirstname" value="<?=$C_Firstname?>" required><br>
        <p>Last Name:</p><input type="text" name="clastname" value="<?=$C_Lastname?>" required><br>
        <p>Unit Number: </p><input type="text" name="unitnumber" value="<?=$Unitnum?>" ><br>
        <p>House Number: </p><input type="text" name="housenumber" value="<?=$Housenum?>" ><br>
        <p>Street:</p><input type="text" name="street" value="<?=$C_Street?>" required><br>
        <p>Suburb:</p><input type="text" name="suburb" value="<?=$C_Suburb?>" required><br>
        <p>City:</p><input type="text" name="city" value="<?=$C_City?>" required><br>
        <p>Post Code:</p><input type="text" name="postcode" value="<?=$C_Postcode?>" required><br>
        <p>State:</p>    									<select class="form-control" type="text" name="state" value="<?=$C_State?>" ><br> <!-- "form control" and "required" changes the input fields color (see css)-->
																		<option value="">Please choose a state</option>
                                                                        <option value="ACT">ACT</option>
                                                                        <option value="NSW">NSW</option>
                                                                        <option value="NT">NT</option>     
                                                                        <option value="QLD">QLD</option>
                                                                        <option value="SA">SA</option>
                                                                        <option value="TAS">TAS</option>
                                                                        <option value="VIC">VIC</option>
                                                                        <option value="WA">WA</option>
                                                                    </select><br>
        <p>Phone:</p><input type="tel"  name="phone" value="<?=$C_Phone?>" ><br>
        <p>Email:</p><input type="email" name="email" value="<?=$C_Email?>" required><br>
        <br><br>
        
      <input type="submit" name="submit" value= "Update">
		<input type ="reset" name="reset" value ="Reset">
   <?php
   // Redirect the browser window back to the select query page if there are no errors
header("location: display_cust.php");
}
	?>
    </form> 
&#13;
&#13;
&#13;

这是表单

的代码

&#13;
&#13;
<?php
// MySQL Database Connect
require_once("connection.php");
// Read the values passed in the URL and store in the variable C_num
$C_num = $_GET['id'];
 
// read the values from the form and store in variables
$C_num = $_POST['cnum'];
$C_Firstname = $_POST['cfirstname'];
$C_Lastname = $_POST['clastname'];
$Unitnum = $_POST['unitnumber'];
$Housenum = $_POST['housenumber'];
$C_Street = $_POST['street'];
$C_Suburb = $_POST['suburb'];
$C_City = $_POST['city'];
$C_Postcode = $_POST['postcode'];
$C_State = $_POST['state'];
$C_Phone = $_POST['phone'];
$C_Email = $_POST['email'];
 
// escape variables for security
$C_num = mysqli_real_escape_string($conn, $C_num);
$C_Firstname = mysqli_real_escape_string($conn, $C_Firstname);
$C_Lastname = mysqli_real_escape_string($conn, $C_Lastname);
$Unitnum = mysqli_real_escape_string($conn, $Unitnum);
$Housenum = mysqli_real_escape_string($conn, $Housenum );
$C_Street = mysqli_real_escape_string($conn, $C_Street);
$C_Suburb = mysqli_real_escape_string($conn, $C_Suburb);
$C_City = mysqli_real_escape_string($conn, $C_City);
$C_Postcode = mysqli_real_escape_string($conn, $C_Postcode);
$C_State = mysqli_real_escape_string($conn, $C_State);
$C_Phone = mysqli_real_escape_string($conn, $C_Phone);
$C_Email = mysqli_real_escape_string($conn, $C_Email);
 
// update the record from the database corresponding to the primary key value passed in the variable id
$query = "UPDATE FROM client WHERE C_num='$C_num'";
$results = mysqli_query($conn, $query );
if(!$results) {
echo ("Query error: " . mysqli_error($conn));
exit;
}
else {
header("location: ../update_cust1.php");
}
?>
&#13;
&#13;
&#13;

有什么想法吗?我有点困惑

0 个答案:

没有答案