Jump to content

Trying to Pass a Variable via the GET Method?


scm22ri

Recommended Posts

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.