Jump to content

[SOLVED] Display entry from database to browser


ubuntu

Recommended Posts

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>

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());";

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?

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>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.