ZeroShade Posted March 18, 2007 Share Posted March 18, 2007 How can I say if(click on submit button){this happens!}?? Link to comment Share on other sites More sharing options...
Anders Moen Posted March 18, 2007 Share Posted March 18, 2007 You mean like this? <?phpif (isset($_POST['submit'])) {$con = mysql_connect("localhost","peter","abc123");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("my_db", $con);$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_close($con);}else {?><form action="insert.php" method="post">Firstname: <input type="text" name="firstname" />Lastname: <input type="text" name="lastname" />Age: <input type="text" name="age" /><input type="submit" name="submit" value="Submit" /></form><?php}?> This is taken from W3Schools PHP MySQL section, so it's not safe for sql-injections just so you know. Link to comment Share on other sites More sharing options...
ZeroShade Posted March 18, 2007 Author Share Posted March 18, 2007 I always seem to forget about isset. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now