Hi, I am trying to design my own forum/guestbook type thing (very simple for now) but I am having some php/mysql difficulties…
So, I have my MySQL database set up (with the files uploaded to the server), and a simple submit reply (which seems to work) and display (which doesn’t work) script going on, but the problem is displaying the user name and message (right now, all that is supposed to show up is the posters name and message, they can enter whatever they want to both and there is no registering yet). Whenever I submit a reply via the posting page, it doesn’t show up on the index page…
I already tried the script from various php/mysql guide web sites (an even the script on the php web site) to no success. (I hope this may not be due to the fact of a not so recent php version on my server! ๐ฎ ) So, anyway, here is my script for both pages so far (don’t worry about the database connecting part of the script (The part with the dbhost , dbun, and dbpass)):
The Login Page:
[code=php]<?php
$dbhost=”hostname”;
$dbun=”username”;
$dbpass=”hostpass”;
$db=mysql_connect($dbhost, $dbun, $dbpass) or die(mysql_error());
$database=”databasename”;
mysql_select_db($database) or die(mysql_error());
?>
<html><head><title>AoABB >> Post Reply</title></head><body>
<form method=”POST” action=”index.php”>
<center><a href=”index.php”>Index Page</a> | Post Reply<br>
<table width=”50%” border=”2″ cellpadding=”5″ cellspacing=”5″><tr><td><p><b>Post a Reply</b><br><br>
Name:<br><input type=”text” name=”username” maxlength=”20″><br>
Message:<br><textarea rows=”8″ cols=”40″ name=”message” wrap=”hard”></textarea><br></p>
<input type=”submit” value=”Submit!”><input type=”reset” value=”Clear!”>
<?php
$insertinfo = “INSERT INTO userinfo (username, message) VALUES (‘$username, $message’)”;
$query = mysql_query($insertinfo);
?>
</form></td></tr></table></body></html>
<?php
mysql_close($db);
?>
And the Index Page:
[code=php]<?php
$dbhost=”hostname”;
$dbun=”username”;
$dbpass=”userpass”;
mysql_connect($dbhost, $dbun, $dbpass) or die(mysql_error());
$database=”aoatech_aoabb”;
mysql_select_db($database) or die(mysql_error());
echo(“<html><head><title>Forum Index</title></head><body>”);
echo(“<center>Index Page | <a href=post.php>Post Reply</a><br>”);
echo(“<table border=2 cellpadding=5 cellspacing=5 width=75%>”);
$query = ‘SELECT * FROM userinfo’;
$result = mysql_query($query) or die(‘Query failed: ‘ . mysql_error());
while( $row = mysql_fetch_array( $result ) )
{
echo(“<tr><td width=25%>”);
print(“$row->username”);
echo(“</td><td width=75%>”);
print(“$row->message”);
echo(“</td></tr>”);
}
echo(“</table></body></html>”);
mysql_close();
?>
Ok, so a few questions:
1. Do I need the database connect things on the Login Page?2. I think that the code for displaying the username and message is wrong…if so, how can I fix it?3. Are there any other mistakes in my code? All this changing around by using guides and samples has most likly messed up my code somewhere because I haven’t been very organized… :rolleyes:
Also, I am trying to keep it simple, so don’t add any new features to the code unless it is needed for the entire script to work.
All help is needed and thanks in advance!
~Testinging