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

Typing math
I've added support for typesetting math using LaTeX on the forums.

Example:
Code: [Select]

How do I get the row number from from an sql table query
Hi all

I have a table that I query and it returns a number of rows.
mysql_num_rows($query)

sendmail code suddenly not working
Hi Guys, I maintain 3 sites (including my own) I use the following code from a french webmaster that

Namespace Problem
I'm having problem with a section of code with a variable namespace.

This code works fine:

mail() says sent but no email received
My code is quite simple:

Code: <?php
$to = "Ty44ler@yahoo.com";
$subje

What makes a script your own?
If someone finds a login script online, and changes some variable names around and some other minor

WHYISNT THIS MYSQL STATEMNT NOT WORKING? (php)
caps because its absolutely rediculous.
i dontunderstand why its not working. there is a column c

Update Database
Hi All,


I have a problem with this:

Code: [Select]<?php
session_start();

help with variable
I've got a problem, i want to echo some images depending on the $id, however for me to get that id i

max function question
Hi All
Ihave a table that holds shipment numbers and dates like this

select * from

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