PHP script won't execute query to MySQL...

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
shawn.berg
-


Joined: 27 May 2004
Posts: 16
Location: Minnesota

PostPosted: Mon Jun 07, 2004 8:11 am    Post subject: PHP script won't execute query to MySQL... Reply with quote

I'm at a loss. This code I wrote is pretty straight forward, but for some reason will not query with MySQL. This script I wrote, helps me to add new clients to my database QUICKLY. Here is the code:

Code:
<?php
#Define variables
$company='company';
$firstname='firstname';
$lastname='lastname';
$username='username';
$password='password';
 
if( (!$company) or (!$firstname) or (!$lastname) or (!$username) or (!$password) )
{
 
 echo("Please enter missing information");

}
else
{
  #connect to MySQL
  $conn = @mysql_connect("localhost","my_username","my_password")
              or die("Could not connect to MySQL");
  #select a database
  $db = @mysql_select_db("clients",$conn)
              or die("Could not select database");
  #create the SQL query
     $sql = "insert into users     (company,first_name,last_name,user_name,password)
  values (\"$company\",\"$firstname\",\"$lastname\",\"$username\",password(\"$password\") )";
 
 #execute the query
     $result = @mysql_query($sql,$conn)
              or die("Could not execute query");
  if($result)
  { echo("New user $username added"); }
}
?>


Of course the fields are in an external HTML form. When I press "submit" it comes up "Could not execute Query". Am I just too tired, or am I missing something? My database name is right as is my table name I'm inserting the info into.

Thanks ahead of time!

Shawn.Berg
Back to top View user's profile Send private message MSN Messenger
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Wed Jun 09, 2004 12:55 pm    Post subject: Re: PHP script won't execute query to MySQL... Reply with quote

shawn.berg,

To have more explicit error messages, change:

Code:

or die("Could not execute query");


with

Code:

or die("Could not execute query (MYSQL Error #" . mysql_errno() . ": " . mysql_error() . ")");


Execute again your script and you should have more information about the cause of the error.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group