Jump to content

Storing Data From a Form


porzant

Recommended Posts

Sorry about the stretching! Not sure how to fix it.I want to be able to store form inputs, so that a user can view them all. I think this may need an SQL database, but I'm not sure :S. If it does, can anyone suggest where I can get one free please :).This is the HTML code for the form:

<html><head><title>Porzant's Shoutbox</title></head><body><form action="http://porzant.awardspace.com/comment.php" method="post" onsubmit="settime()"><table><tr><td>Name: </td><td><input type="text" name="Name" maxlength="12" size="20" /></td><input type="hidden" name="Date" value="Set by Javascript function: settime(). Don't worry about that" /></tr><tr><td>Message: </td><td><input type="text" name="Message" maxlength="250" size="50" /></td></tr></table><input type="submit" value="Post Message" /></form></body></html>

Here is the PHP code that its linking to:

<?phpecho "<table width='600px'><tr><td valign='top' align='left' width='75px'>".$Name."<br />".$Date."</td><td width='25px'> </td><td valign='top' align='left'>".$Message."</td></tr></table>"?>

To store the data from the form, I think it needs to be in a database, and then called as some kind of array. All help appreciated, thanks :).

Link to comment
Share on other sites

So would I use a code like this? :NOTE: Fields from the form are called Name, Date, Message.

$con=mysql_connect("fdb1.awardspace.com","porzant_shoutbox",password);INSERT INTO `shoutbox` ( `Name` , `Date` , `Message` ) VALUES ('$_POST[Name]', '$_POST[Date]', '$_POST[Message]');

^ That would add the records to the database, if I'm correct? Does that go in the PHP file?To show them, would I use this? :

mysql_select_db("porzant_shoutbox", $con);$result = mysql_query("SELECT * FROM table_name");while($row = mysql_fetch_array($result))  {  echo $row['Name'] . " " . $row['Date']." ".$row['Message'];  echo "<br />";  }mysql_close($con);

Not really sure about those codes, any tips would be great :).

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...