NameSilo

Query wont run

Spaceship Spaceship
Watch
Impact
19
Hey
whats wrong wid the query ? it wont work
PHP:
<?

$username = $_GET['user'];
$pass = $_GET['pass'];
$email = $_GET['email'];
$registerpass = $_GET['registerpass'];
$dbusername="zubair";
$dbpassword="";
$database= "z_game";

if (($registerpass == "z3nixrul3s") && ($pass != '') && ($email !='') && ($username!='')) {
mysql_connect(localhost, $dbusername, $dbpassword);

@mysql_select_db($database) or die( "Unable to select database");
$query= "INSERT INTO user (id, username,email,pass) VALUES ('', '$username','$email','$pass')";
mysql_query($query)or die('Error, insert query failed');
}
?>
or gives the error
Code:
Error, Insert Query Failed
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
1.) Why are you using $_GET?
2.) Try echo'ing $query and see what it prints.
 
0
•••
this is what i get :

Code:
INSERT INTO user (id, username,email,pass) VALUES ('', 'zubair','a','a')

I am using the GET statements because i am not making this for a website
i am making a Game in TURING [really old programming language :p] and its almost impossible to make a game online..so i am using PHP to insert stuff from the game to a database and retract it from the database..using PHP...
 
0
•••
k

Try this, instead of:
PHP:
mysql_query($query)or die('Error, insert query failed');

..

PHP:
mysql_query($query)or die(mysql_error());
 
0
•••
dunno if this is a problem or not, but whenever you do a query from phpmyadmin with a autoincrement field, which I assume you have for "id" then it always puts "NULL" in for the id field ie:
PHP:
$query= "INSERT INTO user (id,username,email,pass) VALUES (NULL,'$username','$email','$pass')";
(also, have removed random spaces from before both cases of the username.)

To make sure I have the right code I always run a query from phpmyadmin first and then copy the code. I think that if the phpmyadmin code works there is no reason why it won't work un my code.
 
0
•••
no need to put null in, he can just leave the id part out altogether:-

PHP:
$query= "INSERT INTO `user` (`username`,`email`,`pass`) VALUES ('$username','$email','$pass')";

I also put ` around the the field names and table name.
 
0
•••
mysql_connect(localhost, $dbusername, $dbpassword);

shouldnt the localhost be in speech marks?
 
0
•••
Hello,

If it is lower case which it is it is fine. If it was LOCALHOST or Localhost it is looking for a defined constant (define("PIE", $variable);)
print PIE; would print what ever the variable $variable is equal too.

- Steve
 
Last edited:
0
•••
MrBarby said:
mysql_connect(localhost, $dbusername, $dbpassword);

shouldnt the localhost be in speech marks?

well spotted I completely missed that.




iNod said:
Hello,

If it is lower case which it is it is fine. If it was LOCALHOST or Localhost it is looking for a defined constant (define("PIE", $variable);)
print PIE; would print what ever the variable $variable is equal too.

- Steve

I am sorry but that is just complete misinformation. A constant can be lower case as well and localhost in that command should have been in quotation marks.

It is true that most programmers use upper case when defining constants but it is not a requirement.

The following is taken from the php.net constants page:-

The name of a constant follows the same rules as any label in PHP. A valid constant name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thusly: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*

Example 13-1. Valid and invalid constant names
PHP:
<?php

// Valid constant names
define("FOO",    "something");
define("FOO2",    "something else");
define("FOO_BAR", "something more");

// Invalid constant names
define("2FOO",    "something");

// This is valid, but should be avoided:
// PHP may one day provide a magical constant
// that will break your script
define("__FOO__", "something");

?>
Note: For our purposes here, a letter is a-z, A-Z, and the ASCII characters from 127 through 255 (0x7f-0xff).
 
Last edited:
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back