-3

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");    
  }    
 ?>
5
  • where will i define this? and how? Commented Apr 20, 2012 at 9:29
  • in line 2 and check my answer Commented Apr 20, 2012 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"]; Commented Apr 20, 2012 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. Commented Apr 20, 2012 at 9:40
  • but currently there error within the text boxes are <br /><b>Notice</b>: Undefined variable: SupplierName in <b>E:\xampp\htdocs\EditSupForm.php</b> on line <b>43</b><br /> Commented Apr 20, 2012 at 9:41

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.