Add User.php??
Posted: Mon Mar 07, 2005 4:56 am
Hi - I am very new to Apache, MySQL & PHP and and am I having problems creating an "Add_User.php" which is linked to a very basic database "my_database". When the submit button is pressed I get "Could not execute query" and if I look at the error log - line 3,4,5,6 & 7 could be the problem. I have copied my script below - please can you take a look and see if I have made an errors.
Any help would be much appreciated
Thanks
Russel
Weirdan| Please get yourself acquainted with the bbcode tags (and use them where appropriate)
Code: Select all
<html><head><title?Adding a User</title></head><body>
<?php $self = $_SERVERї'PHP_SELF'];
$firstname = $_POSTї'firstname'];
$lastname = $_POSTї'lastname'];
$username = $_POSTї'username'];
$password = $_POSTї'password'];
if( ( !$firstname ) or ( !$lastname )
or ( !$username ) or ( !$password) )
{
$form ="Please enter all new user details...";
$form.="<form action="$self"";
$form.=" method="post"text">First Name: ";
$form.="<input type="text" name="firstname"";
$form.=" value="$firstname"><br>Last Name: ";
$form.="<input type="text" name="lastname"";
$form.=" value="$lastname"><br>User Name: ";
$form.="<input type="text" name="username"";
$form.=" value="$username"><br>Password: ";
$form.="<input type="text" name="password"";
$form.=" value="$password"><br>";
$form.="<input type="submit" value="Submit">";
$form.="</form>";
echo( $form );
}
else
{ $conn = @mysql_connect( "localhost", "rcox","joshua" )
or die("Could not connect to MySQL");
$db = mysql_select_db( "my_database", $conn )
or die("Could not select database");
$sql = "insert into users
(first_name,last_name,user_name,password) values
("$firstname",\$lastname","$username",
password("$password") )";
$result = mysql_query( $sql, $conn )
or die("Could not execute query");
if( $result ) { echo( "New User $username added" ); }
}
?> </body></html>Any help would be much appreciated
Thanks
Russel
Weirdan| Please get yourself acquainted with the bbcode tags (and use them where appropriate)