AWESOME! That worked! It's inserting into the table now!!
Here are a few things I'm trying now that aren't working.
When the form is submitted, it's supposed to add a time stamp (it's one of the fields in the table). When I add the php, the output is an error, or a weird character. Here's the code:
Code: Select all
<?php
$connect = mysql_connect("localhost","root","xxxxxxxx") or die(mysql_error());
mysql_select_db("feedback") or die(mysql_error());
$_POST = array_map('mysql_real_escape_string', $_POST);
$time = date("Md 'y");
$sql = "INSERT INTO `main` (time, site, name, comment) VALUES('{$time['time']}', '{$_POST['site']}', '{$_POST['name']}', '{$_POST['comment']}')";
mysql_query($sql) or die(not updated);
$ref = $_SERVER['HTTP_REFERER'];
header( 'refresh: 02; url='.$ref);
mysql_close($connect);
?>
I think the syntax is wrong where the variable ($time) is inserted into the table here:
The second thing is that because of the way it's laid out, I'd like to have the 'insert into table name' section be on the page with the form. So it looks like this:
Code: Select all
<form action="process.php" method="post">
who: <input type="text" name="name" />
site: <input type="text" name="site" />
what: <input type="text" name="comment" />
<input type="submit" value="post" />
</form>
<?php
$time = date("Md 'y");
$sql = "INSERT INTO `main` (time, site, name, comment) VALUES('{$time['time']}', '{$_POST['site']}', '{$_POST['name']}', '{$_POST['comment']}')";
?>
which should pass it to the process.php page which looks like this:
Code: Select all
<?php
$connect = mysql_connect("localhost","root","xxxxxxxx") or die(mysql_error());
mysql_select_db("feedback") or die(mysql_error());
$_POST = array_map('mysql_real_escape_string', $_POST);
mysql_query($sql) or die(not updated);
$ref = $_SERVER['HTTP_REFERER'];
header( 'refresh: 02; url='.$ref);
mysql_close($connect);
?>
When I set it up this way, it doesn't work. No error is given. It's not passing the values of the variables to the process.php page? Where the form php is, should I use a "require once" to send the data to the process page - or is the forms action doing that?
The third thing I would like to try is when the site field is filled out, it'll be a url - I'd like to have it wrap the 'name' entry as a link, so when the feedback is displayed, a visitor can click on the name in a post and it'll open the link in a new window. (To combine the "name" and "site" fields when displayed, but adding a href="$site" target="_blank">$name</a .)
I don't have any idea how that's done php wise. I searched a ton of key words and couldn't find anything - does anyone know how to do that?