harlequeen Posted July 11, 2011 Share Posted July 11, 2011 Hi I have 3 variables in a form and I am sending 3 instances of the variable from the form at a time into the arrays. They are team name, team id and points. I am trying to print those out (just to see what I've got) but can only print 2. It seems like there is no value in the $Points array, but I can see that the value is being sent via the url. This is my test code <?php //database connection include'myconnect.php'; $team_id[]=$_GET['team_id']; $teamName[]=$_GET['teamName']; $Points[]=$_GET['Points']; foreach ($_GET['team_id'] as $row=>$name) { $team_id = $name; $teamName = $_GET['teamName'][$row]; $Points = $_GET['Points'][$row]; echo "$name "; echo"$teamName "; echo '$Points <br>'; } mysql_close(); ?> I don't understand why the $Points is not being printed out, although I admit that I'm learning this and it's like pulling teeth for me. The output I get is as below 5 Bristol Hotel $Points 22 Duke of Wellington $Points 40 Pontyates RFC $Points I have tried with " and ' and have left the ' in to show the variable name being printed. Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/241745-arrays/ Share on other sites More sharing options...
AbraCadaver Posted July 11, 2011 Share Posted July 11, 2011 Besides the variable name, what is the main difference between these two? echo "$teamName "; echo '$Points <br>'; http://us3.php.net/manual/en/language.types.string.php Quote Link to comment https://forums.phpfreaks.com/topic/241745-arrays/#findComment-1241592 Share on other sites More sharing options...
AyKay47 Posted July 11, 2011 Share Posted July 11, 2011 what does it print when you encase $print in double quotes instead of singles? Quote Link to comment https://forums.phpfreaks.com/topic/241745-arrays/#findComment-1241612 Share on other sites More sharing options...
teynon Posted July 12, 2011 Share Posted July 12, 2011 In case you still haven't figured it out, given all the hints and documentation posted before me. If you have a string with a variable in it, you need to either use double quotes or escape the string. example: echo "test $value"; or echo 'test '. $value; Quote Link to comment https://forums.phpfreaks.com/topic/241745-arrays/#findComment-1241618 Share on other sites More sharing options...
harlequeen Posted July 13, 2011 Author Share Posted July 13, 2011 Hi Yes, I did put it in " " but that just didn't echo anything at all. As I said in my post when I tried " " nothing echoed and when I use ' ' just $Points is printed. If I don't put anything but echo $Points in nothing is printed. It should output a number which I've entered using this form. Is there something amiss with the form, perhaps. <table width="30%" align="center" border="1"> <form name="inputpoints" method="GET" action="checkresults3.php"> <tr> <td width=40%> <input type="char" name='team_id[]'size="2" value=" <? echo $row['team_id'];?>"></td><td> <input type="text" name='teamName[]' size="36" value=" <? echo $row['teamName']; ?>"></td> <td> <SELECT name='points[]'> <OPTION value=1>1</OPTION> <OPTION value=2>2</OPTION> <OPTION value=3>3</OPTION> <OPTION value=4>4</OPTION> <OPTION value=0>0</OPTION><?php echo $row['Points'];?>"> </select> </td> As far as I can see from the url the values are being passed as shown. [color=purple]checkresults3.php?team_id[]=+5&teamName[]=+Bristol+Hotel&points[]=4&team_id[]=+22&teamName[]=+Duke+of+Wellington&points[]=3&team_id[]=+40&teamName[]=+Pontyates+RFC&points[]=1[/color] I will want to do further things with the information, but need to know that the values are there. I appreciate your help, but I did try both methods and couldn't get anything out. Harlequeen Quote Link to comment https://forums.phpfreaks.com/topic/241745-arrays/#findComment-1242390 Share on other sites More sharing options...
teynon Posted July 13, 2011 Share Posted July 13, 2011 Uh... <OPTION value=0>0</OPTION><?php echo $row['Points'];?>"> ????? How about <option value=<?php echo $row['Points'];?>><?php echo $row['Points'];?></option> Quote Link to comment https://forums.phpfreaks.com/topic/241745-arrays/#findComment-1242473 Share on other sites More sharing options...
harlequeen Posted July 13, 2011 Author Share Posted July 13, 2011 That doesn't make any difference at all, the same thing is being passed through the url. Cheers Harlequeen Quote Link to comment https://forums.phpfreaks.com/topic/241745-arrays/#findComment-1242484 Share on other sites More sharing options...
teynon Posted July 13, 2011 Share Posted July 13, 2011 First off, the variable points that you are sending through the GET method is all lowercase (points) not (Points). Second of all, you should use post for that. Quote Link to comment https://forums.phpfreaks.com/topic/241745-arrays/#findComment-1242486 Share on other sites More sharing options...
harlequeen Posted July 15, 2011 Author Share Posted July 15, 2011 Thanks for all your help everyone. The penny finally dropped when I was telling a colleague that PHP was finicky about cases and I suddenly realised what the problem was. Thanks again. Harlequeen Quote Link to comment https://forums.phpfreaks.com/topic/241745-arrays/#findComment-1243081 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.