Register.php
<?php
include("db.php");
if (isset($_POST['email']) && isset($_POST['password']) && isset($_POST['name']) && isset($_POST['password2']) && isset($_POST['name']) && isset($_POST['address']) && isset($_POST['city']) && isset($_POST['state']))
{
$con=mysqli_connect("localhost", "useradmin", "FNEpsTa6qvmRjBBf", "userdata") or die("failed to connect");
//Prevent SQL injections
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$address = mysql_real_escape_string($_POST['address']);
$city = mysql_real_escape_string($_POST['city']);
$password = mysql_real_escape_string($_POST['password']);
$password2 = mysql_real_escape_string($_POST['password2']);
//Get MD5 hash of password
$password = md5($_POST['password']);
$query="SELECT email FROM users WHERE email = '".$email."'";
$query2="INSERT INTO users (name, email, address, city, state, password) VALUES ('$name', '$email', '$address', '$city', '$state', '$password');";
//Check to see if email exists
$sql = mysqli_query($con, $query);
$rows=(mysqli_num_rows($sql));
if($rows>0)
{
die ("email taken.");
}
if($password<>$password2)
{
die ("passwords do not match");
}
$sql = mysqli_query($con, $query2);
if($sql)
header(location:welcome.php);
}
?>
<html></html>
<center>
<form action="register.php" method="post">
<table>
<tr><td>Name: </td><td><input name="name" type="text" /></td></tr>
<tr><td>Email:</td><td> <input name="email" type="text" /></td></tr>
<tr><td>Address: </td><td><input name="address" type="text" /></td></tr>
<tr><td>City: </td><td><input name="city" type="text" /></td></tr>
<tr><td>State: </td><td><select name="State">
<option value="" selected="selected">Select a State</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select></td></tr>
<tr><td>Password: </td><td><input type="password" name="password" /></td></tr>
<tr><td>Confirm Password: </td><td><input type="password" name="password2" /></td></tr>
<tr><td><input type="submit" value="Submit" /></td></tr>
</table>
</form></center>
ページはエラーなしで実行されますが、データベースに表示されません データを入力して [送信] をクリックすると、エラーなしでページに戻りますが、情報がデータベースに挿入されません。また、私が確認したように、データベース接続は良好です。ただし、以下はデータベースのエクスポートです。
CREATE DATABASE userdata;
USE userdata;
CREATE TABLE IF NOT EXISTS `users` (
`Name` varchar(50) NOT NULL,
`Address` varchar(50) NOT NULL,
`City` varchar(25) NOT NULL,
`State` varchar(2) NOT NULL,
`Email` varchar(25) NOT NULL,
`Password` varchar(25) NOT NULL,
PRIMARY KEY (`Email`),
UNIQUE KEY `Password` (`Password`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
php myadmin でそのパスワードを使用してユーザーを作成したので、それが良いことを知っています。