Error on $_GET
Posted by: avo (---.l5.c2.dsl.pol.co.uk)
Date: June 01, 2006 11:12AM

HI all

Can anyone please help.


im running the latest wamp i have also get a server that i pay for my problam is :

ok this code works on my paid server but not on my local machine error at line echo ?> saying there was a ; pressent but as you can see there is not

CODE
<? if ($_GET['msg']=='0'){
echo ?>
<td colspan="2" align="center" valign="top" class="style9"><strong>No user selected to delete ! </strong></td>
</tr>
<tr>
<? } ?>


i then changed it to

CODE
<? if ($_GET['msg']=='0'){
echo ' ?>
<td colspan="2" align="center" valign="top" class="style9"><strong>No user selected to delete ! </strong></td>
</tr>
<tr>';
<? } ?>


worked on my paid server but not on my local machine saying parse error and pointing to <? } ?> and it should not be there but it should.


hope i have explaned well on my prob
if i remove this code all works well but i need it in there to do a check from another page it must be something to do with setup i guess

ive also done a phpinfo ()
and compared the two tables and the setup looks the same .

all help appriciated.

Options: ReplyQuote
Re: Error on $_GET
Posted by: CyberSpatium (67.170.181.---)
Date: June 01, 2006 12:31PM

you are using short ASP style tags in your code ( <? ), not full php tags ( <?php ). read my post here and it will tell you how to solve your problem.
http://forum.wampserver.com/read.php?f=2&i=6264&t=6264

I also see some php coding errors in your script. for example this line:
<? if ($_GET['msg']=='0'){

your script uses '0'. by putting quotes around that integer, php considers it to be a string type, not a numeric type. Now that is fine if you want the numbers to be stings in special circumstances. however, most of the time that is not what you want. and by quoting the integers and making them strings, it can cause some undesired effects and even some errors when developing your scripts.

for example, a test to see if that variable was an integer could cause problems. if you have a variable like this: $test = '4' and you use this line of code: is_integer($test). it would cause an undesired effect in your script because if you look at the $test variable. since you put quotes around it, it changed to a string type. a test to check if it is an integer would return false because even though the variable $test is a number, the quotes made it a string, not an integer so this code would return false. now, if we were testing the values they submitted using a form on our webpage to verify the values submitted where the correct type (their age for example). a test to see if their age is a valid integer would return false here because the is_integer() function would see the $test variable as a string. so, changing $test to this would keep use from running in to any problems:
$test = 4;

Also, a better way to code your script would be to use php's empty() function. It is more universal (especially in large applications) then just testing if $_GET['msg']==0 because we can test many different types of empty, null, and zero values (including boolean and array types). Here is a list of what empty() checks:
"" (an empty string)
0 (0 as an integer)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
var $var; (a variable declared, but without a value in a class)


also, remove the echo statement from your code, there is no reason to use for what you are attempting to use it for. I have edited your code a bit to make it more efficient, easier to test and develop, and use.

<?php if (emtpy($_GET['msg'])) { ?>
<td colspan="2" align="center" valign="top" class="style9"><strong>No user selected to delete ! </strong></td>
</tr>
<tr>
<?php } ?>


more info
[fr3.php.net]
[fr3.php.net]



Post Edited (06-03-06 10:25)

CyberSpatium
----------------------
WAMP Forum Admin

Web Development for Newbie's Blog - Check out my new blog. It is for web developers, and especially tailored for the web development newbie. If you are not fluent in “geek speak”, then this incredible resource is just you. And even if you are a web development pro, this is a great resource to check out some of the latest web development tips, news, tutorials, codes and more.

Options: ReplyQuote


Sorry, only registered users may post in this forum.