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

Creating web pages by php
Hello again,
I was just wondering us there a way to use a php script to create a new web page. I

Batch Related Pricing
Hi, I need some clarity on the batch related pricing

For example the following are the b

radio button reamains checked
Hello i'm trying to keep the state off my radio buttons so it shows which ones where clicked after t

Help with php code
Hello, can anyone tell me why this php word trap fails to work,
and the trigger words get blow r

Combining refCursors and Summing
Given the following DDL:

CREATE TABLE FOODSALESTEST ("WEEKNBR" NUMBER, "ST

small inaccuracies
I have this code to convert fractional base 10 into base 2:

while($num > 0)

How to replace search button with link?
hi to everbody.
i have a search submit form and button like this :

<form id="f

Help with Hyperlink
Hi,

What I am trying to do may be simple, I just can't get it to work. Ok...

I am usin

SQL Injection
In my attempts to protect my database from mySQL injection I have created another problem for myself

MASS PM
Hello all, I'm trying to send mass private messages to users in my database but keep getting an erro

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