Jump to content


Photo

trying to update fields


  • Please log in to reply
44 replies to this topic

#41 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 September 2006 - 09:30 PM

I found out the problem You have a hidden field called shopName. The value of that field wan't being populated. I have now fixed that. Try this:
<?php
#Script 7.3 - register.php
include "db.php";

if(isset($_POST['submittedUpdate']))
{
    foreach($_POST as $key => $value)
    {
        ${$key} = mysql_real_escape_string($value);
    }

    $query2 = "UPDATE product SET prodName='$prodName', dept='$dept', brand='$brand', type='$type', image='$image', price='$price' WHERE prodId ='$prodId' and shopName='$shopName'";
    $result2 = @mysql_query($query2) or die("Unable to perform query2 <code>" . $query2 . "</code><br /><br />" . mysql_error());

    echo'<p align=center><font color="#333333"><b>UPDATED SUCCESSFULLY</b></font></p>';

}

$prodId = 0;

if(isset($_REQUEST['prodId']) && is_numeric($_REQUEST['prodId']))
{
    $prodId = $_REQUEST['prodId'];
}

$query1 = "SELECT * FROM product WHERE prodId=$prodId";
$result1 = mysql_query($query1, $conn) or die("Unable to perform query1 <code>" . $query1 . "</code><br /><br />" . mysql_error());

if (mysql_num_rows($result1) == 1)
{
    echo'<form action="admin_update2.php" method="post">
  <center>
    <table align="center" cellspacing="0" cellpadding="5" bgcolor="#ffffff" border=1 bordercolor="#2696b8">
      ';

    $row = mysql_fetch_array($result1, MYSQL_ASSOC);

    echo'<tr>
        <td align="left" bgcolor="#2696b8"><center><font color="black"><b>Product Id </b></center></td>
        <td align="left">' . $row['prodId'] . '</td>
      </tr>
      <tr>
        <td align="left" bgcolor="#2696b8"><center><font color="black"><b>Shop Name</b></td>
        <td align="left">' . $row['shopName'] . '</td>
      </tr>
      <tr>
        <td align="left" bgcolor="#2696b8"><center><font color="black"><b>Product Name</b></td>
        <td align="left"><input type="text" name="prodName" size="30" maxlength="30" value="' . $row['prodName'] . '"/></td>
      </tr>
      <tr>
        <td align="left" bgcolor="#2696b8"><center><font color="black"><b>Department</b></td>
        <td align="left"><input type="text" name="dept" size="20" maxlength="20" value="' . $row['dept'] . '"/></td>
      </tr>
      <tr>
        <td align="left" bgcolor="#2696b8"><center><font color="black"><b>Price</b></td>
        <td align="left"><input type="text" name="price" size="50" maxlength="50" value="' . $row['price'] . '"/></td>
      </tr>
      <tr>
        <td align="center">
          <p>
            <input type="submit" name="submit" value="UPDATE"/>
    	    <input type="reset" value="CLEAR FORM">
          </p>

          <input type="hidden" name="prodId" value="' . $prodId . '">
          <input type="hidden" name="shopName" value="' . $row['shopName'] . '">

          <input type="hidden" name="submittedUpdate" value="TRUE"/>
        </td>
      </tr>
    </table>
  </center>
</form>';
}

?>
</body>
</html>
Should be the last time now!

I also removed the if in the foreach loop. it was also the cause of the problem.

#42 kikilahooch

kikilahooch
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 02 September 2006 - 09:40 PM

lol, almost there I hope! Just getting some error messages now, it said there was an inexpected ')' on this line

$row = mysql_fetch_array($result1, MYSQL_ASSOC))

So I removed the 2nd ')'

now I get the message


Parse error: parse error, unexpected T_ECHO in /home/c/ciaracousins/public_html/admin_update2.php on line 99

line 99:

   echo'<tr>//line 99
        <td align="left" bgcolor="#2696b8"><center><font color="black"><b>Product Id </b></center></td>
        <td align="left">' . $row['prodId'] . '</td>
      </tr>


#43 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 September 2006 - 09:41 PM

I just found another bug in my code. Change this:
$row = mysql_fetch_array($result1, MYSQL_ASSOC))

to this:
$row = mysql_fetch_array($result1, MYSQL_ASSOC);

I did noticedyou had trouble

#44 kikilahooch

kikilahooch
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 02 September 2006 - 09:48 PM

Wooo Hooo!! Its working! lol, thanks wildteen your a legend!! As you can see I know nothing about coding! lol. I have a delete page to do now, hopefully it will be pretty much the same but change the sql in it, think I'm gonna leave that till tomorrow though! Thanks for giving up your day, really appreciate it!  :)

#45 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 September 2006 - 09:51 PM

No problem! Glad we got there in the endm only took 7hours! :). I know I changed your code a lot post any questions you have about the code I used here and I'll answer them for you.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users