...how does one put "DB vars into an include file and have a database class?
🙂
If I were to have the mysql connection on the Form Page, how would that work?
I have two areas of the page that need to use the connection (insert contents into a table, and display contents of a table).
Isn't there a way to have the mysql connect info at the top...
display the table contents once then end...
If the form is submitted, write the contents to the table (if not, do nothing).
Here's what I have, and it doesn't work right:
<?php
$connect = mysql_connect("localhost","root","xxxxx") or die(mysql_error());
mysql_select_db("feedback") or die(mysql_error());
$result = mysql_query("SELECT * FROM main");
while($row = mysql_fetch_array($result))
{
echo $row['time'] . " " . $row['name'] . " " . $row['site'] . "<br /><i>" . $row['comment'] . "</i><br /><br />";
}
mysql_close($connect);
?>
<div id="right">
<form action="process.php" method="post">
<input type="text" name="name" size="20" value="your name" style="border:0px;color:#A7A7A7;font-size:11px;" onFocus="this.value=''" /><br /><br />
<input type="text" name="site" size="20" value="your website" style="border:0px;color:#A7A7A7;font-size:11px;" onFocus="this.value=''" /><br /><br />
<textarea name="comment" rows="12" cols="19" style="border:0px;color:#A7A7A7;font-size:11px;" onFocus="this.value=''">your feedback</textarea><br /><br />
<input type="submit" value="post" />
</form>
<?php
$connect = mysql_connect("localhost","root","xxxxx") or die(mysql_error());
mysql_select_db("feedback") or die(mysql_error());
$_POST = array_map('mysql_real_escape_string', $_POST);
$time = date("[d My]");
$site = $_POST["site"];
$sql = "INSERT INTO `main` (time, site, name, comment) VALUES('$time', '{$_POST['site']}', '{$_POST['name']}', '{$_POST['comment']}')";
mysql_query($sql) or die(updating);
mysql_close($connect);
?>