Page 1 of 1

sql code in my php script giving error

Posted: Fri Jul 10, 2009 7:56 am
by mayanktalwar1988
$sql = mysql_query("INSERT INTO mymembers (firstname, lastname,username, country, state, city, zip, email, password, sign_up_date)
VALUES('$firstname','$lastname','$username','$country','$state','$city','$zip','$email1','$db_password', now())")
mysql_query("INSERT INTO phpbb_users (username,user password) VALUES('$email1','$db_password')")
or die (mysql_error());
i am trying to send same information inti two tables former statement is working when it is alone dere but when i add second one i get
Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\edu\register.php on line 128


and line 128 is the later sql statement in the script.....where am i wrong above?

Re: sql code in my php script giving error

Posted: Fri Jul 10, 2009 8:04 am
by Eric!
It really helps if you use the code=php tags.

Code: Select all

$sql = mysql_query("INSERT INTO mymembers (firstname, lastname,username, country, state, city, zip, email, password, sign_up_date)
VALUES('$firstname','$lastname','$username','$country','$state','$city','$zip','$email1','$db_password', now())")
mysql_query("INSERT INTO phpbb_users (username,user password) VALUES('$email1','$db_password')")
or die (mysql_error());
Notice anything missing? Hint = ;

Re: sql code in my php script giving error

Posted: Fri Jul 10, 2009 8:17 am
by mayanktalwar1988
ya i put d ; after second sql statement its working but when there is single sql statement followed by die() it is working without ;why? why

Re: sql code in my php script giving error

Posted: Fri Jul 10, 2009 9:14 am
by Skara

Code: Select all

mysql_query("INSERT ..."); //one statement
mysql_query("INSERT ...") or die(); //one statement
die(); //one statement
The or operator is like an addon to the current statement. It's the equivalent of saying

Code: Select all

if (!mysql_query("INSERT ...") {
    die();
}

Re: sql code in my php script giving error

Posted: Fri Jul 10, 2009 11:17 am
by mayanktalwar1988
ok i got it

Re: sql code in my php script giving error

Posted: Sun Jul 12, 2009 3:18 am
by mayanktalwar1988
and i m getting one problem with aboovee sql...the second line i used is to send user information from site registration form to phpbb user table.so that both have same username and password...but this statement is only able to add one record...it does nt add more than one record in phpb table...if dere is already one record in the phpbbb_user table then d new record is not added by the sql statment.n i don kno wat to do.....help..

Re: sql code in my php script giving error

Posted: Sun Jul 12, 2009 12:00 pm
by Eric!
I'm having a hard time understanding your slang and that long confusing run-on sentence.

Can you ask your question more clearly? Please use real words for us old people....

Perhaps you are trying to update an existing record? Use UPDATE instead of insert. Why would you want multiple records with the same user/password?

Re: sql code in my php script giving error

Posted: Sun Jul 12, 2009 1:53 pm
by Skara
Yeah, all I got was trouble with the second query.

Code: Select all

INSERT INTO phpbb_users (username,user password) VALUES('$email1','$db_password');
I see one problem is that you have a space rather than an underscore. "user password" should be "user_password"

Code: Select all

INSERT INTO `phpbb_users` (`username`,`user_password`) VALUES('$email1','$db_password');
In any case, I've recently been heavily modding phpbb3 and I can tell you that only inserting those two values will give you problems in the future, unless you're soon after adding more data to the row. Your version may be older, but from what I'm looking at, you at least need to add `user_form_salt` and preferably `user_regdate`

Re: sql code in my php script giving error

Posted: Mon Jul 13, 2009 12:14 am
by mayanktalwar1988
ok eric i m trying again ..eric i m trying to make site log in and phpbb log in one...and to achieve it i have this in mind...
1.when a new person register to the site..the data of him is tranferred in site eisting usetable...and now i want to add phpbb..so phpbb has it own table..so thats why i inserted the sql statement which would insert same user data in the phpbb user table also....
2now afte both the table has same user data...the same person doesnt has sign up fpr phpbb anymore...
3.if this achieved..i will make one more login form for phpbb which will use my site log in form data to log in phpbbso that aperson who log in site get automatically logged in phpbb....after that i m blank.....
4after achieving this i will somehow tackle logout ......but..the second sql statement is not inserting data in the phpbb usertable...it is able to insert one record...but after that it doesnt work for phpbb...although the..first sql insert command for existing usertable..i.e mymembers..is working fine....


..if still there are loopholes in bove slang i will try again...

1. $sql = mysql_query("INSERT INTO mymembers (firstname, lastname,username, country, state, city, zip, email, password, sign_up_date)
2. VALUES('$firstname','$lastname','$username','$country','$state','$city','$zip','$email1','$db_password', now())");
3. mysql_query("INSERT INTO phpbb_users (username,user password) VALUES('$email1','$db_password')")
4. or die (mysql_error());

Re: sql code in my php script giving error

Posted: Mon Jul 13, 2009 12:26 am
by Eric!
The extra table seems unnecessary, however it should work. I see your code still has the same errors pointed out by Skara. Try fixing your query statements and try again. Make sure your fields match your database names.

Code: Select all

INSERT INTO `phpbb_users` (`username`,`user_password`) VALUES('$email1','$db_password');

Re: sql code in my php script giving error

Posted: Mon Jul 13, 2009 12:29 am
by Eric!
The extra table seems unnecessary, however it should work. I see your code still has the same errors pointed out by Skara. Try fixing your query statements and try again. Make sure your fields match your database names.

Code: Select all

INSERT INTO `phpbb_users` (`username`,`user_password`) VALUES('$email1','$db_password');
Also your first line is missing the ; at the end again.

Re: sql code in my php script giving error

Posted: Mon Jul 13, 2009 12:37 am
by mayanktalwar1988
sirr i also tried with underscore and ;..but it is not able to add more than one record.......is my method of making one log in..feasible?this the only thing came in mymind..beyond that i don how to make one log in for both

Re: sql code in my php script giving error

Posted: Mon Jul 13, 2009 1:02 am
by mayanktalwar1988
this is for skara........i have done all that u said previously but it didnt help yes i m using phpbb2...now tell

Re: sql code in my php script giving error

Posted: Mon Jul 13, 2009 3:18 am
by mayanktalwar1988
not wopking even adding more than two fields as skara said it is not adding more than one record