Forms are killing me, help please !
Posted: Sun Oct 06, 2002 8:50 pm
Hi!, I'm trying this simple example w/forms, that uses 2 .php pages, but if I dont turn 'ON' the "register_globals = Off" in the php.ini file, the variables from forms are not passed between .php pages... why ? (I have had problems not only w/this example, but w/all the examples that uses variables coming from forms).
I have created a database in mysql called "test", and the table w/which I'm dealing is "employees". The objective of the example is to insert information into the table "employees", simple as that, but everytime the form try to send the info by the "post method" the info in the form elements never comes to the other page, is like if that info. get banned.
* my first page is called "forms-test01.php", and is as follows:
<html>
<body>
<form method="post" action="forms-test02.php">
First name:<input type="Text" name="first"><br>
Last name:<input type="Text" name="last"><br>
Address:<input type="Text" name="address"><br>
Position:<input type="Text" name="position"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
</body>
</html>
* and the second one is called "forms-test02.php":
<?
$connect = mysql_connect("localhost", "user", "pass") or die("Could not connect to the server");
mysql_select_db("test", $connect) or die("Could not select database");
$query1 = "INSERT INTO EMPLOYEES (first, last, address, position) VALUES('$first', '$last', '$address', '$position')";
$result1 = mysql_query("$query1", $connect);
$query2 = "SELECT * FROM EMPLOYEES";
$result2 = mysql_query("$query2", $connect);
echo "<table border=1>";
echo "<tr><td>First</td> <td>Last</td> <td>Address</td> <td>Position</td></tr><br>";
$myrow = mysql_fetch_array($result2);
do
{
printf("<tr> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> </tr> <br>", $myrow["first"], $myrow["last"], $myrow["address"], $myrow["position"]);
}
while($myrow = mysql_fetch_array($result2));
echo "</table>";
?>
--------------------------------------------------------------------------------
I'm runing Apache 2.0.36, PHP 4.2.0 and MySQL 3.23.52 on Win XP Pro, thx for any help guys
.
I have created a database in mysql called "test", and the table w/which I'm dealing is "employees". The objective of the example is to insert information into the table "employees", simple as that, but everytime the form try to send the info by the "post method" the info in the form elements never comes to the other page, is like if that info. get banned.
* my first page is called "forms-test01.php", and is as follows:
<html>
<body>
<form method="post" action="forms-test02.php">
First name:<input type="Text" name="first"><br>
Last name:<input type="Text" name="last"><br>
Address:<input type="Text" name="address"><br>
Position:<input type="Text" name="position"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
</body>
</html>
* and the second one is called "forms-test02.php":
<?
$connect = mysql_connect("localhost", "user", "pass") or die("Could not connect to the server");
mysql_select_db("test", $connect) or die("Could not select database");
$query1 = "INSERT INTO EMPLOYEES (first, last, address, position) VALUES('$first', '$last', '$address', '$position')";
$result1 = mysql_query("$query1", $connect);
$query2 = "SELECT * FROM EMPLOYEES";
$result2 = mysql_query("$query2", $connect);
echo "<table border=1>";
echo "<tr><td>First</td> <td>Last</td> <td>Address</td> <td>Position</td></tr><br>";
$myrow = mysql_fetch_array($result2);
do
{
printf("<tr> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> </tr> <br>", $myrow["first"], $myrow["last"], $myrow["address"], $myrow["position"]);
}
while($myrow = mysql_fetch_array($result2));
echo "</table>";
?>
--------------------------------------------------------------------------------
I'm runing Apache 2.0.36, PHP 4.2.0 and MySQL 3.23.52 on Win XP Pro, thx for any help guys