Page 1 of 1

conceting variables...

Posted: Sun May 28, 2006 4:22 pm
by a94060
Ok,i promise this will be the alst time that i am going to ask a question liek this,but how do i use variable sin a sql statement or anywhere else.

Like for example,i have this code

Code: Select all

while($result = mysql_fetch_array($query)) {
		  		echo "Title:'.$result['title'].'";
		  		<hr>
		  		echo "Written By: '.$result['author'].'";
		  		echo "Date: '.$result['date'].'";
		  		echo "Time: '.$result['time'].'";
		  		}
i get :Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/noob/public_html/index.php on line 56
im not sure what it means but i think it is relevant to this piece of code.

Also,say in this SQL statement

Code: Select all

$query = ("SELECT name,pass,email FROM users WHERE name='.$name.' AND pass='.$md5.'");
Im pretty sure that i did something wrong with variables in both of them,could someone help me?

Posted: Sun May 28, 2006 4:32 pm
by twigletmac
You've got your quotes a bit mixed up - if you start a string with double quotes (or single quotes) you need to end it with the same so you could try:

Code: Select all

while($result = mysql_fetch_array($query)) {
	echo 'Title: '.$result['title'];
	echo '<hr>';
	echo 'Written By: '.$result['author'];
	echo 'Date: '.$result['date'];
	echo 'Time: '.$result['time'];
}
Also, variables within double quoted strings are parsed whereas those in single quoted strings aren't so the SQL statement you posted could be changed to (the single quotes in the double quoted string don't mean anything special to PHP):

Code: Select all

$query = "SELECT name, pass, email FROM users WHERE name='$name' AND pass='$md5'";
Mac

Posted: Sun May 28, 2006 4:34 pm
by a94060
ok,thanks,ill try that