I have bought a book to learn PHP. I have got to the database bit and can't get any further because I think there is something wrong with the installation.
Here is the code I copied from the book and modified a bit. It is a webform where somebody creates a user id and the user id info gets written to a mysql database. When I run it on apache, nothing happens at all. I press the submit button and nothing!! no error message, it just does nothing.
When I change the mysql login name to one that doesn't exist, it should die, but it doesn't. But if I miss out a ; or { then I get an error message, so it must be reading the script.
<html>
<title>TITLE</title>
<head>
<style type="text/css">@import url(styles/forms.css);</style>
</head>
<body>
<body background="images/bg2.gif">
<br>
<center>
<table width = "85%" border="1" bgcolor="white" cellpadding="20">
<td style="background:url('images/scales2.gif') 50% 50% no-repeat;">
<center><h1>Create User ID</font></h1>
<img src="images/image.gif"><br>
<?php
if (isset($POST['submit'])) {
$mysqli = new mysqli("localhost", "user", "password", "user");
if ($mysqli === false) {
die("ERROR: Could not connect to database. " . mysqli_connect_error());
}
// open message block
echo '<div id="message">';
// retrieve and check input values
$inputError = false;
if (empty($_POST['username'])) {
echo 'ERROR: Please enter a User ID';
$inputError = true;
} else {
$username = $mysqli->escape_string($_POST['username']);
}
if ($inputError != true && empty($_POST['password'])) {
echo 'ERROR: Please enter a password';
$inputError = true;
} else {
$password = $mysqli->escape_string($_POST['password']);
}
if ($inputError != true && empty($_POST['email'])) {
echo 'ERROR: Please enter an email address';
$inputError = true;
} else {
$email = $mysqli->escape_string($_POST['email']);
}
$date= date("Y-m-m", mktime());
//add new user to database
if ($inputError != true) {
$sql = "INSERT INTO Users (username, password, rating, postnum, threadnum, joined, active, email)
VALUES ($username, $password, Beginner, 0, 0, $date, n, $email)";
if ($mysqli->query($sql) === true) {
echo 'Your ID has been created, you can now log in' . $mysqli ->insert_id;
}else {
echo "ERROR: Could not execute query: $sql. " . $mysqli->error;
}
}
// close message block
echo '</div>';
// close connection
$mysqli->close();
}
?>
</div>
<form action="createid.php" method="POST">
Username: <input type="text" name="username" size="20" />
<p/>
Password: <input type="password" name="password" size="20" />
<p/>
Email Address (for verification): <input type="text" name="email" size="100" />
<p/>
<input type="submit" name="submit" value="Submit" />
</form>
</center>
</td>
</table>
<br>
</center>
</body>
</html>
I am on day 2 now of trying to work out what is wrong and I think it has something to do with:
In the book it says, when installing PHP find the php.ini file and
alter extension_dir = "./" to read
extension_dir = "c:\php\ext\"
and remove the ; from
extension=php_pdo.dll
extension=php_sqlite.dll
extension=php_mysqli.dll
extension=php_pdo_sqlite.dll
extension=php_pdo_mysqli.dll
But, two of these lines are not even in the php.ini file and the .dll files are not even in the ext folder. The missing lines are
extension=php_pdo.dll
extension=php_pdo_mysqli.dll
and the corresponding dll files are missing from ext folder. Does the program not working have anything to do with this? I have checked the db and no fields have been updated.