/    Sign up×
Community /Pin to ProfileBookmark

how do i print info in my database for viewers

[CODE]i am a geoscientist trying to build a career in database management and i have choose to study php which i am doing relentlessly on a self study basis.please i need you all to help me achieve just this: I have been able to create a mysql database and use a form to input data into the database but i have been trying to print/show all that has been stored in the database on a page so that it can be view.Pleeaaaassssee help me with this codes:mad:

<?php
$connection = mysqli_connect(“localhost”, “root”, “”, “latest_news”) or die (“error connection”);

$name = $_POST[“txt_name”];
$len = strlen($name) ;
if ($len >0)
{
$email = $_POST[“txt_email”];
$comment = $_POST[“txt_comment”];
$date = time();

$query = “INSERT INTO guest_book( autoID, name, comment, date_auto) VALUES( NULL, ‘$name’, ‘$comment’,’$date’)”;

$res = mysqli_query( mysqli_connect(“localhost”, “root”, “”, “latest_news”), $query) or die ( mysqli_error());
}

?>
<html>
<head>
<title>guest_book</title>
</head>

<body>
<center>
<form method=”post” action=”<?php echo $_SERVER[‘PHP_SELF’];?>”>
<p>Name:
<input name=”txt_name” type=”text” id=”txt_name” />
</p>
<p>Email:
<input name=”txt_email” type=”text” id=”txt_email” />
</p>
<p>Comment:
<textarea name=”txt_comment” id=”txt_comment”></textarea>
</p>
<p>
<input name=”btn_Submit” type=”submit” id=”btn_Submit” value=”Submit” />
<input name=”btn_Reset” type=”reset” id=”btn_Reset” value=”Reset” />
</p>
</form>
<br>
<table bgcolor=”#AAAAAA” border=”0″ width=”75%” cellspacing=”1″ cellpadding=”2″>
<?php

$query = ” SELECT * FROM guestbook ORDER BY date_auto”;
$result = mysql_query ( $query, mysql_connect(“localhost”, “root”, “”, “latest_news”));
for( $i = 0; $i < mysql_num_rows(mysql_query ( $query, mysql_connect(“localhost”, “root”, “”, “latest_news”))); $i++)
{
$name = mysql_result ( $result, $i, “name”);
$email = mysql_result ( $result, $i, “email”);
$email_len = strlen ($email);
$comment = mysql_result ( $result, $i, “comment”);
$date = mysql_result ( $result, $i, “date_auto”);
$show_date = date(“H:i:s m/d/y”, $date);

echo’
<tr>

<td with= “50%” bgcolor= “#EEEEEE”>
<font face = “arial” size= “2”>’;
if ( $email_len>0)
{
echo ‘<b> name: </b> <a href= “mailto:’.$email.’>” ‘.$name. ‘
</a>’;

}
else
{
echo ‘<b> name: </b>’ .$name;

}
echo’
<br>
<b>comment:</b>’.$comment.’
</font>
<td>
<td width = “1%” valign = “top” nowrap bgcolor = “#EEEEEE”>
<font>
<b> Date:</b>’.$show_date.’
</font>
</td>
</tr>
‘;

}

?>

</table>
</center>
</body>
</html>

[/CODE]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @bodjem spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...