Having a problem with a large while loop. . .

04-30-05, 10:37 PM
|
|
Newbie Coder
|
|
Join Date: Jan 2004
Location: In front of my computer
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Having a problem with a large while loop. . .
I am having a problem with a large while loop I am using in my PHP page. I get the error unexpected $ on line 476 (Last line of the page) I've narrowed the problem down to my while loop, but am not sure what in teh while loop is causing the problem.
|

05-01-05, 04:36 AM
|
 |
Community VIP
|
|
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
|
|
This loop is correct in syntax and all braces are matched.
since you said the error you had pointed the last line, it means that there is a missing brace(s)
however, I noticed this:
'$we_num' will not evaluate $we because it's inside single quotes. use double quotes to evaluate it.
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
|

05-01-05, 04:44 AM
|
 |
Aspiring Coder
|
|
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Correct syntax:
You do:
Edit: Also you do not need double quotes...
Last edited by Acecool; 05-01-05 at 04:48 AM.
|

05-01-05, 01:15 PM
|
|
Newbie Coder
|
|
Join Date: Jan 2004
Location: In front of my computer
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank You both, that solved the error, however it is not inserting the stuff into the database. Here is the updated code.
|

05-01-05, 01:51 PM
|
|
Wannabe Coder
|
|
Join Date: Mar 2005
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
mysql_query("INSERT INTO ships ($tech, $type, $dmg) VALUES('$tech3', '$type3', '$dmg3') WHERE ship_name = '$ship' AND owner = '$user'") or die (mysql_error());
are $tech,$type, $dmg valid names in your db?
and also is this written so the query will write over an already existant row?
|

05-01-05, 03:03 PM
|
|
Newbie Coder
|
|
Join Date: Jan 2004
Location: In front of my computer
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
There is no row to overwrite, but. . .
$tech = weap_tech1
weap_tech1, or whatever the number is, is a valid name in the database. Is it a problem with me using a variable for the name the values should be inserted into? I have bolded it below. . .
mysql_query("INSERT INTO ships ($tech, $type, $dmg) VALUES('$tech3', '$type3', '$dmg3') WHERE ship_name = '$ship' AND owner = '$user'") or die (mysql_error());
|

05-01-05, 04:09 PM
|
|
Wannabe Coder
|
|
Join Date: Mar 2005
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
|
Originally Posted by Spreegem
There is no row to overwrite, but. . .
$tech = weap_tech1
weap_tech1, or whatever the number is, is a valid name in the database. Is it a problem with me using a variable for the name the values should be inserted into? I have bolded it below. . .
mysql_query("INSERT INTO ships ($tech, $type, $dmg) VALUES('$tech3', '$type3', '$dmg3') WHERE ship_name = '$ship' AND owner = '$user'") or die (mysql_error());
|
I don't think it would be a problem, except I would think you would need some single quotes around them....also one think that I have to ask is why do you have conditional statements in an insert?
what does fields does your ships table have?
|

05-01-05, 04:17 PM
|
 |
Aspiring Coder
|
|
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Single quotes in double quotes work fine..
Why do you need a WHERE ship_name='...'?
If you want to UPDATE a row, then use the UPDATE row syntax..
INSERT INTO will create a new row, and you do not need a WHERE...
|

05-01-05, 05:05 PM
|
|
Wannabe Coder
|
|
Join Date: Mar 2005
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well I am glad someone agrees with me..... 
|

05-01-05, 05:57 PM
|
|
Newbie Coder
|
|
Join Date: Jan 2004
Location: In front of my computer
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Opps. . . Yeah, I meant update, can't believe I didn't notice that.
Still not working for some reason. . . I just tried echoing $weapon, $tech, $tech3, and the others, but nothing gets echoed, none of them have values it appears.
Here's the updated code for the loop
Last edited by Spreegem; 05-01-05 at 06:16 PM.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|