-
That syntax is correct. Something must be wrong with the variable names (or how it was sent originally). At some point in there, "agency" (in one of its forms) was blank.
Turn on error reporting to the highest level and you will get warnings when you are calling a variable with no value or an array with a key that does not exist. It will tell you the line number so you can track it that way and find out where it is being lost.
http://www.php.net/manual/en/functio...-reporting.php
At the beginning of your script, add:
// Report all PHP errors
error_reporting(-1);
You can also change the setting in php.ini, but this way it will just be there for debugging. Find the errors, fix them, and once the page is ready to go, remove that line again and the users won't see any extra errors (or back to the original setting, at least), so that you can debug but they don't get worrying, confusing notices.
Though it is always a good idea to fix all errors and notices, some of them do not actually "hurt" anything, but instead just make it confusing because php can guess and work around them. Basically if you use a variable that doesn't exist it will use an empty string instead (why you're getting ''). If you have this kind of problem and then don't show the notices (low level error reporting), then the users won't know the difference and the script will run fine (most likely), but it will be more difficult to debug.
So, if you turn that on and find many things wrong with the script, then just fix the ones that are actually causing you problems. Then you can remove that code again and it'll go back to how it was. If you have the extra time, fix the extra problems too, but it's not crucial. (More important later if you are expanding the script, or someone else is working on it.)
-
Hi traq: I did do the whole thing your way, ie. setting all the $_POST variables to plain variables first, but was desperately trying anything to get it to work.
$Agency is correct, but good eye that you caught that change. Through this process I discovered that I had been using one variable for two different values and had to introduce $Agency to represent the short name. But you did draw my attention to the possibility that the variable name was wrong and, sure enough, the script that creates the drop-down boxes was still using the old name, so I changed it to $Agency and now everything works like a charm. I'm about to make it live, which is the real test... I'll let you know what happens. :)
-
Hi Nile: I removed that code when things weren't working, but as soon as I have everything live and functioning, I'll reintroduce it and try your addition... thanks! :)
-
Hi Daniel: Great advice, which I will try in a bit. The owner's waiting for me to make it live right now so I have a feeling I'm going to need it very soon haha. :)
-
Miracle of all miracles, I made it all live without a hitch! Thank you guys for all your help... I could never have done this without you. Daniel, I even understand 99% of the code thanks to your great explanations and homework you give me! I still have some modules in the Admin Panel to do, but the main functions are done... yea!!
After all the modules are done, then I need to try turning Register_Globals off and see how I really did haha. I'm sure it will crash and burn, but it feels good to get this far. Thanks a million for being there. I wish I could give you a big hug. :)
-
I sure hope you guys are there because I am in a major emergency on the live site. Nothing is working because I am getting this error message but cannot find the error...
Code:
Parse error: syntax error, unexpected '=' in /home1/mauiretr/public_html/_car/php/add-agency-logos.php on line 5
There is no equal sign that seems to be incorrect. Here is the code...
Code:
if($selection == "best"){
sql = "SELECT agency_id, agency, agencyname, logo FROM `agency` WHERE `agency` = $Best_Rental ";
$result = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error());
$row = mysql_fetch_array($result);
} elseif($selection == "all"){
sql = "SELECT * FROM `agency` WHERE `agency_id` = $_POST['agency_id'] ";
$result = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error());
$row = mysql_fetch_array($result);
} elseif($source == "cp" || $source == "cancel"){
sql = "SELECT agency_id, agency, agencyname, logo FROM `agency` WHERE `agency` = '$Agency' ";
$result = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error());
$row = mysql_fetch_array($result);
}
$Best_Rental = $row['agency'];
$agencyname = $row['agencyname'];
$Car_Logo = $row['logo'];
Please help before the owner freaks out!!! Thanks. e :)
-
$sql =
mistyped twice in your code
-
Dear bluewalrus:
OMG! Duh! 3 times actually (from copy and paste). Thank you so much!!! I have been up all night and cannot even see straight.
Talk about misdirected attention. :) e
-
Parse errors are special: this means that upon the initial scan of your code, the php engine did not know what to do with it. There isn't something "going wrong" as the code is run, but it's actually unintelligible from the beginning. This usually makes it easy to find because it's almost always a typo or misplaced bracket, etc. The only problem is that frequently parse errors don't tell you exactly where to look because it only knows there's a problem when it gets to something it doesn't understand. For example, if you are missing a bracket and it reaches the end it will give an error (unexpected $end) for the last line, regardless of where the actual typo is. Still, though, this makes debugging clearer. Hope that helps next time.
-
Hi Daniel:
I am really starting to "get" this stuff thanks to your great explanations. Now that the panic's over I can put the code back to the way I like it with the least amount of redundant code. One thing I'm not sure about is when you have to separate the variables from the SQL. Which is the best practices way of saying agency = $Best_Rental;
Like this? "... WHERE agency = '$Best_Rental' ";
OR this? "... WHERE agency = ' ".$Best_Rental." ' ";
OR this? "... WHERE agency = $Best_Rental ";
Also is "||" exactly equivalemt to "OR" and does it matter if you use one or the other? Any advantages either way? Thanks, e :)