Jump to content

Why no workee?


badgerchap
Go to solution Solved by mac_gyver,

Recommended Posts

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);

?>

 

Link to comment
Share on other sites

  • Solution

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 by mac_gyver
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.