boredemt boredemt - 5 months ago 9
SQL Question

Submit variable in URL to MySQL Database

I would like to have a page that, when someone clicks a pre-formatted link I've sent, writes a variable in the URL to a MySQL database and just displays "Thank You" or something to the user.

Example:

The user would click a link formatted something like http://www.example.com/click.php?id=12345

When the page loads the 12345 would be written to a table in a MySQL database, it would show a Thank you, and that is it.

Seems like it should be simple enough but I can't find anything on it. I'm probably searching wrong, since this is all new to me.

Answer

User $_GET to retrive the value and put into your table. Example:

code inside click.php

<?php
$id=$_GET['id'];
$sql="Insert into table1 VALUES ($id)";
mysqli_query($connect,$sql);
echo "<script>alert('Thank you')</script>";
?>
Comments