Page 1 of 1

Add User.php??

Posted: Mon Mar 07, 2005 4:56 am
by russellbcv
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.

Code: Select all

<html><head><title?Adding a User</title></head><body>
<?php       $self =      $_SERVER&#1111;'PHP_SELF'];
            $firstname = $_POST&#1111;'firstname'];
            $lastname =  $_POST&#1111;'lastname'];
            $username =  $_POST&#1111;'username'];
            $password =  $_POST&#1111;'password'];

if( ( !$firstname ) or ( !$lastname )
                   or ( !$username ) or ( !$password) )
&#123;
 $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 );
&#125;

else
&#123; $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 ) &#123; echo( "New User $username added" ); &#125;
&#125;
 ?> </body></html>

Any help would be much appreciated

Thanks

Russel

Weirdan| Please get yourself acquainted with the bbcode tags (and use them where appropriate)

Posted: Mon Mar 07, 2005 4:59 am
by Jean-Yves
You are missing a double-quote at the start of $lastname in the insert values

Posted: Mon Mar 07, 2005 10:48 am
by feyd
mysql suggests that people not use the password() function: http://dev.mysql.com/doc/mysql/en/Encry ... tions.html