Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Posts
    6

    Unanswered: Hidden Field Problem

    Hi, im trying to insert some information passed from a form into a table. I've created a hidden field to pass one part of the information, but it won't insert into the table.

    Can anyone see why not?
    Thanks.

    PHP Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="#FFFFFF" text="#000000">
    <table width="100%" border="1">
      <tr>
        <td width="20%"><?php include("menu.php"); ?></td>
        <td width="80%">
          <p>&nbsp;</p>
         
    <?php
    include("connectBookdb.php");
    if(
    $_POST['submit']) 

        
        
    $sql "INSERT INTO advert2 
            (username, mod_book_id, asking_price, condition, date_added, description) VALUES ('
    {$_SERVER['PHP_AUTH_USER']}', '$hiddenID', '".$_POST['askingPrice']."', '" .$_POST['condition']."', 'now', '".$_POST['description']."')";
        
    $result pg_exec("$sql");

    print 
    "<PRE>"
    print_r($_GET); 
    print 
    "</PRE>";
        
    }

    else 

    $title $_GET['title'];
    $author $_GET['auth'];
    $publisher $_GET['pub'];
    $pubYear $_GET['pubYear'];
    $id $_GET['id'];

    echo 
    "<h1>Please enter further details for your advert</h1>";

    echo 
    "<hr>";
    echo 
    "<b>Book Details</b><br><br>";
    echo 
    "<b>Title</b> : $title<br>";
    echo 
    "<b>Author</b> : $author<br>";
    echo 
    "<b>Publisher</b> : $publisher<br>";
    echo 
    "<b>Year</b> : $pubYear<Br>";
    ?>

    <form method="post" action="<? echo $PHP_SELF?>"> 
    Asking Price:<INPUT TYPE="text" NAME="askingPrice" SIZE="30"><br><br>
    Condition of book:
    <select name="condition">
    <option value="Like new">Like New
    <option value="Good">Good
    <option value="Fair">Fair
    <option value="Worn">Worn
    <option value="Worn">Excellent
    </select><br><br> 

    Additional Comments:<br><textarea name="description" cols="50" rows="5"></textarea> <br><br>

    <input type="Submit" name="submit" value="Enter information">

    <input type="hidden" name="hiddenID" value="$id">

    </form> 
    <? 

    ?> 

        </td>
      </tr>
    </table>
    </body>
    </html>

  2. #2
    Join Date
    Oct 2003
    Location
    Slovakia
    Posts
    482
    At first you need:

    PHP Code:
    $sql "INSERT INTO advert2 

            (username, mod_book_id, asking_price, condition, date_added, description) VALUES ('
    {$_SERVER['PHP_AUTH_USER']}', '".$_POST['$hiddenID']."', '".$_POST['askingPrice']."', '" .$_POST['condition']."', 'now', '".$_POST['description']."')";

        
    $result pg_exec("$sql"); 
    ...and second change:


    PHP Code:
    <input type="hidden" name="hiddenID" value="<? echo $id ?>">

  3. #3
    Join Date
    Apr 2004
    Posts
    6
    It still isn't inserting into the mod_book_id code??!
    Any more ideas?
    Thanks.

  4. #4
    Join Date
    Oct 2003
    Location
    Slovakia
    Posts
    482
    Originally posted by louphp
    It still isn't inserting into the mod_book_id code??!
    Any more ideas?
    Thanks.
    Try to add input type hidden before smubmit button in form.

Posting Permissions

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