Add User.php??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
russellbcv
Forum Newbie
Posts: 2
Joined: Mon Mar 07, 2005 4:55 am

Add User.php??

Post 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)
User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

Post by Jean-Yves »

You are missing a double-quote at the start of $lastname in the insert values
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mysql suggests that people not use the password() function: http://dev.mysql.com/doc/mysql/en/Encry ... tions.html
Post Reply