While it is not showing any errors that I can see, my input from an HTML form is not working. I copied part of the script from Visual QuickPro Guide book on PHP 6 and MYSQL 5. I only had one input , so I modified the script for my uses. My database name is mytestdayabse, the table is userdata, and I have two columns called name and email. I just wanted to post a name. Here is the code for each script:
Morning.HTML :
<html>
<head><title></title></head>
<body>
<form action="php_handler.php" method="post">
<p>Name:
<input type="text" name="name" size="20" maxlength="20" />
<p><select name="occupation">
<option value="service">Customer Service </option>
<input type="submit" name="y" value="submit my data" /></body>
</html>
php_handler.php:
<?php
if (isset($_POST['submit'])){
$fn=trim($_POST['name']);
$errors=array();
if(empty($_POST['name']))
{
$errors[]="You forgot to enter a name";
}
else {$fn=trim($_POST['name']);}
if (empty($errors))
{
require_once('/mysqli_connect.php');
$q="INSERT INTO userdata ('name') VALUES('$fn')";
$r=mysqli_query($dbc,$q);
if($r)
{
echo"Thank you!";
}
else
{
echo"System Error";
}
mysqli_close($dbc);
exit();
}
}
?>
mysqli_connect.php:
<?php
DEFINE ('DB_USER','root');
DEFINE ('DB_PASSWORD','');
DEFINE ('DB_HOST','localhost');
DEFINE ('DB_NAME','mytestdatabase');
$dbc=mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME) or die ('could not connect to DB'. mysqli_error());
?>
By the way I know I will need to change root, it is just I am having a hard time changing privleges for another account. I am using the zwamp environment, and everything is working to my knowledge. It just shows a blank page, which confuses me. Any thoughts? Thanks.