Hey,
Last night i coded a silly little login script for practice. I'm not the world's best programmer, and I've not used php in over a year, I've been using pascal and C++.
Can anyone see why, when I push submit, the script just refreshes rather than submitting the data to MySQL?
<html>
<head><title>Register</title></head>
<body>
<?php
$self = $_SERVER['PHP_SELF'];;
$username = $_POST['username'];
$password = $_POST['password'];
if( ( $username == NULL ) or ( $password == NULL ) ) {
$form ="Please enter all new user details...";
$form.="<form action=\"$self\"";
$form.="method=\"post\">Username: ";
$form.="<input type=\"text\" name=\"username\"";
$form.=" value=\"$username\"><br>Password: ";
$form.="<input type=\"text\" names=\"password\"";
$form.=" value=\"$password\"><br>";
$form.="<input type=\"submit\" value=\"Submit!\">";
$form.="</form>";
echo( $form );
}else{
// MySQL details
$mysql_host="localhost";
$mysql_user="user";
$mysql_pass="pass";
$mysql_dbname="db";
//Connect to MySQL
$conn = @mysql_connect( "localhost", "user", "pass" )
or die("Could not connect to MySQL");
//Selects the database
$db = @mysql_select_db( "db", $conn )
or die("Could not select database");
//creates the query
$sql = "insert into users (username, password) values ('".$username."', '".$password."')";
$result = @mysql_query( $sql, $conn )
or die("Could not execute query");
if( $result !== FALSE)
echo( "New user $username added" );
}
?>
</body>
</html>