GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 23-Nov-2007, 19:34
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road

Need help with Syntax


I am uncertain what I am doing wrong with this.

The 1st set of code does not work, but the second set of code works fine, the only difference is the 'where `ip` = xxxxxxx' in both pieces of code.

PHP Code:

// 1st set of code
$ip = '71.206.122.144';

$query = 'SELECT * FROM `wcvisitor_ip` WHERE `ip` = \'$ip\'';
$result = mysql_query($query);
$row = mysql_fetch_array($result);


// 2nd set of code
$query = 'SELECT * FROM `wcvisitor_ip` WHERE `ip` = \'71.206.122.144\''; 
$result = mysql_query($query);
$row = mysql_fetch_array($result); 



Please show me what I am doing wrong, and what to do to fix this.

Thanks,
Richard
Last edited by admin : 07-Dec-2007 at 10:30. Reason: Please insert your example PHP codes between [PHP] and [/PHP] tags
  #2  
Old 26-Nov-2007, 08:04
filth filth is offline
New Member
 
Join Date: Oct 2007
Posts: 5
filth is on a distinguished road

Re: Need help with Syntax


in the first piece of code $ip is within single quotes therefore it is a part of the string. To fix this you can do either of the following:-

PHP Code:

$query = 'SELECT * FROM `wcvisitor_ip` WHERE `ip` = \''.$ip.'\''; 



OR

PHP Code:

$query = "SELECT * FROM `wcvisitor_ip` WHERE `ip` = \'$ip\'"; 



In the first instance we are using something called concatenation. Ie. we have come out of the single quotes and used a . to show that we are still assigning data to the variable.

In the 2nd example we use double quotes ("). Variables within double quotes are evaluated and output their content to the string.
 
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked Lists advice request promsan C Programming Language 74 23-May-2007 08:29
syntax errors in document coder MS Visual C++ / MFC Forum 0 11-Mar-2006 04:12
Winsock error when compiling FLTK 2.0 Projects mauriciorossi FLTK Forum 3 16-Aug-2005 10:18
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 20:30
C++ PhoneBook marita CPP / C++ Forum 46 12-Jun-2005 12:10

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 23:08.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.