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.


Did you know?Explore Trending and Topic pages for more stories like this.

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

$get problem
Hi Guys ...

can you please tell me what i am doing wrong here
Code: <?php

Code clarification
Hi

In the following code what could be the "search_print()" and where it could be

Help with PHP and checkboxes
I am posting this for a friend of mine, i wrote a small script for her to process her form data to a

php calculate
this code echoes correctly the sum but the inserted result is 0??
Code: <?php
$TotalNum

PHP url branch??
Functionally, using PHP, I'm doing a test of login input submitted by a user via an html form in a f

Using mysql_real_escape_string for displayed content
On my website users can input data into a textarea and it will store it in the mysql database. But,

Need help PLEASE
ok i have this warning showing up

Warning: in_array() [function.in-array]: Wrong datatype for

php code generators
All

Whilst enjoying learning a new language i have come accross a number of free code generat

Remove letter from numeric textbox
I have a textbox that will search the employee database by entering in the employee ID and it will r

Reading waves
Hi,

I am trying to find a way of finding the highs and lows on a graph line, the line points

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