Question:
How does one insert html form data into an existing table?
NelsonBig
2012-07-20 13:00:55 UTC
I would like to create a simple form that sends the data to an existing table just below it.

The table would get an additional row at the top.

Basically, this is going to be a user-generated data table.

I'm good with creating the form. I'm good with creating the table. I just can't get the form data to create a new row on the table.

If possible, I'd like to keep this strictly html. Thank you all, in advance.
Three answers:
Wertle Woo
2012-07-20 13:57:43 UTC
Are you using a database to store the records? If so, here's an example of adding a comment section to a page with the PHP for retrieving all stored comments to display, then a section to allow the user to enter comments, then the PHP file used to send the user's comments to the database (tested on my own page and it works):





DISPLAY ALL COMMENTS FROM A DATABASE:




$username="dbo123456";

$password="password";

$database="db654321";

$localhost="db123.whatever.net";



mysql_connect($localhost,$username,$password);

mysql_select_db($database) or die( "Unable to reach database");



$query="SELECT * FROM tablename";

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();



// echo "
Comments


";

$i=0;

while ($i < $num) {

$Name=mysql_result($result,$i,"Name");

$IP=mysql_result($result,$i,"IP");

$Comment=mysql_result($result,$i,"Comment");

echo "$Name $IP
$Comment

";

$i++;

}

?>



ALLOW USER TO ENTER COMMENTS:









Name:  



Comment:






   











// THE PHP FOR ADDING THE NEW COMMENT




$Name = $_POST['Name'];

$IP = $_SERVER['REMOTE_ADDR'];

$Comment = $_POST['Comment'];



$database = "db654321";

$localhost = "db123.whatever.net";

$username = "dbo123456";

$password = "password";



mysql_connect($localhost, $username, $password);

mysql_select_db($database) or die("Unable to reach database");



$query = "INSERT INTO tablename VALUES

('$Name', '$IP', '$Comment')";



$result = mysql_query($query);

print "";



mysql_close();

?>





EDIT: Are you quite sure you know what you're talking about?
Diane
2016-05-18 18:25:38 UTC
Create table: create table check (id int not nul auto_increment primary key, email varchar(50)) Check whether session contains value or not.
David
2012-07-20 13:41:27 UTC
You'd have to use JavaScript to do something like that.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...