MySQL UPDATE statement works in query but not in PHP code -
when execute statement in phpmyadmin, works properly, when copy , paste exact same query php file, doesn't work.
php code:
if($_get['vote'] == 1) { echo "if statement ran"; $sql = "update raids set attendees = attendees +1 dateposted = '2017-08-19 16:15:46'"; mysql_query($sql, $link); }
my link variable work , 'if' statement executes. other sql statements haven't given me trouble.
why isn't php code incrementing 'attendees' when used in php code?
as milan chheda said, mysql deprecated , no longer secure. use pdo or @ least mysqli instead.
mysqli implementation code:
//mysqli information $db_host = "localhost"; $db_username = "username"; $db_password = "password"; //connect mysqli database (host/username/password) $connection = mysqli_connect($db_host, $db_username, $db_password) or die("error " . mysqli_error()); //select mysqli dabatase table $db = mysqli_select_db($connection, "table") or die("error " . mysqli_error()); if(isset($_get['vote']) && $_get['vote'] !== null) { $vote = $_get['vote']; if($vote == "1") { echo "vote 1, updating database"; $sql = mysqli_query($connection, "update raids set attendees = attendees + '1' dateposted = '2017-08-19 16:15:46'"); } }
i hope helped you. luck!
Comments
Post a Comment