I doesn’t seem to be inserting anything to the database. It prints out the code and everything else just fine, but nothing is being inserted to the database.
<form target="foo" action="php page location" method="post">
Username: <input type="text" name="user" />
<input type="submit" />
[php]<?PHP
If its loaded without form aka. if its in an iframe.
if($_POST[‘user’] == “”) {
} else {
This is MySql information so fill it out
$user_name = “user_name”;
$password = “passworld”;
$database = “database”;
$server = “server”;
Connecting to the database
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
$mysqli = new mysqli($server, $user_name, $password, $database);
if(mysqli_connect_errno()) {
echo "Connection Failed: " . mysqli_connect_errno();
exit();
}
if($stmt = $mysqli -> prepare(“SELECT * FROM sqlapply Where playername=? VALUES (?)”)) {
/* Bind parameters
s - string, b - boolean, i - int, etc */
$stmt -> bind_param("s", $_POST['user']);
/* Execute it */
$stmt -> execute();
/* Bind results */
$stmt -> bind_result($result);
/* Fetch the value */
$stmt -> fetch();
/* Close statement */
$stmt -> close();
}
/*$SQL = “SELECT * FROM sqlapply Where playername =”. $_POST[‘user’];
$result = mysql_query($SQL);
*/
if ($result) {
while ($db_field = mysql_fetch_assoc($result)) {
print ‘Your Apply Password is ‘.$db_field[‘applypassword’].’’;
}
}else {
$pass = rand_string(5);
$mysqli = new mysqli($server, $user_name, $password, $database);
if(mysqli_connect_errno()) {
echo "Connection Failed: " . mysqli_connect_errno();
exit();
}
//$SQL = “INSERT INTO sqlapply (playername, applypassword, time) VALUES (?, ?, ?)”;
/* Create a prepared statement */
if($stmt = $mysqli -> prepare(“INSERT INTO sqlapply (playername, applypassword, time) VALUES (?, ?, ?)”)) {
/* Bind parameters
s - string, b - boolean, i - int, etc */
$stmt -> bind_param("sss", $_POST['user'], $pass, time());
/* Execute it */
$stmt -> execute();
/* Bind results*/
$stmt -> bind_result($result);
/* Fetch the value */
$stmt -> fetch();
/* Close statement */
$stmt -> close();
}
/* Close connection */
$mysqli -> close();
Printing the password
print '<font size="+4">'.$_POST['user'].' Your Apply Password is '.$pass.'</font>';
print '<p><font size="+4"> Valid for 1 hour</font></p>';
print '<p><font size="+4">Make sure name is exact capitals</font></p>';
}
}else {
print "Database NOT Found ";
mysql_close($db_handle);
}
}
function rand_string( $length ) {
Characters random string can contain
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Creating the string
$size = strlen( $chars );
for( $i = 0; $i < $length; $i++ ) {
$str .= $chars[ rand( 0, $size - 1 ) ];
}
return $str;
}
?>
[/php]