Languages :: PHP :: looping problems !!! Please Help !! |
|||
| By: PHP newbee |
Date: 18/02/2003 00:00:00 |
Points: 100 | Status: Answered Quality : Excellent |
|
The code is working upto the "elseif" statement, but it is unable to get passed the "elseif" statement, has anybody got any idea, why?? please !! <?php //set background color, font color and page title print"<html>\n<head>\n<title>Add Customer Allocation</title>\n</head>\n"; print"<LINK REL=stylesheet TYPE=\"text/css\" HREF=\"style3.css\">\n"; //connecting to database $db_host = "localhost"; $db_user = "telaa"; $db_pass = "aaa"; $db_name = "telaa"; $link = mysql_connect($db_host, $db_user, $db_pass) or die("Could not connect to MySql host"); mysql_select_db($db_name) or die("Could not select database: $db_name"); //select prefix, then prints all avaiable numbers under that prefix $func="getsource"; if ($func =="getsource"){ if (!isset($sou)){ print"<div align='center'>\n <h1>TELCO</h1>\n"; print"Add <b>Customer </b>Details to Number \n"; print"<form name=\"frm\" method=\"post\" >"; print"Select prefix: "; print" <select name='sou'> <option> <option>0800 <option>0845 <option>0870 </select>\n"; print" \n<input type=\"submit\" value=\"Get Numbers\" >\n"; print"</form>\n"; print"<a href=\"telco.php\">Return To Main Menu</a>\n"; print"</div>\n"; }else{ //select prefix query. looks at the ranges table for the prefix that has //been selected. Also looks at the allocated field for numbers //under that prefix that have the number 0 next to them to say //that the number has not been allocated to a customer yet. $query ="SELECT * from ranges WHERE prefix='$sou' AND allocated='0' "; $result = mysql_query($query); print"<div align='center'>\n"; print"<h1>TELCO</h1>\n"; print"<b>Select Number Below: $sou</b>\n "; print"<select name='$sou2'>\n"; //results have been collected using the fetch array command and will //appear in a drop down box. while ($row = mysql_fetch_array($result)){ $data1 =$row["number"]; print"<option>$data1\n"; $func ="updatedb"; } print"</select>"; $func ="updatedb"; print" $func"; //Once the first query has been executed. The drop down box will appear, //and two other text fields where the destination number and //customer name, need to be added. } }elseif($func =="updatedb"){ if(!isset($sou2)){ print"<form name=\"frm2\" method=\"post\" >\n"; print"<b>Enter Destination Number & Customer Name</b>\n"; print" dest:<input type=\"text\" name=\"dest1\"> \n"; print"cust:<input type=\"text\" name=\"cust1\"> \n"; print" <input type=\"submit\" value=\"Add\" >\n"; print"</form>\n"; print"<a href=\"java script:history.back(1);\">Return to Previous Page</a></div>"; }else{ //Below two queries take place, the first one is to update the //ranges table so that where the source and number //match, the allocated field is set to 1. The second query inserts //into the allocated table the source, destination number, //prefix and the customer. $query ="UPDATE ranges SET allocated='1' WHERE prefix=$sou AND number=$sou2"; mysql_query($query); $query ="INSERT into allocated SET source='$sou$sou2', dest='$dest1', cust='$cust1', prefix='$sou'"; mysql_query($query); //prints that the details have been added once the two above queries have //been executed. print" <div align='center'>"; print"Details Added, Click <a href=\"java script:history.back(1);\">Here</a>"; print" Click <a href=\"telco.php\">Here</a> For Main Menu</div>"; } else{ echo"error"; } return; print"</html>"; ?> |
|||
| By: VGR | Date: 18/02/2003 06:44:00 | Type : Answer |
|
| easy in the last 6 lines : else{ echo"error"; you lack a closing } before the else basically, the control scheme of your script is this : <?php $func="getsource"; if ($func =="getsource"){ if (!isset($sou)){ } else { } } elseif ($func =="updatedb") { if(!isset($sou2)){ } else { } else{ echo"error"; } ?> As you can see, there is clearly a problem... PS : good and friendly advice : COMMENT YOUR OPENING AND CLOSING OF BLOCKS !! like this : (putting . for indenting spaces, as EE refuses the insertion of ... <?php $func="getsource"; if ($func =="getsource"){ ..if (!isset($sou)){ ..} else { // $ou is set ..} // if isset $ou } elseif ($func =="updatedb") { ..if(!isset($sou2)){ ..} else { // $ou2 is set ..} // if isset $ou2 } else{ // func not updatedb nor getsource ..echo"error"; } // if func ?> |
|||
| By: TheFalklands | Date: 18/02/2003 06:44:00 | Type : Comment |
|
| what error are you getting? have you tried single quotes? |
|||
| By: VGR | Date: 18/02/2003 19:46:00 | Type : Comment |
|
| no TFL, copy-paste the script and you'll see the error. It has nothing to do with quotes |
|||
| By: sumotimor | Date: 19/02/2003 22:50:00 | Type : Comment |
|
| hi PHPnewbee You said that it is not going to the elseif condition at all. Bcoz since every time you are redirecting it to the same page you have initially given $func="getsource" Even if you have initialized it to "updatedb" in the else part it again comes to the same page and again gets initialized to "getsource".thats why its not going to else if part. |
|||
| By: RQuadling | Date: 19/02/2003 22:56:00 | Type : Comment |
|
| Yep. Line 26 of your code. Makes all the further testing redundant. |
|||
| By: RQuadling | Date: 19/02/2003 22:58:00 | Type : Comment |
|
| What you MAY want is ... if (!isset($func)) { $func = "getsource"; } I assume func is coming into the script via GET/POST? Ideally, then you should use ... if (!isset($_POST[]) || !isset($_POST["func"])) { $_POST["func"] = "getsource"; } and then use $_POST["func"] from that point onwards. |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








