PDA

View Full Version : Displaying a MySQL Query result usin PHP


iamien
06-24-03, 22:50
Ok i'm trying to make a small test script that will query my database and display the result.

<html>
<body>
<?php
$db = mysql_connect("localhost", "****", "");
mysql_select_db("emp",$db);
$test = mysql_query("SELECT name FROM employees WHERE punch = 34");
printf("Name is %s, $test);
?>
</body>
</html>

now when i try to run this, i get
Parse error: parse error, unexpected $ in /home/fritzsof/public_html/php/recall.php on line 11
only line 11 is at the end of my script and there is nothing there
no if i ocmment out the printf statemtn this goes away so i know my erro is there
What am i doing worng and/or how can i display databse query results?

Vlad902
06-25-03, 17:18
you forgot a "

and PHP si not C, it's not:
printf("Name is %s, $test);

it's
echo "Name is $test";

iamien
06-25-03, 17:47
actual printf works ifne and i got it + tons mroe wokring hehe
thanks
i dont know echo alwasy giving me eror verso printf working fine any rreaosn to use echo over pritnf

Vlad902
06-25-03, 17:54
Are you using ' or " or <<<, if you keep switching between ' and " you're gonna get errors, I can't find a link but somewhere in the PHP manual in the first 100 pages it talks about this...

iamien
06-25-03, 19:18
whep i'll play with echo. it working so far and my sites getting going have cookies set up and that doing more html work then anything atm

da chicken
06-26-03, 12:50
Originally posted by Iamien
actual printf works ifne and i got it + tons mroe wokring hehe
thanks
i dont know echo alwasy giving me eror verso printf working fine any rreaosn to use echo over pritnf

Maybe you misspelt something? :D ;)

iamien
06-26-03, 13:20
quiet you :D