scm22ri Posted July 1, 2012 Share Posted July 1, 2012 Hey Everyone, I'm trying to pass a variable via the GET method but I seem to be doing something wrong although I'm not sure what? When you hover a number under "ID" and click, it goes to the next page but does not pass any information. Below is my source code. Would anyone know what I might be doing wrong? Thanks Everyone! http://whatsmyowncarworth.com/practiceTemplate/practice1/33/loans/table3.php <?php include('init.php'); /*$sql = "SELECT * FROM cars WHERE id='1' ORDER BY year ASC";*/ $sql = "SELECT * FROM dealers"; if ($result = mysql_query($sql)) { echo "<table border='1'>"; echo "<tr> <th>ID</th> <th>Name</th> <th>Address</th> <th>State</th> <th>City</th> <th>Website</th> "; // keeps getting the next row until there are no more to get while ($row = mysql_fetch_array($result)){ $id = $row['id']; $name = $row['name']; $address = $row['address']; $state = $row['state']; $city = $row['city']; $website = $row['website']; $maps = $row['maps']; $lat = $row['lat']; $lng = $row['lng']; // Use this as a loose guide /*<form action="/reviews.php" method="get"> <b>Enter Your First Name:</b> <input type="text" name="zip" maxlength="85" value="" /> <p> <input type="submit" value="Get Approved" name="submit" /> </form>*/ echo("\t<tr>\n"); /*echo("\t\t<td>" . "$id" . "</td>\n");*/ echo("\t\t<td><a href='reviews2.php?id=" . $_GET['id'] . "'>" . $id . "</a>"); echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$name" . "</a></td>\n"); echo("\t\t<td>" . "$address" . "</td>\n"); echo("\t\t<td>" . "$state" . "</td>\n"); echo("\t\t<td>" . "$city" . "</td>\n"); echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$name" . "</a></td>\n"); /*echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$name" . "</a></td>\n"); echo("\t\t<td>" . "<a href='http://$maps' target = '_blank'>" . "$address" . "</td>\n"); echo("\t\t<td>" . "<a href='http://$maps' target = '_blank'>" . "$address" . "</td>\n"); echo("\t\t<td>" . "$state" . "</td>\n"); echo("\t\t<td>" . "$city" . "</td>\n"); echo ("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$website" . "</a></td>\n"); echo("\t\t<td>" . "$maps" . "</td>\n"); echo("\t\t<td>" . "$lat" . "</td>\n"); echo("\t\t<td>" . "$lng" . "</td>\n");*/ // Print out the contents of each row into a table } echo "</table>"; } else { trigger_error(mysql_error()); // for development only; remove when in production } ?> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/265076-trying-to-pass-a-variable-via-the-get-method/ Share on other sites More sharing options...
Pikachu2000 Posted July 1, 2012 Share Posted July 1, 2012 You don't have error reporting set up to display errors, do you? Quote Link to comment https://forums.phpfreaks.com/topic/265076-trying-to-pass-a-variable-via-the-get-method/#findComment-1358364 Share on other sites More sharing options...
scm22ri Posted July 1, 2012 Author Share Posted July 1, 2012 Hey, I believe I do ........ trigger_error(mysql_error()); // for development only; remove when in production Quote Link to comment https://forums.phpfreaks.com/topic/265076-trying-to-pass-a-variable-via-the-get-method/#findComment-1358365 Share on other sites More sharing options...
Pikachu2000 Posted July 1, 2012 Share Posted July 1, 2012 What output does this produce? echo 'Error reporting: ' . ini_get('error_reporting') . '<br>Display errors: ' . ini_get('display_errors'); Quote Link to comment https://forums.phpfreaks.com/topic/265076-trying-to-pass-a-variable-via-the-get-method/#findComment-1358367 Share on other sites More sharing options...
Pibbingston Posted July 1, 2012 Share Posted July 1, 2012 Your getting the link for "?id=" from the $_GET['id'] which is what another page would pass to this page (otherwise its blank) and it would give the same id for every row anyway. you probly mean to use $id from the database Quote Link to comment https://forums.phpfreaks.com/topic/265076-trying-to-pass-a-variable-via-the-get-method/#findComment-1358368 Share on other sites More sharing options...
Pikachu2000 Posted July 1, 2012 Share Posted July 1, 2012 Yeah, it's always better to give a person the answer straight away than it is to help them learn how to find the answer on their own. Quote Link to comment https://forums.phpfreaks.com/topic/265076-trying-to-pass-a-variable-via-the-get-method/#findComment-1358370 Share on other sites More sharing options...
scm22ri Posted July 1, 2012 Author Share Posted July 1, 2012 Hey, Thanks for the replies guy. My mistake for not getting back sooner. Had somethings I needed to do. I added the below line of code and I'm getting an odd error message. My error is Error reporting: 6135 I did some research on 6135. I think it might have to do with my PHP version? http://whatsmyowncarworth.com/practiceTemplate/practice1/33/loans/table3.php Quote Link to comment https://forums.phpfreaks.com/topic/265076-trying-to-pass-a-variable-via-the-get-method/#findComment-1358393 Share on other sites More sharing options...
scm22ri Posted July 1, 2012 Author Share Posted July 1, 2012 Hey Guys, I think I know what I'm doing wrong. I think I might have corrected the problem. Although I'm not entirely sure? Below is my code. When you hover over 1-16 the number is appearing in the URL, which was my goal to figure out! But can I go about it doing it in a better way? echo("\t\t<td><a href='reviews2.php?$id='>" . "$id" . "</a>"); <?php include('init.php'); /*$sql = "SELECT * FROM cars WHERE id='1' ORDER BY year ASC";*/ $sql = "SELECT * FROM dealers"; if ($result = mysql_query($sql)) { echo "<table border='1'>"; echo "<tr> <th>ID</th> <th>Name</th> <th>Address</th> <th>State</th> <th>City</th> <th>Website</th> "; // keeps getting the next row until there are no more to get while ($row = mysql_fetch_array($result)){ $id = $row['id']; $name = $row['name']; $address = $row['address']; $state = $row['state']; $city = $row['city']; $website = $row['website']; $maps = $row['maps']; $lat = $row['lat']; $lng = $row['lng']; // Use this as a loose guide /*<form action="/reviews.php" method="get"> <b>Enter Your First Name:</b> <input type="text" name="zip" maxlength="85" value="" /> <p> <input type="submit" value="Get Approved" name="submit" /> </form>*/ echo("\t<tr>\n"); /*echo("\t\t<td>" . "$id" . "</td>\n");*/ /*echo("\t\t<td><a href='reviews2.php?id=" . $_GET['id'] . "'>" . "$id" . "</a>");*/ echo("\t\t<td><a href='reviews2.php?$id='>" . "$id" . "</a>"); echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$name" . "</a></td>\n"); echo("\t\t<td>" . "$address" . "</td>\n"); echo("\t\t<td>" . "$state" . "</td>\n"); echo("\t\t<td>" . "$city" . "</td>\n"); echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$name" . "</a></td>\n"); echo 'Error reporting: ' . ini_get('error_reporting') . '<br>Display errors: ' . ini_get('display_errors'); /*echo("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$name" . "</a></td>\n"); echo("\t\t<td>" . "<a href='http://$maps' target = '_blank'>" . "$address" . "</td>\n"); echo("\t\t<td>" . "<a href='http://$maps' target = '_blank'>" . "$address" . "</td>\n"); echo("\t\t<td>" . "$state" . "</td>\n"); echo("\t\t<td>" . "$city" . "</td>\n"); echo ("\t\t<td>" . "<a href='http://$website' target = '_blank'>" . "$website" . "</a></td>\n"); echo("\t\t<td>" . "$maps" . "</td>\n"); echo("\t\t<td>" . "$lat" . "</td>\n"); echo("\t\t<td>" . "$lng" . "</td>\n");*/ // Print out the contents of each row into a table } echo "</table>"; } else { trigger_error(mysql_error()); // for development only; remove when in production } ?> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/265076-trying-to-pass-a-variable-via-the-get-method/#findComment-1358397 Share on other sites More sharing options...
Pikachu2000 Posted July 1, 2012 Share Posted July 1, 2012 The 6135 is a binary value that translates to E_ALL & ~E_NOTICE. You wouldn't get notice-level errors because of the second part of that (~E_NOTICE) so you weren't notified that $_GET['id'] was undefined. While developing, you should have error_reporting = -1 display_errors = On in your php.ini file. Restart Apache after saving any changes to the php.ini file. As far as the way you currently have it, it should work as it is now. A couple things I'd mention are that you don't really need to concatenate variables into a double-quoted string, and there's no need to use parentheses with echo. In some circumstances, you can not use parentheses with echo. echo("\t\t<td><a href='reviews2.php?$id='>" . "$id" . "</a>"); //could easily be written as: echo "\t\t<td><a href='reviews2.php?$id='>$id</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/265076-trying-to-pass-a-variable-via-the-get-method/#findComment-1358398 Share on other sites More sharing options...
jcbones Posted July 1, 2012 Share Posted July 1, 2012 But, since there is no real reason to have a variable to be the same as the value, I would suggest. echo("\t\t<td><a href='reviews2.php?$id='>" . "$id" . "</a>"); //could easily be written as: echo "\t\t<td><a href='reviews2.php?id=$id'>$id</a>"; See what I did there? Quote Link to comment https://forums.phpfreaks.com/topic/265076-trying-to-pass-a-variable-via-the-get-method/#findComment-1358406 Share on other sites More sharing options...
Pikachu2000 Posted July 1, 2012 Share Posted July 1, 2012 Yup. Completely missed the missing argument, didn't i? Quote Link to comment https://forums.phpfreaks.com/topic/265076-trying-to-pass-a-variable-via-the-get-method/#findComment-1358412 Share on other sites More sharing options...
jcbones Posted July 1, 2012 Share Posted July 1, 2012 It's not often I catch something you missed, it is usually the other way around. Thought I would rub it in a little. Quote Link to comment https://forums.phpfreaks.com/topic/265076-trying-to-pass-a-variable-via-the-get-method/#findComment-1358423 Share on other sites More sharing options...
scm22ri Posted July 1, 2012 Author Share Posted July 1, 2012 Hey Guys, Thanks for the responses. I appreciate them. I'm just having one minor issue now. I'm trying to echo out the name of the business on page reviews2.php the visitor clicked on. I'm using the GET method but does not seem to want to work. I'm pretty sure my code is correct but I'm not sure what I'm doing wrong not to echo the name of the business. Thanks everyone! http://whatsmyowncarworth.com/practiceTemplate/practice1/33/loans/table3.php http://whatsmyowncarworth.com/practiceTemplate/practice1/33/loans/reviews2.php?Online%20Auto%20Sales <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <?php $name = $_GET['name']; echo $name; ?> <b>Write a Review!</b> <form name="form"> <textarea type="text" name="reviews" "rows="6" cols="75"> </textarea> </br> <input type="submit" value="Submit!"/> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/265076-trying-to-pass-a-variable-via-the-get-method/#findComment-1358430 Share on other sites More sharing options...
Pikachu2000 Posted July 2, 2012 Share Posted July 2, 2012 Did you catch this from jcbones' post above? echo "\t\t<td><a href='reviews2.php?id=$id'>$id</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/265076-trying-to-pass-a-variable-via-the-get-method/#findComment-1358431 Share on other sites More sharing options...
scm22ri Posted July 2, 2012 Author Share Posted July 2, 2012 Brilliant! I understand why it works! Thanks guys for the help, much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/265076-trying-to-pass-a-variable-via-the-get-method/#findComment-1358442 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.