Skip to content

Instantly share code, notes, and snippets.

@alteredorange
Created July 17, 2015 22:16
Show Gist options
  • Save alteredorange/0fad2c9a67c3a1c0d185 to your computer and use it in GitHub Desktop.
Save alteredorange/0fad2c9a67c3a1c0d185 to your computer and use it in GitHub Desktop.
PDO Stuff
/*** begin the session ***/
session_start();
// Connection to database
$connection=mysqli_connect("localhost","root","Iamdone2010","vrcrush");
// Check connection
if (mysqli_connect_errno())
{
echo 'NOT_OK';
//echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//Check if Voted Already
$query="INSERT INTO voted (user_id,news_id) VALUES (?,?)";
$stmt=$connection->query($query);
$stmt->bind("ii",$_SESSION['ID'],$_POST['id1']);
$stmt->execute();
$error=$mysqli_stmt->errno($stmt);
if(!$error) {
mysqli_query($connection,"UPDATE news SET votes=(votes + 1) WHERE ID='". $_POST['id1'] . "'");
}
else {
//Do Nothing
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment