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 3 of 3
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Cool Rendering MySQL output to edit in a form

    Im coding a form to upload items into MySQL database, everything works fine except when i click "edit" (to change details with that item) the data doesnt render in the form...

    <?php
    // Gather this product's full information for inserting automatically into the edit form below on page
    if (isset($_GET['pid'])) {
    $targetID = $_GET['pid'];
    $sql = mysql_query("SELECT * FROM products WHERE id='$targetID' LIMIT 1");
    $productCount = mysql_num_rows($sql); // count the output amount
    if ($productCount > 0) {
    while($row = mysql_fetch_array($sql)){

    $product_name = $row["product_name"];
    $price = $row["price"];
    }
    } else {
    echo "Item doesnt exist!";
    exit();
    }
    }
    ?>

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Because you are limiting your query to 1 result, you don't actually need a while loop, so remove the while to leave you with this inside the if:
    PHP Code:
    $row mysql_fetch_array($sql); 
    $product_ name $row["product_ name "];
    $price $row["price "]; 
    You Should add 'or die(mysql_error())' to the end of your query to catch any errors.

    Also, could you post your form code?

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,346
    Thanks
    60
    Thanked 527 Times in 514 Posts
    You're only showing php code there. You're not showing us any code that actually puts the data directly into the form or even tries to do so.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Tags for this Thread

    Posting Permissions

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