Well.. I'm back with another simple question but I'm not sure what the term is so I can't google it. I think it may have to do with $_SERVER[SELF]
What I am after is a form that will insert data into a mysql database. What I want is for that page to display the html, the user would then enter the data, press submit and if there are any errors, remain on that page and show the errors in red. I think I have the errors down but what is happening is that when I press submit, I am being taken to a different page. Here are my simple scripts:
[CODE=html] <html>
<body>
<form action="test.ph p" method="post">
Firstname: <input type="text" name="firstname " />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html> [/CODE]
and..
[CODE=php]<?php
include "connection.php ";
$sql="INSERT INTO person (FirstName, LastName, Age)
VALUES('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($ sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_cl ose($con)
?> [/CODE]
I have tried to combine both scripts into one but the sql is immediatley inserting a new record into the database *instead* of waiting until the submit button is pressed.
Can someone please point me in the right direction or maybe tell me what the term to do this might be so I can google it?
Please don't recommend Ajax. I know this can be done using Ajax but I prefer not to use it cuz I don't know it. :)
Thanks
What I am after is a form that will insert data into a mysql database. What I want is for that page to display the html, the user would then enter the data, press submit and if there are any errors, remain on that page and show the errors in red. I think I have the errors down but what is happening is that when I press submit, I am being taken to a different page. Here are my simple scripts:
[CODE=html] <html>
<body>
<form action="test.ph p" method="post">
Firstname: <input type="text" name="firstname " />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html> [/CODE]
and..
[CODE=php]<?php
include "connection.php ";
$sql="INSERT INTO person (FirstName, LastName, Age)
VALUES('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($ sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_cl ose($con)
?> [/CODE]
I have tried to combine both scripts into one but the sql is immediatley inserting a new record into the database *instead* of waiting until the submit button is pressed.
Can someone please point me in the right direction or maybe tell me what the term to do this might be so I can google it?
Please don't recommend Ajax. I know this can be done using Ajax but I prefer not to use it cuz I don't know it. :)
Thanks
Comment