HTML form in my PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tom_b
    New Member
    • Jan 2006
    • 18

    HTML form in my PHP

    I have the following code with a small form in it. The form is fine when on its' own but doesn't show up when combined with the PHP code. Suggestions anyone??

    Thanks!!

    <?php

    $username="root ";
    $password="woot s";
    $database="text ";
    $id=$_GET['id'];
    mysql_connect(l ocalhost,$usern ame,$password);
    @mysql_select_d b($database) or die( "Unable to select database");

    $query="SELECT * FROM trc_text where id='$id'";
    $result=mysql_q uery($query);
    $num=mysql_numr ows($result);
    mysql_close();

    $i=0;
    while ($i < $num) {
    $text=mysql_res ult($result,$i, "text");
    ?>

    <form action="updated _text.php" method="post">
    <input type="hidden" name="ud_id" value="<?php echo $id; ?>">
    Text: <input type="text" name="ud_text" value="<?php echo $text; ?>"><br>
    <input type="Submit" value="Update">
    </form>

    <?php
    ++$i;
    }

    ?>
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Your form states ACTION=POST. But you read the value using a $_GET['id'].

    Ronald :cool:

    Comment

    • iam_clint
      Recognized Expert Top Contributor
      • Jul 2006
      • 1207

      #3
      there is also a better way to loop through your sql results

      Code:
      while($row=mysql_fetch_array( $result )) {
      $text = $row['text'];
      }
      anyways i like to use this way better.

      Comment

      • bevort
        New Member
        • Jul 2006
        • 53

        #4
        Do you get something back from your database. A common error is asking for "$ID" as a string instead of $ID as an integer.
        Check this using an

        Echo($num);

        after counting tne number of records.
        Another way is to check for the result like

        if ($result) {echo ("No data recieved from the database);}
        else { show your form }

        Using your form in a faked environment dit not give any problems

        Vincent

        Comment

        Working...