badgerchap Posted August 13, 2013 Share Posted August 13, 2013 This is a pretty simple bit of code, taken from a template on w3schools.com. For some reason though, it doesn't clear my table. I've tried exactly the same but with TRUNCATE TABLE. It's not the $ipaddress as the table name, as a) that works fine with other commands elsewhere in my site and b) I've tried the same commands with a simpler table name. I've messed around with this now and I'm out of ideas! No error is being returned, and to all intents and purposes it seems as if the command has gone through, but the table remains resolutely full of data :/ Any help please? Thanks in advance. <?php $con=mysqli_connect("*********","*****","*****","*********"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $ipaddress=$_SERVER["REMOTE_ADDR"]; mysql_query($con,"DELETE FROM `".$ipaddress"` WHERE Quantity!=='0'"); mysqli_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/281125-why-no-workee/ Share on other sites More sharing options...
Solution mac_gyver Posted August 13, 2013 Solution Share Posted August 13, 2013 (edited) you are making a mysqli connection (with an i), but trying to use a mysql_query() (no i). all your database functions must be of the same type, you cannot mix calls to the different database libraries. if you had php's error reporting set to E_ALL and display_errors set to on so that php would help you by reporting and displaying the errors it detects, you would have been getting a error pointing to the problem ($con isn't a mysql_ connection.) also, i'm pretty sure !== isn't a valid mysql database comparison operator and is probably causing a query error. Edited August 13, 2013 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/281125-why-no-workee/#findComment-1444769 Share on other sites More sharing options...
badgerchap Posted August 13, 2013 Author Share Posted August 13, 2013 You're a star, would never have picked that up myself. Many thanks! Yeah, you were right about the !==, have change it to > and it's just fine now. Many thanks! Quote Link to comment https://forums.phpfreaks.com/topic/281125-why-no-workee/#findComment-1444772 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.