View Full Version : PHP problem
Dean B
05-13-1999, 05:41 PM
I have created a PHP that starts with an 'if' then three 'elseif' statements finishing with the 'else' block.[nbsp][nbsp]This all works fine but I'm now trying to add two mysql_query statements.[nbsp][nbsp]I can get them to work fine in a PHP on their own but I'm having trouble combining the two (I want to add the mysql_querys on the end) I've tried using else: with if: and other combos but no luck.
Suggestions ?
Dean.
pdstein
05-17-1999, 11:00 AM
Hey Dean,
What exactly _is_ happening?[nbsp][nbsp]Are you getting an error (if so what is it) or is it never getting to one or both of the queries?
It also might be easier to help if you posted the relevant part of your code.
- Paul
[nbsp][nbsp]
Dean B
05-17-1999, 05:39 PM
Paul,
Placing the two mysql_query's after the last elseif block causes a parse error.[nbsp][nbsp]I'm unsure exactly how to add the queries which is undoubtedly why I'm having problems.[nbsp][nbsp]This is what I've got -
if (blah blah) {
do this
}
elseif (blah blah) {
do this
}
elseif (blah blah) {
do this
}
elseif (blah blah) {
do this
}
now I want to add the two mysql_querys so I tried ..
ELSE :
$query = "SELECT * FROM $usertable WHERE NickName = ('$NickName')";
$result = MYSQL_QUERY($query);
$num = MYSQL_NUMROWS($result);
IF ($num >0):
print "sorry this nickname is already in use";
ELSE :
$query = "SELECT * FROM $usertable WHERE password = ('$password')";
$result = MYSQL_QUERY($query);
$num = MYSQL_NUMROWS($result);
IF ($num >0):
print "sorry this password is already being used";
Does this make it clear what I'm trying to do ?
:)
Dean.
[This message has been edited by Dean B (edited 05-17-99)]
Justin
05-17-1999, 06:20 PM
Not sure if this makes any difference, but try:
$query = "select * from $usertable where (NickName = '$NickName')";
- or -
$query = "select * from $usertable where NickName = '$NickName'";
Not sure why you have just the parameter in parenthesis... but they aren't needed unless you have multiple parameters:
$query = "select * from $usertable where (NickName = '$NickName') and (password = '$password')";
Or something like that - the best way to figure out where a query is having a problem is to do it on the command line until it gives the desired results - either in telnet or dos. Then once it's right, just copy the query into your php code (removing the <font color=#FF0000>;</font> first of course).
Let me know if this helps.
------------------
Justin Nelson
FutureQuest Support
pdstein
05-18-1999, 11:59 AM
Dean,
A couple of thoughts...
I know you can use the IF: ELSEIF: ELSE: ENDIF; convention and the IF{} ELSEIF{} ELSE{} convention, but I don't know if you can use them together.
Do you have all the needed ENDIF's after your queries?
Since you're getting a parse error rather than an mySQL error, it's probably not your queries.[nbsp][nbsp]To confirm this, you could comment out the mySQL stuff and insert $num=0 in place of $num = MYSQL_NUMROWS($result)
Hope this helps.
- Paul
Dean B
05-18-1999, 02:18 PM
Nope... still got me stumped.[nbsp][nbsp]Rather than post the entire file in it's entirety here I've uploaded it as txt file to my site.[nbsp][nbsp]If anyone would care to take a look and tell me what stupid doo-doo I'm making I'd appreciate it.
Muchly thx.
Dean.
http://www.dmcity.com/2CREPORT.txt
pdstein
05-18-1999, 02:42 PM
Dean,
It looks like you're missing the } after the
elseif ($Password =="") {
[nbsp][nbsp] // bunch of stuff here
code.[nbsp][nbsp]I think you also have a problem further down where you have /*check to see if losers nickname is in the database*/.[nbsp][nbsp]This code is between elseif blocks.[nbsp][nbsp]You can't do that.
- Paul (no, I don't have anything better to do)
Dean B
05-18-1999, 04:14 PM
The missing } was just a typo when I cut and pasted.[nbsp][nbsp]Yes Paul, the code between the elseifs is the problem but that's the part I can't figure out ;)
Dean.
pdstein
05-18-1999, 04:54 PM
Dean,
You can't place any code between the the closing bracket of one elseif and the next elseif.[nbsp][nbsp]If you do, the parser sees the code and thinks the if statment is complete.[nbsp][nbsp]Then it gets to the next elseif statement and freaks out because it thinks that there is no if statement preceding it.
Rather than
if {
[nbsp][nbsp]// misc code block 1
}
elseif {
[nbsp][nbsp]// misc code block 2
}
// misc code block 3
elseif {
[nbsp][nbsp]// misc code block 4
}
You need to to have
if {
[nbsp][nbsp]// misc code block 1
}
elseif {
[nbsp][nbsp]// misc code block 2
}
else {
[nbsp][nbsp]// misc code block 3
[nbsp][nbsp]if {
[nbsp][nbsp][nbsp][nbsp]// misc code block 4
[nbsp][nbsp]}
}
- Paul
Dean B
05-19-1999, 10:12 AM
Paul,
I understand that ok but before I add the if, elseif blocks I need to run the mysql query so I have something in the expression after the if to compare it to, don't I ? Phew :)
You can't just add the if on it's own, can you ?
This is what I'm trying to say -
if (result of mysql query = whatever) {
print this out
}
Boy, do I need some help with these ladder php's or what ;)
Dean.
--- off to play with his bourne again shell ---
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.