0
<?php

session_start();

include_once("db_connect.php");

if(isset($_POST['update']))
{
    $ret_id=$_POST['ret_id'];
    $ret_name=$_POST['ret_name'];
    $ret_street=$_POST['ret_street'];
    $ret_city=$_POST['ret_city'];
    $ret_phone=$_POST['ret_phone'];
    $ret_fax=$_POST['ret_fax'];
    $ret_user_fname=$_POST['ret_user_fname'];
    $ret_user_lname=$_POST['ret_user_lname'];
    $ret_email=$_POST['ret_email'];

    // checking empty field
    if(empty($ret_name) || empty($ret_street) || empty($ret_city) || empty($ret_phone) || empty($ret_fax) || empty($ret_user_fname) || empty($ret_user_lname) || empty ($ret_email))
    {

        if(empty($ret_name))
        {
            echo "<font color='red'>Retailer Name field is empty.</font><br/>";
        }
        if(empty($ret_street))
        {
            echo "<font color='red'> Street field is empty.</font><br/>";
        }
        if(empty($ret_city))
        {
            echo "<font color='red'>City field is empty.</font><br/>";
        }
        if(empty($ret_phone))
        {
            echo "<font color='red'>Phone field is empty.</font><br/>";
        }
        if(empty($ret_fax))
        {
            echo "<font color='red'>Fax field is empty.</font><br/>";
        }
        if(empty($ret_user_fname))
        {
            echo "<font color='red'>First Name field is empty.</font><br/>";
        }
        if(empty($ret_user_lname))
        {
            echo "<font color='red'>Last Name field is empty.</font><br/>";
        }
        if(empty($ret_email))
        {
            echo "<font color='red'>Email field is empty.</font><br/>";
        }

    }   
    else
    {   
        //updating the table

        $result=mysql_query("UPDATE tblretailer SET ret_name='".$ret_name."', ret_street='".$ret_street."', ret_city='".$ret_city."', ret_phone='".$ert_phone."', ret_fax='".$ret_fax."', ret_user_fname='".$ret_user_fname."', ret_user_lname='".$ret_user_lname."', ret_email='".$ret_email."' WHERE ret_id='".$ret_id."';");

        //redirectig to the display page. In our case, it is index.php
        header("Location: del_updret.php");
    }
}
?>
<?php

$ret_id = $_GET['ret_id'];

$result=mysql_query("SELECT ret_name, ret_street, ret_city, ret_phone, ret_fax, ret_user_fname, ret_user_lname, ret_email FROM tblretailer where ret_id = ".$ret_id."") or die(mysql_error());

?>
<html>
<title>Edit Product</title>
<body background="Images/contentbg.jpg">
<a href="del_updret.php"><img src="Images/back button.png" width="100" /></a>
<br/><br/>
<form name="edit" method="post" action="updretailer.php">
<table align="center" border="0">
<?php
while($res=mysql_fetch_array($result))
{

    $ret_name=$res['ret_name'];
    $ret_street=$res['ret_street'];
    $ret_city=$res['ret_city'];
    $ret_phone=$res['ret_phone'];
    $ret_fax=$res['ret_fax'];
    $ret_user_fname=$res['ret_user_fname'];
    $ret_user_lname=$res['ret_user_lname'];
    $ret_email=$res['ret_email'];

?>
   <tr> 
    <td>Retailer Name</td>
    <td>
        <input type="text" name="ret_name" value = "<?php echo $ret_name;?>"> </td>
  </tr>
  <tr> 
    <td>Street</td>
    <td>
        <input type="text" name="ret_street" value = "<?php echo $ret_street;?>">     </td>
  </tr>
  <tr> 
    <td>City</td>
    <td>
        <input type="text" name="ret_city" value = "<?php echo $ret_city;?>">     </td>
  </tr>
  <tr> 
    <td>Phone</td>
    <td>
        <input type="text" name="ret_phone" value = "<?php echo $ret_phone;?>">     </td>
  </tr>
  <tr> 
    <td>Fax</td>
    <td>
        <input type="text" name="ret_fax" value = "<?php echo $ret_fax;?>">     </td>
  </tr>
  <tr> 
    <td>First Name</td>
    <td>
        <input type="text" name="ret_user_fname" value = "<?php echo $ret_user_fname;?>">     </td>
  </tr>
  <tr> 
    <td>Last Name</td>
    <td>
        <input type="text" name="ret_user_lname" value = "<?php echo $ret_user_lname;?>">     </td>
  </tr>
  <tr> 
    <td>Email</td>
    <td>
        <input type="text" name="ret_email" value = "<?php echo $ret_email;?>">     </td>
  </tr>
   <?php } ?> 
   <tr>
    <td><input type="submit" name="update" value="Update"></td>
  </tr>
</table>
</form>

</body>
</html>

the retailer table (tblretailer) is not being updated after the record displayed are altered

no error messages are generated

3
Contributors
2
Replies
24
Views
4 Years
Discussion Span
Last Post by Zagga
0

hi,

for testing purposes only, can you modify this code,

     $result=mysql_query("UPDATE tblretailer SET ret_name='".$ret_name."', ret_street='".$ret_street."', ret_city='".$ret_city."', ret_phone='".$ert_phone."', ret_fax='".$ret_fax."', ret_user_fname='".$ret_user_fname."', ret_user_lname='".$ret_user_lname."', ret_email='".$ret_email."' WHERE ret_id='".$ret_id."';");
//redirectig to the display page. In our case, it is index.php
header("Location: del_updret.php");

to

 $this_query = "UPDATE tblretailer SET ret_name='".$ret_name."', ret_street='".$ret_street."', ret_city='".$ret_city."', ret_phone='".$ert_phone."', ret_fax='".$ret_fax."', ret_user_fname='".$ret_user_fname."', ret_user_lname='".$ret_user_lname."', ret_email='".$ret_email."' WHERE ret_id='".$ret_id."'";

 $result=mysql_query($this_query);
//redirectig to the display page. In our case, it is index.php
//header("Location: del_updret.php");

if (!$result) {

  $err  = 'OOPS ONe:' . mysql_error() . '<br/>';
  $err .= 'OOPS Two! This query cannot be inserted: <br/>' . $this_query . '<br/>';
  echo '<br/><br/>';
  die($err);
}

if the modified version works, the error is in your query.. this part of your code

WHERE ret_id='".$ret_id."';");

It is desirable to get the query confirmation first, before redirection.. so your codes should have either this

if (!$result) {

  $err  = 'OOPS ONe:' . mysql_error() . '<br/>';
  $err .= 'OOPS Two! This query cannot be inserted: <br/>' . $this_query . '<br/>';
  echo '<br/><br/>';
  die($err);
}

else{
     header("Location: del_updret.php");
}

or positive with postiive confirmation

if($result){

        header("Location: del_updret.php");

        }

        else{
        die('Something Went Wrong');

        }

It is alll up to you there are tens of ways of doing this..

0

$ret_id is not being posted with the form data so the WHERE part of your query is failing. If you add some error catching to the query you should get a message informing you.
Add
or die(mysql_error());
to the end of your query (line 61).
You can correct this by adding a hidden form field containing it as your code already tries to find it in the POST array.
You also seem to have a stray semicolon at the end of that query, but it wouldn't cause the error.

Edited by Zagga

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.