Jump to content

Click Link to Execute Code


Dysan

Recommended Posts

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)

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]')";

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']}')";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.