Jump to content

[SOLVED] Whats wrong with this? (php mysql syntax)


monkeytooth

Recommended Posts

$query = " SELECT * FROM memb_pers " .
         " LIMIT $offset, $rowsPerPage " .
	 " WHERE c0unty = '$clocd' ";

 

the error is:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE c0unty = 'Litchfield'' at line 1

 

 

I have no idea where I went wrong with this, it works without the WHERE clause, but then I added the WHERE and I think I did it right.. but im wrong so help?

Link to comment
Share on other sites

no need for braces when using double quotes unless you're using arrays:

 

$name = 'Bob';
$names = array('first' => 'Bob');

echo "Hello, my name is $name<br />";
echo "Hello, my name is {$names['first']}<br />";

echo 'Hello, my name is '.$name;

 

for the record, you should always be using single quotes for strings that contain no variables - that way PHP doesn't have to waste resources scouring the string for variable references before echoing it.  read up on variable interpolation for more info.

Link to comment
Share on other sites

your still talking minimal amounts and most of the time you are phrasing a string with variables (other wise php doesn't provide you a lot of usefulness) so I personally use double quotes and then ". to escape any variable.

<?php
$var = "yes";
echo "Do you like php?<br />".$var;
?>

 

If you use brackets or escape it php knows that variable name and won't waste a ton of resources trying to find a variable that doesn't exist thus it result in echoing it out or fatal error.

Link to comment
Share on other sites

your still talking minimal amounts and most of the time you are phrasing a string with variables (other wise php doesn't provide you a lot of usefulness) so I personally use double quotes and then ". to escape any variable.

<?php
$var = "yes";
echo "Do you like php?<br />".$var;
?>

 

If you use brackets or escape it php knows that variable name and won't waste a ton of resources trying to find a variable that doesn't exist thus it result in echoing it out or fatal error.

 

a fatal error from PHP not finding a variable that matches what's in double quotes?  more like a blank space appearing there.  if you concatenate the variable, what's the point of even using double quotes?  you yourself said that's what it's useful for.

 

<?php
$var = "yes";
echo "Do you like php?<br />$var";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.