Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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:\xampp\htdocs\EditSupForm.php on line 2
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in E:\xampp\htdocs\EditSupForm.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");    
  }    
 ?>
share|improve this question
$row is undefined... – Uriel_SVK Apr 20 '12 at 9:28
where will i define this? and how? – Natalie Webb Apr 20 '12 at 9:29
in line 2 and check my answer – Uriel_SVK Apr 20 '12 at 9:31
why you are using like this $SupplierID= $_POST['SupplierID'] = $row ["SupplierID"]; in first line after db connection. Here what is $row ["SupplierID"]; – nithi Apr 20 '12 at 9:31
i basically want all of the details to be inputted into the text fields so i thought that this would retrieve that data so i can then edit it. – Natalie Webb Apr 20 '12 at 9:40
show 1 more comment

1 Answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.