Hi,

I am having a problem with $_POST which I will explain below.  My
configuration is Redhat 7.3 Linux 2.4.18 with Apache 2.0.39, PHP 4.2.2,
and MySQL 3.23.49.

I have an SQL table which was created by:

CREATE TABLE testTable (id nut null primary key aut_increment, testField
varchar (75));

I have an HTML form using POST:

<!-- insert_form.html -->
<HTML>
<HEAD><TITLE>Insert Form</TITLE>
</HEAD>
<BODY>
<FORM ACTION="insert.php" METHOD=POST>
<P>Text to add:<br>
<input type=text name=testField size=30>
<p><input type=submit value="Insert Record"></p>
</FORM>
</BODY>
</HTML>




and I have a PHP script that uses $_POST to put the value from the form
into the SQL table:

<!-- insert.php -->
<?

$conn = mysql_connect("localhost", "supercontact", "tical123");

mysql_select_db("contactDB", $conn);

$sql = "INSERT INTO testTable VALUES ('', '$_POST[testField]')";

echo "the value is $_POST[testField]<BR>";
echo "$sql<BR>";


if ($result = mysql_query($sql, $conn))
{
        echo "record added!";
}
else
{
        echo "something went wrong";
}


?>




when I open up insert_form.html in a browser and put in a value of
"Testing the form" and then submitting it to insert.php, this is the
result:

the value is Testing the formtestField=Testing the form
INSERT INTO testTable VALUES ('', 'Testing the formtestField=Testing the
form')
record added!



and when I go to MySQL to see what was inserted into the table I have:

mysql> select * from testTable;
+----+--------------------------------------------+
| id | testField                                  |
+----+--------------------------------------------+
| 19 | Testing the formtestField=Testing the form |
+----+--------------------------------------------+
1 row in set (0.00 sec)

Which that is not correct, it should be | 19 | Testing the Form |

If I change the method=POST to method=GET and the $_POST to $_GET and use
"Testing the form" it works correctly:

the value is Testing the form
INSERT INTO testTable VALUES ('', 'Testing the form')
record added!

mysql> select * from testTable;
+----+--------------------------------------------+
| id | testField                                  |
+----+--------------------------------------------+
| 20 | Testing the form                           |
| 19 | Testing the formtestField=Testing the form |
+----+--------------------------------------------+
2 rows in set (0.00 sec)


Does anyone know why it is not working with $_POST but works fine with
$_GET?

                        Thanks,
                        Adam





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to