MySQL – INSERT Records with HTML Hyperlinks and PHP($_GET)

Using the GET method you can pull variable values from HTML hyperlinks and process them in a PHP script to Insert records into a MySQL Table.


Vote for Something<br>
<a href="" > YES</a>
<a href="" > NO</a>
<a href="" > BOTH</a>





$servername = "localhost";
$username = "bob";
$password = "123456";
$db = "classDB";

$conn = new mysqli($servername, $username, $password, $db);

if ($conn->connect_error){
	die("Connection failed: ". $conn->connect_error);

$sql = "insert into votes(yes,no,time)values('$vote_yes','$vote_no','$time')"; 

if ($conn->query($sql) === TRUE) {
	echo "Votes Recorded: Yes = ".$vote_yes." No = ".$vote_no." Time = ".$time;
} else {
	echo "Error: ".$sql."<br>".$conn->error;



votes Table

create table votes(
	vote_id int auto_increment primary key,
	yes int,
	no int,
	time int);  

Be the first to comment

Leave a Reply