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)

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.