I'm wearing myself out trying to figure out why my username and password don't work with my db connect. I use a username and password and my if statement for db connect throws an error. If I set the database to any user and remove the username and password, it connects flawlessly. It's just beyond me. I've never had a problem like this. Even my other database with a DB connect works with the username and password.
More importantly, I've worked out all of the syntax errors and the code executes fine, it just doesn't insert data into the employee column of the employee table in the database I've targeted. Like I said, I got so mad trying to fix the user name and password, I set it to any user. Since it's running in localhost for the time being the important part is figuring out why I can't get it to connect. :xbones:
Here's the syntax. Since it's on localhost, we can focus on one problem at a time.
<?php
// create short variable names
@ $employee = $_POST['employee'];
if (!$employee) {
echo "You have not entered all the required details.<br />"
."Please go back and <a href=newemployee.php>try again</a>.";
exit;
}
@ $db = new mysqli('localhost', 'dbname');
if (mysqli_connect_errno()) {
echo "<strong>Error:</strong> Could not connect to database. Please contact the system administrator or <a href=newemployee.php>try again</a>.";
exit;
}
$query = "insert into employee values
('".$employee."')";
$result = $db->query($query);
if ($result) {
echo $db->$employee." name inserted into database.";
} else {
echo "An error has occurred. The employee was not added. <br /> Click <a href=newemployee.php>here</a> to try again.";
}
$db->close();
?>
If we don't see anything wrong with the syntax, I'll no that I need to restructure the database in some fashion.
If you need I can also post the schema, with changed names to protect the innocent. =)