Why is the logic of this simple code not working?


Posted on 16th Feb 2014 07:03 pm by admin

Hey, I'm trying to determine if a table already exists in mysql, but doing a query first with mysql_query, then checking $sql as if it a were TRUE of FALSE. Which I though it would be. My Code always skips to the }else{ statment after the If(). What is wrong, How I do this?
I could of sworn I've wrote other scripts using this and it works.



PHP:

//Check first if it exists
$sql = mysql_query("SELECT var FROM fake WHERE token='{$token}'");


if( ! $sql){
// Does not exist! Create it.
$sql = mysql_query("INSERT INTO fake (var,token) VALUES('$var','$token')") ;


} else {
//It exists, Update it.

$sql = mysql_query("UPDATE fake SET var='{$var}' WHERE token='{$token}'") ;


}


Also

echo $sql; prints out, Resource id #11 or something.. Doesn't seem to say false or true....

No comments posted yet

Your Answer:

Login to answer
153 Like 49 Dislike
Previous forums Next forums
Other forums

New to Arrays
Hi I am new to PHP (a week and a half now) and I am just beginning to read about arrays. I understan

Help? Need help on project with templates involving mysql and php.
I'm having a hard time explaining what I want but basically here is what I have in place:

-Da

INSERT data problem!
After having an string with apostrophes ', double quotes " or any other special characters, suc

Amatuer requiring assistance
Beginner and amateur in need of assistance

My Site - (Spare Parts for Domestic Appliances)

My query is being run with no results.
I have this.

Code: function DropUser($duser_id, $user_email, $user_username) {

Need help to modify php ELSE code
I'm trying to find a way to have the php code display a message if there is no inventory listed in t

MySQL-PHP Query Results Help
Hello all. I'm hoping to be able to get some help in solving a problem with query/rowcount output. I

Request.UrlReferrer
I need to make it so that a page can only be loaded when a button is clicked on a specific page. I d

please hep to get values from a table row
can anyone tel me how I can select and get data from one row by pressing an Edit button in that row

Insert to MySQL inside foreach
Hey.
I am parsing some html, and putting inside an html db.
I need to create a randomized inte

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash