I need a little help with my php script and getting it to function from Wordpress. I have installed a plugin that can run my php script. But when I input data into the fields and press submit, the form clears and nothing is added to the db. Where am I going wrong?
First with my HTML as followed:
<form method="post">
<table style="height: 149px;" width="220">
<tbody>
<tr>
<td style="width: 102px;">Medlemsnr:</td>
<td style="width: 102px;"><input name="stor_medlemsnr" type="smallint" />
</td>
</tr>
<tr>
<td style="width: 102px;">Navn:</td>
<td style="width: 102px;"><input name="stor_navn" type="text" /></td>
</tr>
<tr>
<td style="width: 102px;">Båd:</td>
<td style="width: 102px;"><input name="stor_baad" type="text" /></td>
</tr>
<tr>
<td style="width: 102px;">Dato:</td>
<td style="width: 102px;"><input name="stor_date" type="date" /></td>
</tr>
<tr>
<td style="width: 102px;">Art:</td>
<td style="width: 102px;"><input name="stor_art" type="text" /></td>
</tr>
<tr>
<td style="width: 102px;">Kg:</td>
<td style="width: 102px;"><input name="stor_kg" type="decimal(11,0)" /></td>
</tr>
</tbody>
</table>
<input type="Submit" />
[xyz-ips snippet="insert"]
The above "insert" calls the following php:
$servername = "localhost";
$username = "******dk_user";
$password = "********";
$dbname = "******dk_storfanger2017";
$con = mysql_connect(localhost,$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db( $dbname, $con);
$sql="INSERT INTO `******dk_storfanger2017`.`stor_2017` (`2017_medlemsnr`,
`2017_navn`, `2017_dato`, `2017_baad`, `2017_art`, `2017_kg`)
VALUES($_POST[stor_medlemsnr],$_POST[stor_navn],$_POST[stor_baad],
$_POST[stor_date],$_POST[stor_art],$_POST[stor_kg])";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
I hope somebody is able to point me in the right direction, getting this to work.
I also tried building it into insert.php, but wordpress will not accept the page, and gives me a HTTP 500 error when trying to access it.
I think $_POST['stor_kg'] is right thing not $_POST[stor_art] :
$sql="INSERT INTO `******dk_storfanger2017`.`stor_2017` (`2017_medlemsnr`,
`2017_navn`, `2017_dato`, `2017_baad`, `2017_art`, `2017_kg`)
VALUES(". $_POST['stor_medlemsnr'] .",". $_POST['stor_navn'] .",".
$_POST['stor_baad'] .",". $_POST['stor_date'] .",".
$_POST['stor_art'] .",". $_POST['stor_kg'] .")" ;