PHP MySql help :]

Status
Not open for further replies.

Hereisfun

Solid State Member
Messages
15
Location
San Marcos CA
Uhmmm I want to make a comment system thing...
I have the form and then the INSERT thing right
So i can insert stuff into my database from my form but i dont know how to get the info from my database and onto the place where i want the comments to be shown, so everyone can see them...
If anyone could help, that would be awesome :D
If you need the codes to see i can post on here
 
Well selecting the database is fine, but right now i have it so you can enter information into my database via a form. I want to take that data that was inserted into my database and have it posted right under the form. The book i bought told me how to use INSERT INTO and SELECT but then skipped the part i needed...

...It's hard for me to explain it..uhggg
Sorta like when i click post right here, it goes into the database and then onto the forum.
Mine just gets added into the database...
If you want to see what i mean go to :

Comment
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Comment</title>
<style type="text/css">
<!--
body {
background-image: url(Http://www.hereisfun.com/images/backgroundfun.jpg);
background-repeat: repeat;
}
-->
</style>
</head>

<body>

<table width="200" height="500" border="0" cellspacing="1" cellpadding="1" align="center">
<tr>
<td><font color="#FFFFFF"><form method="post" action="maybe.php">
<label for="firstname">First Name:</label>
<input type="text" id="firstname" name="firstname" /><br />
<label for="lastname">Last Name:</label>
<input type="text" id="lastname" name="lastname" /><br />
<label for="email">email:</label><br />
<input type="text" id="email" name="email" /><br />
<label for ="comment">Comment: </label>
<input name="comment" type="text" id="comment" value="" /><br />
<input type="submit" value="Enter Comment" name="submit" />
</form></font>
</td>
</tr>
</table>


</body>
</html>

And here is my other page that the form goes to
<html>
<head>
<title> Thank you for entering your comment. </title>
</head>
<body>

<?php

$firstname = $_POST[ 'firstname' ];

$lastname = $_POST[ 'lastname' ];

$email = $_POST[ 'email' ];

$comment = $_POST[ 'comment' ];

$dbc = mysqli_connect('databaselocation', 'mysql username', 'mysq password', 'database')
or die('Error connectiong to MYSQL server.');

$query = "INSERT INTO cmmnts (first_name, last_name, email, cmmnt) " .
"VALUES ('$firstname', '$lastname', '$email', '$comment')";

$result = mysqli_query($dbc, $query) or die('Error querying database.');
mysqli_close($dbc);
echo 'Thanks for submitting the form into the database!<br />';
echo ' ' . $firstname;
echo ' ' . $lastname . '<br />';
echo 'Email: ' . $email . '<br />';
echo 'Comment: ' . $comment . '<br />';
?>
<p><a href="form.php"> Post another comment. </a></p>

</body>


All of this works it just puts the stuff into the database
it doesnt put it on my site :/
i changed to password and database location and stuff but im 100% they work
 
Ahh yesh thats what iwant
iwnt the data to be posted on my website
what people comment


uhmmm heres the link

hereisfun.com/form.php

i want the comments to be posted under that form
if you just type in junk and look at what the next page says thank you it was inserted into the database

when i view the database
i can see my columns in the table i made
and then the inserts which the form has inserted from people filling it out
 
PHP:
<?php

$dbc = mysqli_connect('databaselocation', 'mysql username', 'mysq password', 'database')
or die('Error connectiong to MYSQL server.');

$sql = mysqli_query($dbc, "SELECT * FROM cmmnts");

while ($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)) {
	echo 'First Name: '.$row['first_name'].'<br />
		  Last Name: '.$row['last_name'].'<br />
		  Email: '.$row['email'].'<br />
		  Comment: '.$row['cmmnt'].'<br /><br />';
}

?>

I'm not 100% sure if this will work, because I never use mysqli...but try it.
 
Kmote: Thank you for helping me :]
CrazeD: Man your a genius! Code worked! Second time you helped me out!!! If theres anything i can do for you don't hesitate to ask! If there is anything i can do for you...lol
 
Status
Not open for further replies.
Back
Top Bottom