Jump to content

Problem with a simple edit page functionality


shalli

Recommended Posts

Hi There

 

I am trying to create a page that edit mysql database from a php page. I can get the edit page to show the orginal information but it wont update the data in the mysql database.

 

I am sure I have entered everything right. If anyone could help with this I would greatly appreciated

 

<?php

 

include("dbconnect.php");

 

    if(isset($_POST['submit']))

 

  {

 

 

      // Set global variables to easier names

    // and prevent sql injection and apostrophe to break the db.

 

      $ProductName = mysql_escape_string($_POST['ProductName']);

      $ProductText = mysql_escape_string($_POST['ProductText']);

      $ProductImage = mysql_escape_string($_POST['ProductImage']);

      $ProductPrice = mysql_escape_string($_POST['ProductPrice']);

 

 

        $result = mysql_query("UPDATE Product SET ProductName='$ProductName', ProductText='$ProductText', ProductImage='$ProductImage', ProductPrice='$ProductPrice' WHERE ID='$ID' ",$dbconnect);

 

          echo "<b>Thank you! Product UPDATED Successfully!<br>You'll be redirected to View Page after (2) Seconds";

 

          echo "<meta http-equiv=Refresh content=2;url=view.php>";

         

          echo "$ProductName <br> $ProductText <br> $ProductImage <br> $ProductPrice";

 

}

 

elseif(isset($_GET['ID']))

 

{

 

 

 

        $result = mysql_query("SELECT * FROM Product WHERE ID='$_GET[iD]' ",$dbconnect);

 

        while($myrow = mysql_fetch_assoc($result))

 

            {

 

                $ProductName = $myrow["ProductName"];

                $ProductText= $myrow["ProductText"];

                $ProductImage = $myrow["ProductImage"];

                $ProductPrice = $myrow["ProductPrice"];

 

 

 

?>

 

<br>

 

<h3>::Edit Product</h3>

 

<form method="post" action="<?php echo $PHP_SELF ?>">

 

<input type="hidden" name="ID" value="<? echo $myrow['ID']?>">

Product Name: <input name="ProductName" size="40" maxlength="255" value="<? echo $ProductName; ?>"><br>

Product Text: <textarea name="ProductText"  rows="7" cols="30"><? echo $ProductText; ?></textarea><br>

Product Image: <textarea name="ProductImage"  rows="7" cols="30"><? echo $ProductImage; ?></textarea><br>

Product Price: <textarea name="ProductPrice" rows="7" cols="30"><? echo $ProductPrice; ?></textarea><br>

<input type="submit" name="submit" value="Update Product">

 

</form>

 

<?

 

              }//end of while loop

 

 

 

  }//end else

 

?>

Link to comment
Share on other sites

you sure it's not updating? The order in which you have your code setup it should make the update when you submit but since there is no $_GET when you submit, your code doesn't turn around and query for it so it looks like it shows up blank or not updated (because your condition only does one or the other, not both).  Try refreshing the page after submit to test (or look directly in your db), you should see the updated.  You will have to reorder/rewrite your code to do the query to show the data regardless of whether you posted or not. 

 

p.s. - use [ code] ...[ /code] tags when posting code.

Link to comment
Share on other sites

thanks for your response Crayon Violent

 

Yes it seems to do nothing

 

I entered the following echo to check that I was passing the correct variables

 

echo "$ProductName <br> $ProductText <br> $ProductImage <br> $ProductPrice";

 

Basically what the code does is display a form with the data from the database and you edit that data in the form and when you click submit it should update the database

 

I was using this tutorial to help me create this functionality http://www.maaking.com/index.php?loadpage=tutorials

 

hope this help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.