-1

I'm currently trying to enter data from a form in a wordpress web page into a mysql database.

here is the code from the html page on wordpress

<form action="<?php echo $_SERVER[PHP_SELF] ?>" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
 die('Could not connect: ' . mysql_error());
}

mysql_select_db("test", $con);

$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

if (!mysql_query($sql,$con))
{
  die('Error: ' . mysql_error());
 }
echo "1 record added";

mysql_close($con);
?> 

i have installed the phpexec plugin and that seems to be runing fine.

when i enter data in the form and i submit it doesnt appear in the database.

My primary key seems to auto increment telling me something happened but no data appears.

thanks in advance

4

1 回答 1

0

根据上面的评论,我会得到一本好书,并确保您正在学习如何正确安全地使用 MySQL 和 PHP。请参阅学习 PHP 和 MySQL - O'Reilly 媒体

于 2012-11-08T18:26:14.273 回答