Jump to content

Can't execute query

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
happy

happy

    Newbie

  • Members
  • PipPip
  • 25 posts
Im creating a registration form, in PHP (or atelast trying to). Im new to PHP and im struggling.

What I'm aiming for is the information (first name, last name, username and password) to be enetered into my PHP form and this information is then stored in the psql database (already created). This information can then be used later on on the log in page (yet to be created).

The first half of my script is running fine. The form displays and the user can enter the information. Once the submission form is hit this error appears:


Warning: pg_query() [function.pg-query]: Query failed: ERROR: function password("unknown") does not exist in /home2/webusers/07/344740/public_html/sporticket/reg.php on line 17
Could not execute query


As i said im new to PHP so if anyone is kind enough to explain what the error is can they please be explicit when explaining I'd appreciate it. Here is my script.

<html>
    <head><title> Register </title></head>
        <body>
<?php
  if(isset($_POST['first_name'])){  
    $first_name =   pg_escape_string($_POST['first_name']);
    $last_name =    pg_escape_string($_POST['last_name']);
    $username =   pg_escape_string($_POST['username']);
    $password =    pg_escape_string($_POST['password']);

    if ( ( !$first_name ) or (!$last_name) or (!$username) or (!$password) ){
      die("Missing some values");
    }

    $conn = @pg_connect("connection details hidden");
    $psql = "INSERT INTO users(first_name,last_name,username,password) VALUES ('$first_name','$last_name','$username',password('$password'))";   
    $result = pg_query($psql) or die ("Could not execute query");
    if ( $result ) {
      echo "Congratulations, You can now log into Sporticket with the username and password you supplied";
    } else {
      echo "Failed to add user";
    }
  }else{
        
        $form ="Please enter your details below to register with Sporticket";
        $form.="<form action=\"\"";
        $form.=" method=\"post\"> First Name: ";
        $form.="<input type=\"text\" name=\"first_name\"";
        $form.=" <br>Last Name: ";
        $form.="<input type=\"text\" name=\"last_name\"";
        $form.=" <br>Username: ";
        $form.=" <input type=\"text\" name=\"username\"";
        $form.=" <br>Password: ";
        $form.=" <input type=\"text\" name=\"password\"";
        $form.=" <br>";
        $form.=" <input type=\"submit\" value=\"Submit\">";
        $form.="</form>";
     
     echo $form;
  }
?>
        </body>
</html>

It may need to be said that I'm not using MySql, but using to putty to access my psql. Also I'm limited to PHP 5

If anyone could be kind enough to have a look, I'd be very greatful.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Well, in your query you have password('$password')... where's your password function that you're calling?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
happy

happy

    Newbie

  • Members
  • PipPip
  • 25 posts
I know thats whats causing the error. But i don't know how to rectify it.
:confused:

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Do you have a password function anywhere? What's it supposed to do?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
happy

happy

    Newbie

  • Members
  • PipPip
  • 25 posts
its supposed to add first name, last name, username and password into the database table 'users'.

then the information username and password will be used to log into the site

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Try this:

$psql = "INSERT INTO users(first_name,last_name,username,password) VALUES ('$first_name','$last_name','$username','$password')";
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
happy

happy

    Newbie

  • Members
  • PipPip
  • 25 posts
I had been racking my brain for days. And thats brilliant. Its what i wanted. The information stores into the database.
How can i elaborate this so that a user has to enter the password twice, and the passwords must match. If you haven't time to help me with this, its okay.

#8
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You'll need another form entry, like confirmpassword, and you need to call die if they aren't equal.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog