PDA

View Full Version : Need Some PHP Help


Tyler
June 17th, 2007, 08:21 PM
Im always getting a "Could not execute error" and i dont know what im doing wrong can someone please help me. I have all my database info set up it just doesnt want to execute

Form Script:
<html>
<head>
</head>

<body>
<form action="register2.php" method="post">
Username: <form type="text" name="user" value="user"><br>
Password: <form type="password" name="pass" value="pass"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>PHP Script:
<html>
<head>
</head>
<body>
<?php
$self = $_SERVER['PHP_SELF'];
$user = $_POST['user'];
$pass = $_POST['pass'];


{ $conn = @mysql_connect( "localhost", "u70423688","284ad1" )
or die("Could not connect to MYSQL"); #Connecting to MYSQL
$db = @mysql_select_db( "d60385531", $conn )
or die("Could not select database"); #select database
$sql = "insert into users
(user,pass) values
(\"$user\",password(\"$pass\") )";
$result = @mysql_query( $sql, $conn )
or die("Could not execute query");
if( $result ) { echo( "New user $user added" ); }
}
?>
</body>
</html>

Ausaudriel
June 17th, 2007, 10:41 PM
Your PHP is fine (albeit messy.)

You just messed up your form. Change to:
Username: <input type="text" name="user" value="user"><br>
Password: <input type="password" name="pass" value="pass"><br>

Tyler
June 18th, 2007, 06:25 AM
It still comes up with a Can not execute query

Ausaudriel
June 18th, 2007, 07:03 AM
Worked fine for me after the edits to the form. O_o

LegosJedi
June 18th, 2007, 03:01 PM
You just messed up your form.

It wouldn't be the HTML, cause the PHP is generating that error. It's obviously a problem with your SQL statment, which is the following piece of code:

$sql = "insert into users
(user,pass) values
(\"$user\",password(\"$pass\") )";
$result = @mysql_query( $sql, $conn )
or die("Could not execute query");

Personally, I would change it to something like this:

$result = mysql_query("INSERT INTO users (user, password) VALUES ('$user', '$pass')") or die("Could not execute query!");

And I would md5 the password in PHP, cause I don't know what the password function that you have included in your query does.

Hope that helps!

Ausaudriel
June 18th, 2007, 11:28 PM
The error he's getting is created because of
$result = @mysql_query( $sql, $conn )
or die("Could not execute query");Meaning the query didn't get executed. The reason it didn't get executed is because his HTML form was screwed up and it wasn't getting passed to the PHP.

As I said, I tested it, and it works fine after the correction of the form.

LegosJedi
June 20th, 2007, 11:59 AM
But I'm looking at both his and yours side by side, and there's no difference. How could the form be the problem?

And I would suggest adding mysql_error() to your die so you can see the actual reason for the error.

Ausaudriel
June 20th, 2007, 03:44 PM
There is a difference, look:

Username: <form type="text" name="user" value="user"><br>
Password: <form type="password" name="pass" value="pass"><br>

That's his. Notice the <form type=

This is the correction, with <input type=

Username: <input type="text" name="user" value="user"><br>
Password: <input type="password" name="pass" value="pass">

He made a very simple mistake with his HTML which prevents any data from actually getting to the PHP, causing the error. If there's no data, there's nothing for the query to insert, and with his

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

he's getting his "Could not execute query" error as a result.

LegosJedi
June 21st, 2007, 05:15 PM
Wow, how did I miss that? That would most certainly solve your problem.