Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.4k views
in Technique[技术] by (71.8m points)

mysql - php UPDATE QUERY fail my_fetch_array

I am trying to update my supplier information within a form

Here is my my code for the editsupplier form

<?php   
$SupplierID = $_GET['SupplierID'] = $row['SupplierID'];
//Connect and select a database
mysql_connect ("localhost", "root", "");
mysql_select_db("supplierdetails");
//Run query
$result1 = mysql_query("SELECT * FROM suppliers WHERE SupplierID=$SupplierID"); 
while($row = mysql_fetch_array($result1)){
$SupplierID = $_GET['SupplierID'] = $row['SupplierID']; 
$SupplierName = $row['SupplierName'];
$Currency = $row['Currency'];
$Location = $row['Location'];
$ContactNumber = $row['ContactNumber'];
$Email = $row['Email'];
  }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-    strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
 <meta name="description" content="" />
 <meta name="keywords" content="" />
<meta name="author" content="" />
 <link rel="stylesheet" type="text/css" href="style.css" media="screen" />
 <title>Harrison Spinks</title>
  </head>
   <body>
   <div id="wrapper">
 <?php include('includes/header.php'); ?> 
 <?php include('includes/nav.php'); ?>
 <div id="content">
 <h3><center>Edit Supplier Information</center></h3>
<p>Please enter all the following details to edit a supplier</p>
 </div>
<div>
 <br>
 </br>
<form action="Edit_Supp.php" method="post">
 <br>
 </br>
 <input type="hidden" name="SupplierID" value="<?php echo $SupplierID;?>"/> 

 Supplier Name: <input type="text" name="SupplierName" value="<?php echo $SupplierName ;?>" />
 <br>
 </br>
 Currency: <input type="text" name="Currency" value="<?php echo $Currency ;?>" />
 <br>
 </br>
  Location: <input type="text" name="Location" value="<?php echo $Location ;?>" />
  <br>
  </br>
 Contact Number:<input type="text" name="ContactNumber" value="<?php echo $ContactNumber ;?>" /> 
<br>
</br>
 Email:<input type="text" name="Email" value="<?php echo $Email ;?>" />
 <br>
 </br>
 <input type="submit" value= "Edit Supplier Information"/>

 </form>
 </div>
</body>
 </html> 

Errors are:

Notice: Undefined variable: row in E:xampphtdocsEditSupForm.php on line 2
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in E:xampphtdocsEditSupForm.php on line 8

This is the code behind the form:

<?php
 $con = mysql_connect("localhost", "root", "");  
    mysql_select_db("supplierdetails");   
      if (!$con)     
          {       
        die('Could not connect: ' . mysql_error());        
         }    
  //Run a query        
    $SupplierID= $_POST['SupplierID'] = $row ["SupplierID"];
$result1 = mysql_query ("SELECT * FROM suppliers WHERE SupplierID= '".$SupplierID."'")         or die(mysql_error());     
$row = mysql_fetch_array($result1); 
$SupplierID = $_POST['SupplierID'] = $row ["SupplierID"];
$SupplierName = $_POST['SupplierName'];
$Currency = $_POST['Currency'];
$Location = $_POST['Location'];
$ContactNumber = $_POST['ContactNumber'];
$Email = $_POST['Email'];  
$SupplierID = $row['SupplierID'];         
    $query = "UPDATE suppliers SET SupplierID = '".$SupplierID."', SupplierName= '".$SupplierName."', Currency = '".$Currency."', Location = '".$Location."', ContactNumber = '".$ContactNumber."', Email = '".$Email."' WHERE SupplierID = '".$id."'";     
$result1 = mysql_query($query);           
//Check whether the query was successful or not    
 if($result1) 
 {          
 echo "Supplier Updated"; 
 header ("Location: Supplier.php");    
 }
else 
{        
 die ("Query failed");    
  }    
 ?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In both of your code you are using $row ["SupplierID"]; before performing mysql query, `$row ["SupplierID"];' thats why your are getting errors.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...