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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>

 

 

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.