Hey im trying to create a registartion form and its allmost there,
The user can input there data
php connects to mysql and the database

it fails when trying to run the sql query i create this is the first time iv tried to edit a table through php and cant see whats going wrong.

Here is the actual sql statement:

$sql = "insert into customer
(Cust_ID, User_Name, Password, First_Name, Last_Name, Email) values
(\"$customerid\", \"$username\", password(\"$password\"),\"$firstname\",\"$lastname\",\"email\" )";

$result = @mysql_query( $sql, £conn )
or die("Could not execute query");

this i where it goes wrong everytime iv checked that the clumon names and variables are typed in correct in other than that im completly lost so any help would be great my full code is below

<html><head><title>Register</title></head><body>
<?php   $self =  $_SERVER['PHP_SELF'];
		$customerid = $_POST['customerid'];
		$username =	$_POST['username'];
		$password =  $_POST['password'];
		$firstname = $_POST['firstname'];
		$lastname = $_POST['lastname'];
		$email = $_POST['email'];

if( ( !$username ) or ( !$password ) or ( !$firstname )  or ( !$lastname )  or ( !$email ) )
{
$form ="Please Enter The Following Details To Create An Account";
$form.="<form action=\"$self\" ";
$form.=" method=\"post\"> Customer ID: ";

$form.="<input type=\"text\" name=\"customerid\" ";
$form.=" value=\"$customerid\"> <br>User Name: ";

$form.="<input type=\"text\" name=\"username\" ";
$form.=" value=\"$username\"> <br>Password: ";

$form.="<input type=\"text\" name=\"password\" ";
$form.="value=\"$password\"> <br>First Name: ";

$form.="<input type=\"text\" name=\"firstname\" ";
$form.="value=\"$firstname\"> <br>Last Name: ";

$form.="<input type=\"text\" name=\"lastname\" ";
$form.="value=\"$lastname\"> <br>Email: ";

$form.="<input type=\"text\" name=\"email\" ";
$form.="value=\"$email\"> <br>";

$form.="<input type=\"submit\" value=\"Submit\">";
$form.="</form>";
echo( $form );
}

else
{ 
$conn = @mysql_connect( "localhost", "root", "")
or die("could not make the connection");

$db = @mysql_select_db( "store", $conn )
or die("could not connect to database");

$sql = "insert into customer
(Cust_ID, User_Name, Password, First_Name, Last_Name, Email) values
(\"$customerid\", \"$username\", password(\"$password\"),\"$firstname\",\"$lastname\",\"email\" )";

$result = @mysql_query( $sql, £conn )
or die("Could not execute query");

if( $result ) 
{
echo( " New user $username added" ); }
}
?>
</body></html> 

</body>
</html>

the error code "or die("Could not execute query");" is what keeps displaying after i enter the data and click submit so it is getting pretty far through the code but crashes out on this last bit

    OK, I am fairly sure it is the password() which kills the query, but to be sure:

    change:
    $result = @( $sql, £conn )
    or die("Could not execute query");

    to:
    $result = @( $sql, £conn )
    or die(mysql_error()."=>".$sql);

    and post the output please

      Hey thanks for the reply

      i changed the code and got the following output

      =>insert into customer (Cust_ID, User_Name, Password, First_Name, Last_Name, Email) values ("3", "Test1", password("pass123"),"leo","powell","email" )

      im not too sure what that means but the last input-outputed seems quite strange as i entered 123@33 in the email input box yet in that out put it displays "email"

        ok, think I got it..

        cvhange:
        $sql = "insert into customer
        (Cust_ID, User_Name, Password, First_Name, Last_Name, Email) values
        (\"$customerid\", \"$username\", password(\"$password\"),\"$firstname\",\"$lastname\",\"email\" )";
        to:

        $pass = password($password);
        $sql = "insert into customer
        (Cust_ID, User_Name, Password, First_Name, Last_Name, Email) values
        (\"$customerid\", \"$username\",\"$pass\",\"$firstname\",\"$lastname\",\"$email\" )";
        

        and it should work ... ? Unless the password funtion doesn't work, but that is the next problem ;-)

          hmm

          that creates the error
          Fatal error: Call to undefined function password() in C:\xampp\htdocs\Shop\Register.php on line 48

          witch is as you said the password functions might not work.

          I create this php from a tutoiral sadly from a book so i cant link it.
          it states that using password(\"$password\") like in my code is a inbuilt mysql function that encrypts the password as a 16 digit hexadecimal number.
          fully how this works im not sure the book doesnt explain. but i imagine then that this needs to be kept in the sql statment as it is line 48 is where the new code
          $pass = password($password);
          was and that is also the error code

          i mutch appreciate your help, as i dont know where to start

            Ah, ok.

            In your originall query, you did:

            password(\"$password\")
            which should most likely be:
            password($password).

            Please note that you do need the $ sign in front of email in the query

              ok i tried changing the password function and writing as you said but the same error.
              Iv decided to take that bit out for the moment try to get the basics working first. So now the password just gets sent to the database as any other value would.

              still doesnt work though :queasy:

              Iv decieded to re-create the cable taken out the data types,primary key and auto-increase and leaving it all as VARCAHR.

              I Created the table with phpmyadmin witch creates the code

              $sql = 'CREATE TABLE customer ('
              . ' Cust_ID VARCHAR(10) NOT NULL, '
              . ' User_Name VARCHAR(30) NOT NULL, '
              . ' Password VARCHAR(15) NOT NULL, '
              . ' First_Name VARCHAR(40) NOT NULL, '
              . ' Last_Name VARCHAR(40) NOT NULL, '
              . ' Email VARCHAR(80) NOT NULL'
              . ' )'
              . ' ENGINE = myisam;';

              The table is created i can see the folder in my mysql\data\ the folder has in it
              customer.fr
              customer.MYD
              customer.MYI
              db.opt

              so to me the database and tables seem fine.

              what else could be going wrong all the examples i have seen are written just like my code?

              connect to database
              insert into [tablename]
              column names then values

              $conn = @mysql_connect( "localhost", "root", "")
              or die("could not make the connection");
              
              $db = @mysql_select_db( "store", $conn )
              or die("could not connect to database");
              
              $sql = "insert into customer
              (Cust_ID, User_Name, Password, First_Name, Last_Name, Email) values
              (\"$customerid\", \"$username\", \"$password\",\"$firstname\",\"$lastname\",\"$email\" )";

              thanks for any help

                What does the SQL show when you echo it out? What is the error message you get?
                Have you tried running the sql in a database interface, such as phpmyadmin?

                J.

                  hey

                  using phpmyadmin and running that script, but swaping the variables for actual scripted values it works fine and creates a new row

                  Inserted rows: 1 (Query took 0.0163 sec)

                  the sql error message is the same as before states:

                  =>insert into customer (Cust_ID, User_Name, Password, First_Name, Last_Name, Email) values ("12", "wez", "adr","leo","powell","123@333" )

                  and no row is created but iv copy and padted that sql shown above and ran the statement within phpmyadmin and its created a new row fine

                  so if the codes getting the values wright, the sql works when used outside the code and the databsae is working correctly, there must be something wrong with the way php is talking to mysql as the php cant insert the values into the table?

                    :queasy:
                    We have been sleeping:
                    $result = @( $sql, £conn )

                    should be:
                    $result = @( $sql, $conn )

                    or could even be:

                    $result = @( $sql )

                    if you only have one open connection.

                    oh.. And you do not need the @ symbols

                      lol thanks for all your help i appreciate you taking time to help me out, im sorry that after all that it was just me being dumb fingerd and hitting the pound key instead of the doller sign :quiet:

                      allthough you did still learn me the(mysql_error()."=>".$sql);
                      whitch is mutch more usefull than the or die("error message") i was using before
                      so hopefully you dont feel like youv wasted your time too much

                      but ITS WORKING thanks alot🙂

                      im gonna go learn how to use REGEXPs to check user input ill triple check i dont make a mistake like that again before asking for help

                        Write a Reply...