Page 1 of 1

Passing a variable between forms

Posted: Fri Oct 11, 2002 11:25 am
by mikebr
I thought I had got my head around the problems with variables that register_globals was causing in the latest version of php until I tried using two forms to add information to a mysql table. The table has three columns, one for "books", one for "quantity" and one for the "ID", the ID gets passed on as the ID column "auto_increment" adds 1 to each entry and returns the value to the second form but the entries for the columns of "book" and "qty" seem to have empty values which get added to the table as " " i.e. the variable is empty, nor does the second form return an error on this, can anyone tell me why the variables for "book" and "qty" are empty?

The process starts by calling "last_ID.php", which on SUBMIT calls "last_ID2.php" the code for these are as follows:

ps. The logging into the database is done through the include: include ("test_holding_inc.php");

last_ID.php

Code: Select all

<html>
<body>
<center><b> Place a book order</b></center><br></br>
<?php
# last_ID.php
# include file
echo "<FORM METHOD=GET ACTION="last_ID2.php">";
echo "Please select a book:";

echo "<SELECT> NAME="book">";
echo "<OPTION>Web admin";
echo "<OPTION>Shell programming";
echo "<OPTION>Linux security";
echo "<OPTION>Posix programming";
echo "<OPTION>Apache admin";
echo "<OPTION>Networking Linux";
echo "</SELECT>";
echo "Select the quantity";
echo "<SELECT> NAME="qty">";
echo "<OPTION>1"; 
echo "<OPTION>2";
echo "<OPTION>3";
echo "<OPTION>4";
echo "<OPTION>5";
echo "</SELECT>";
echo "<BR></BR><BR></BR>";
echo "<INPUT TYPE="SUBMIT" VALUE="Place order!">";
echo "<INPUT TYPE="RESET" VALUE="Clear!">";
?>
</FORM>
</BODY>
</HTML>
last_ID2.php

Code: Select all

<html>
<body>
<?php
# last_ID2.php
# include file
include ("test_holding_inc.php");

$book=$_GET&#1111;'book'];
$qty=$_GET&#1111;'qty'];
$sql="INSERT INTO linux_books(book,qty) VALUES ('$book','$qty')";

if (!mysql_query($sql,$connection)) &#123;
echo "Error cannot add record..hit the back button and try again!!!<BR>";
exit;
&#125; else &#123;
# insert OK inform user and get the last insert ID 
$ID=mysql_insert_ID();
echo "Order taken &#1111;".mysql_affected_rows()."] record added<BR>";
echo "Details are<BR>Book: <B>$book</B><BR>Qty:<B>$qty</B><BR>";
echo "For your reference the order number is:&#1111;<B>$ID</B>]";
&#125;
echo "<BR><A HREF="last_ID.php"> Back</A>";
?>
</BODY>
</HTML>
Thanks

Posted: Fri Oct 11, 2002 11:57 am
by volka
i.e.
<SELECT> NAME=\"book\">
you're closing the tag before writing the property. try

Code: Select all

echo '&lt;SELECT NAME="book"&gt;';

Posted: Fri Oct 11, 2002 12:01 pm
by mikebr
Yes that did it, thank you very much.

Mike