Dysan Posted November 15, 2007 Share Posted November 15, 2007 Hello! Can code be inserted into a database via clicking on a link? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted November 15, 2007 Share Posted November 15, 2007 Yes.. ie <a href="?do=this">do this</a><br><a href="?do=that">do that</a> <?php if(isset($_GET['do'])) { switch($_GET['do']) { case "this": echo "done this"; break; case "that": echo "done that"; break; } } ?> of course this and that will be the input.. to the database (the example is just the concept) Quote Link to comment Share on other sites More sharing options...
Dysan Posted November 15, 2007 Author Share Posted November 15, 2007 Oops! Sorry, I didn't explain my question correctly. How do I adding records to the database using the following code, upon a link being clicked?: mysql_select_db("my_db", $con); $sql="INSERT INTO person (FirstName, LastName, Age) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')"; Quote Link to comment Share on other sites More sharing options...
MadTechie Posted November 15, 2007 Share Posted November 15, 2007 Well as your using POST.. i guess you have a form.. so the link will need to submit that form.. so are you asking for a hyper link instead of a button ? normally your do it like this (for a button) //Form <form method="post"> <input name="firstname" type="text" /><br> <input name="lastname" type="text" /><br> <input name="age" type="text" /><br> <input name="submit" type="submit" value="submit" /> </form> //code <?php if(isset($_POST['submit'])) { //connect to database mysql_select_db("my_db", $con); $sql="INSERT INTO person (FirstName, LastName, Age) VALUES ('{$_POST['firstname']}','{$_POST['lastname']}','{$_POST['age']}')"; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.