Forum Moderators: coopster

Message Too Old, No Replies

INSERT INTO help needed

After 6 hours of trying, cant get it to work

         

IamStang

3:34 am on Oct 31, 2005 (gmt 0)

10+ Year Member



Goes without saying that I am a nooB with mysql. I have spent the majority of 6 hours trying to get this thing to work with no luck. I've googled for examples and tried atleast 10 different "tutorials" to no avail. Thus, I am here asking for help from you folks.

I have my database setup like this:


mysql> show fields from user_data;

Field ¦ Type ¦ Null ¦ Key ¦ Default ¦ Extra

user_id ¦ int(11) ¦ ¦ PRI ¦ NULL ¦ auto_increment
user_name ¦ varchar(36) ¦ ¦ ¦ ¦
user_login ¦ varchar(36) ¦ ¦ ¦ ¦
user_password ¦ varchar(36) ¦ ¦ ¦ ¦
user_telnum1 ¦ varchar(25) ¦ YES ¦ ¦ NULL ¦
user_telext1 ¦ varchar(4) ¦ YES ¦ ¦ NULL ¦
user_telnum2 ¦ varchar(25) ¦ YES ¦ ¦ NULL ¦
user_telext2 ¦ varchar(4) ¦ YES ¦ ¦ NULL ¦
user_cellnum ¦ varchar(25) ¦ YES ¦ ¦ NULL ¦
user_faxnum ¦ varchar(25) ¦ YES ¦ ¦ NULL ¦
user_email ¦ varchar(50) ¦ YES ¦ ¦ NULL ¦
user_is_here ¦ int(1) ¦ ¦ ¦ 0 ¦
user_use_signature ¦ int(1) ¦ ¦ ¦ 0 ¦
user_signature ¦ varchar(250) ¦ YES ¦ ¦ NULL ¦
user_is_mod ¦ int(1) ¦ ¦ ¦ 0 ¦

Now, my code to insert from my php script is:


// ********** build query **********
$query = "INSERT INTO user_data ";
$query .= "(user_id, user_name, user_login, user_password, user_telnum1, user_telext1, ";
$query .= "user_telnum2, user_telext2, user_cellnum, user_faxnum, user_email, user_is_here, ";
$query .= "user_use_signature, user_signature, user_is_mod) ";
$query .= " values('','$name','$login','$add_pass','$telnum1','$telext1','$telnum2',";
$query .= "'$telext2','$cellnum','$faxnum','$email','0','$usesig','$signature','0')";
mysql_pconnect("localhost","login","password")
or die("Unable to connect to SQL server");
mysql_select_db("use4test") or die("Unable to select database");

// ********** remove after working correctly **********
echo "$name - $login - $add_pass<br>";
// ********** END remove after working correctly **********

mysql_query($query) or die("Insert Failed!");


NOTE: most will have already figured this out, but the "values" are recieved from a form.

I am connecting to the database without problems. Or atleast I seem to be as I am getting the error "Insert Failed!"

What, is wrong with this? I hate asking in this manner as I usually prefer finding the solution on my own, but I have already pulled enough hair out over this one. I wont be able to reply till after work sometime tomorrow. But I will then. In the meantime, thank you for taking the time to read/think on this. It is appreciated!

PS1:
Also, wouldn't mind hearing of some good mysql related info/tutorial websites you folks have ran across.

PS2:
I just realized that this might have been better posted in the PHP forum. If it should have been, my appologies. Feel free to move it mods.

grandpa

4:15 am on Oct 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can find out more about the insert error by returning the error message and/or number.

mysql_query($query) or die("Insert Failed!" . mysql_error() . "<br>" . mysql_errno());

Most of the time mysql_error() will tell you everything you need to know. Sorry, I didn't spot the problem.

IamStang

11:35 am on Oct 31, 2005 (gmt 0)

10+ Year Member



Thank you!

Woke up early this morning and that did the trick!
Thanks again!