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

Displaying Column Names
I have a question regarding the ability to show the column names from my table/query.
What I'm lo

Why do I get this error
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/a5488351/public_html/b

How many users online in the last 24-hours using time()?
I'm fairly new to PHP. I have a MySQL table called 'users' and a field called 'loggedin' which is in

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,

Significance of BPM
Hi Experts,
I am a novice in BPM , I just want to know how BPM as permenant department is

How to add advertisment on top of videos
Hello,
I was told that i should find the answer for this problem in this forums.
I searched a

Files in current folder. Should be an easy fix.
Never mind. I've asked about this before and just found my answer. Anyway to delete this?

CODE NOT WORKING
Code: [Select]<?php
//include shared codes

include '../lib/common.php';
include

upload only text files
hi guys i want to upload only text like like (pdf,note pad and ofiice files) so can any one please t

function to return url
Hi,

Can you guys help me giving a function that takes all the contents in a particular field

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