Dysan Posted November 15, 2007 Share Posted November 15, 2007 Hello! Can code be inserted into a database via clicking on a link? Link to comment https://forums.phpfreaks.com/topic/77400-click-link-to-execute-code/ 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) Link to comment https://forums.phpfreaks.com/topic/77400-click-link-to-execute-code/#findComment-391818 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]')"; Link to comment https://forums.phpfreaks.com/topic/77400-click-link-to-execute-code/#findComment-391848 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']}')"; } ?> Link to comment https://forums.phpfreaks.com/topic/77400-click-link-to-execute-code/#findComment-391855 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.