Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    71
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Title Problem in Database

    hi to all , i have a weird problem when i try to edit my price from database via my php file it is changing other item title and price in database, please help

    here is the code of my php file:

    PHP Code:
    <?php ob_start() ;
    if(!isset(
    $cmd)) 
    {
       
    //displaying all products on the page with title and price
       
    $result mysql_query("select * from booklist order by id"); 
       echo
    '<center><h3>Product List</h3></center>';
       
    //run the while loop that grabs all 
       
    while($r=mysql_fetch_array($result)) 
       { 
         
          
    $title=$r["title"];// title
          
    $id=$r["id"];// id
         

          
    echo "$id : $title - <a href='manager.php?cmd=edit&id=$id'>Edit</a>";
          echo 
    "<br>";
        }
    }

    if(
    $_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
    {
       if (!isset(
    $_POST["submit"]))
       {
          
    $id $_GET["id"];
          
    $sql "SELECT * FROM booklist WHERE id=$id";
          
    $result mysql_query($sql);        
          
    $myrow mysql_fetch_array($result);
          
    ?>
       
          <form action="manager.php" method="post">
          <input type="hidden" name="id" value="<?php echo $myrow["id"?>">
          <h3>Please Enter New Price For the Unit:</h3>
          <b>Title:</b><?php echo $myrow["title"?><br />
          <b>Message:</b><? echo $myrow["body"?><br />
          <b>Enter New Price:<b/><INPUT TYPE="TEXT" NAME="price" VALUE="<?php echo $myrow["price"?>" SIZE=4><br>
       
          <input type="hidden" name="cmd" value="edit">
       
          <div style="margin:10px 0 0 120px;"><input type="submit" name="submit" value="submit"></div>
       
          </form>
       
    <?php  
       if (
    $_POST["submit"])
       {
          
    $title $_POST["title"];
         
    $body $_POST["body"];
         
    $price $_POST["price"];
         
    // Here i am having issue when i update it
         
    $sql "UPDATE booklist SET title='$title',body='$body',price='$price' WHERE id=$id";
               
    $result mysql_query($sql);
          echo 
    "<br /><center><font color=\"red\">The Product Price Has been Updated. </font></center>";
       }
    }
    ob_flush() ; ?>
    Thanks for any help
    Last edited by Dshah; 10-17-2009 at 03:04 PM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    hi to all , i have a weird problem when i try to edit my price from database via my php file it is changing other item title and price in database, please help
    Please explain that 'weird problem'
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Oct 2009
    Posts
    71
    Thanks
    16
    Thanked 0 Times in 0 Posts
    ok thanks... here is the detail...

    i have a page displaying all the products name and price from database and on same page i have edit button to update the price

    echo "$id : $title - <a href='manager.php?cmd=edit&id=$id'>Edit</a>";

    when i click it it will open that item on same page there i have option to edit the price:

    <b>Enter New Price:<b/><INPUT TYPE="TEXT" NAME="price" VALUE="<?php echo $myrow["price"] ?>" SIZE=4><br>

    and after that submit button:

    <div style="margin:10px 0 0 120px;"><input type="submit" name="submit" value="submit"></div>

    when i click submit it runs :

    if ($_POST["submit"])
    {
    $title = $_POST["title"];
    $body = $_POST["body"];
    $price = $_POST["price"];
    // Here i am having issue when i update it
    $sql = "UPDATE booklist SET title='$title',body='$body',price='$price' WHERE id=$id";
    $result = mysql_query($sql);
    echo "<br /><center><font color=\"red\">The Product Price Has been Updated. </font></center>";
    }
    in booklist database i have 20 products . for example if i will update the price of ID16 item it will change the price and title of ID20 .... so confuse sir any help

    Thanks

    Edit: ok here was the problem in my query
    $sql = "UPDATE booklist SET title='$title',body='$body',price='$price' WHERE id=$id";
    i was using all three fields

    now what is happenning its not updating the price
    $sql = "UPDATE booklist SET price='$price' WHERE id=$id";
    Last edited by Dshah; 10-17-2009 at 03:30 PM.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Try
    PHP Code:
    $id=(int) $_POST["id"];
    $title $_POST["title"];
         
    $body $_POST["body"];
         
    $price $_POST["price"];
         
    // Here i am having issue when i update it
         
    $sql "UPDATE booklist SET title='$title',body='$body',price='$price' WHERE id=$id";
               
    $result mysql_query($sql) or die(mysql_error()); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New Coder
    Join Date
    Oct 2009
    Posts
    71
    Thanks
    16
    Thanked 0 Times in 0 Posts
    IT WORKS...thank you very much sir

    Best wishes


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •