« Reply #3 on: May 18, 2007, 10:07:53 AM »
<html>
<head><title>Register</title></head>
<body>
<?php
$self = $_SERVER['PHP_SELF'];;
$username = $_POST['username'];
$password = $_POST['password'];
if (!isset($_POST['submit'])) { //form hasn't been submitted
//the reason the next line is wrong is because will return a true statement
//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{ //form's been submitted
// MySQL details
$mysql_host="localhost";
$mysql_user="nikon";
$mysql_pass="lol";
$mysql_dbname="nutrition_db";
//Connect to MySQL
$conn = @mysql_connect( "localhost", "nikon", "lol" )
or die("Could not connect to MySQL");
//Selects the database
$db = @mysql_select_db( "nutrition_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>