ubuntu Posted May 14, 2007 Share Posted May 14, 2007 Hello everyone, I can't display entry from database to browser, what's wrong with my code? Thank you for your kind attention. Regards. <?php $connection = mysql_connect("$host", "$user", "$password") or die(mysql_error()); $db = mysql_select_db($database, $connection) or die(mysql_error()); $sql = "select fullname from pendaftaran where username = '$_COOKIE[username]'" or die(mysql_error()); ?> <html> <title><head>Display entry from database</head></title> <body> <p><?php echo $sql; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
StormTheGates Posted May 14, 2007 Share Posted May 14, 2007 Its because you ended the SQL string to early: $sql = "select fullname from pendaftaran where username = '$_COOKIE[username]'" or die(mysql_error()); Needs to be $sql = "select fullname from pendaftaran where username = \'$_COOKIE[username]\' or die(mysql_error());"; Quote Link to comment Share on other sites More sharing options...
ubuntu Posted May 14, 2007 Author Share Posted May 14, 2007 Thank you StormTheGates, however, I've try your code, but the result display was: Let's say the username set in cookie was user1 & fullname in database is Jack Display results: select fullname from pendaftaran where username = \'user1\' or die(mysql_error()); I wonder, why it display the whole sql statement? Quote Link to comment Share on other sites More sharing options...
StormTheGates Posted May 14, 2007 Share Posted May 14, 2007 Well I thought thats what you wanted? Or do you want to just display something out of the SQL statement? If you want to display the thing from the SQL query do something like this: <?php $connection = mysql_connect("$host", "$user", "$password") or die(mysql_error()); $db = mysql_select_db($database, $connection) or die(mysql_error()); $result = mysql_query("SELECT select fullname from pendaftaran where username = '$_COOKIE[username]'") or die(mysql_error()); $row = mysql_fetch_array($result); $fullname = $row['fullname']; ?> <html> <title><head>Display entry from database</head></title> <body> <p><?php echo $fullname; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
ubuntu Posted May 14, 2007 Author Share Posted May 14, 2007 I want the display result as following. Display result: Jack Quote Link to comment Share on other sites More sharing options...
StormTheGates Posted May 14, 2007 Share Posted May 14, 2007 Yea the above code should work then. Quote Link to comment Share on other sites More sharing options...
ubuntu Posted May 14, 2007 Author Share Posted May 14, 2007 Yes, thank you StormTheGates, you are so expert! Appreciated. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.