Forum Moderators: coopster

Message Too Old, No Replies

query help

         

superxtian

2:04 pm on Sep 5, 2008 (gmt 0)

10+ Year Member



im having problem with my code

function add_user($username, $cryptedpass, $type, $firstname, $surname, $gender, $email)
{
// see if there is already a user with the username of '$username'
$query = "SELECT 1 FROM `users` WHERE `username`='$username'";
$query = @query($query) or die("Error checking the database.");
if(num_rows($query) > 0){ cust_die("The requested username is already in the database. Please select another one."); }

$add_query = "INSERT INTO `users` (`username`, `password`, `type`, `firstname`, `surname`, `gender`, `email`) VALUES ('$username', '$cryptedpass', '$type', '$firstname', '$surname', '$gender', '$email')";
query($add_query) or die("Error adding the user's information into the database.");

}

cause everytime i press register it always says "Error adding the user's information into the database" is there anything wrong with my query?

jatar_k

2:26 pm on Sep 5, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you'll need better data try changing this line

query($add_query) or die("Error adding the user's information into the database.");

to

query($add_query) or die("Error adding the user's information into the database: " . mysql_error());

that will give you the error, if there was one, from mysql

the other thing would be to echo your query as well to see if it looks correct

superxtian

12:30 pm on Sep 6, 2008 (gmt 0)

10+ Year Member



i try your suggestion and i still get error

"Error adding the user's information into the database.Duplicate entry '0' for key 1"

i check my database and i forgot to put auto_increment in the table 'user' maybe there is a connection with the problem..

anyway thanks for the help

jatar_k

1:26 pm on Sep 6, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that would be the problem

what field is your key?

superxtian

10:45 am on Sep 8, 2008 (gmt 0)

10+ Year Member



is it possible to edit my table and insert auto_increment?

jatar_k

6:17 pm on Sep 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



absolutely

look at ALTER TABLE [dev.mysql.com]

superxtian

9:42 am on Sep 10, 2008 (gmt 0)

10+ Year Member



this is table for user

CREATE TABLE `users` (`ID` int(11) NOT NULL, `username` text NOT NULL, `password` varchar(32) NOT NULL default '', `type` int(11) NOT NULL default '0', `firstname` text NOT NULL, `surname` text NOT NULL, `gender` char(1) NOT NULL default '', `email` text NOT NULL, PRIMARY KEY (`ID`));

how can i alter this one?

jatar_k

3:08 pm on Sep 10, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well you could read through the page and then search for some examples

you could try a modify

alter table users modify id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY

just making that up, it might work but you get the idea

superxtian

2:39 pm on Sep 11, 2008 (gmt 0)

10+ Year Member



your the MAN jatar_k, finally it works perfectly

thank you for your patience in helping me! :D

i luv ya dude! lol