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

Problem with coding MySQL query
I'm having heaps of trouble getting one of my PHP/MySQL queries to work for some reason (and the fun

Text Not Displaying Correctly With PHP:GD
I recently moved servers and since then I have noticed that one line of text is showing weirdly.

GET * FROM _____ Except?
I have a site that is for stock photography.

This section of the code calls images to display

Help me with some material on Open Text Overview.
Hi Experts,
Please help me out with some material on Open Text. I have been supporting AP Workf

Variables and Include
Code: [Select]<?php

$header = $_COOKIE['mss']['header'];
$body = $_COOKIE['mss']['b

Undefined offset
The following script checks to see if the user answer matches the correct answer.

Form Fiel

Data storage spaces in varchar2
Trying to understand what's happening.
I am selecting a value from a table that is defined as c

Is it possible to put an entire 500-page book in a database with PHP?
I am working on an intranet and I was wondering if its possible to code php with mysql to enter a fu

Coding Critique
I was hoping someone could take a second and look down my code and see if they see any problems with

Warehouse Management
Hi,

On our system, we have two storage locations ( A and B ) where A is the main factory

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