www.webdeveloper.com
Results 1 to 3 of 3

Thread: Please I need help with this PHP Update code.

  1. #1
    Join Date
    Jan 2013
    Posts
    4

    Please I need help with this PHP Update code.

    Hello everyone!

    Please I need help updating my database from a html form.

    I'm quite new to PHP. I can't figure out where the error is.

    Please can anyone help?

    Thank you very much!

    HTML Code:
    <body>
    <?php
    mysql_connect("localhost", "root", "");
    mysql_select_db("wrapper");
     
    if(isset($_POST['update'])){
    $UpdateQuery = "UPDATE articles_selection SET article = '$_POST[article]' WHERE id ='$_POST[hidden]'";
    mysql_query($UpdateQuery, $sql);
     
    
     
    
    };
     
    $sql = mysql_query("SELECT * FROM articles_selection");
     
    echo "<table border = '1'>
    <tr>
    <th>ID</th>
    <th>ARTICLE</th>
    </tr>";
     
    while($record = mysql_fetch_array($sql)){
    echo "<form action="index1.php" method ="post">";
    echo "<tr>";
    echo "<td>" . "<input type = "text" name = "id" value ="  . $record['id'] . " </td>";
    echo "<td>" . "<input type = "text" name = "article" value ="  . $record['article'] . " </td>";
    echo "<td>" . "<input type = "hidden" name = "hidden" value ="  . $record['id'] . " </td>";
    echo "<td>" . "<input type = "submit" name = "Update" value = "update">" . " </td>";
    echo "</tr>";
    echo "</form>";
    }
     
    echo "</table>";
     
    ?>
    </body>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,147
    double quotes within a double-quoted string literal need to be escaped, or else use single quotes:
    PHP Code:
    // syntax error:
    echo "<form action="index1.php" method ="post">";

    // instead escape the literal quotes within the string:
    echo "<form action=\"index1.php\" method =\"post\">";

    // or else you could use single quotes within the HTML markup:
    echo "<form action='index1.php' method ='post'>"
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jan 2013
    Posts
    4
    Thank you very much!! I used single quotes within the HTML markup, and it worked.

    Thank you!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
HTML5 Development Center



Recent Articles