Jump to content

Help with $_GET


Klance

Recommended Posts

If you go here: http://24.177.36.183/test/Submit/index.php?game=GH2&console=PS2&diff=Expert

you'll see that console=PS2 and diff=Expert is in the url and I want to enter these into a database. These were set on different pages btw.

 

For some reason $_GET['diff'] and $_GET['console'] turn out blank, here is the code for the page:

 

<?php

//check to see if form is submitted, if not, show form
if (!isset($_POST['submit'])) {
echo $_GET['diff'];
?>

<form action="scores.php" method="post">
Song*:
<select name="song" size="1">
<option value="">Click Here to Choose a Song</option>
<option value="">-----Opening Licks-----</option>
<option value="Shout at the Devil">Shout at the Devil</option>
<option value="Mother">Mother</option>
<option value="Surrender">Surrender</option>
<option value="Woman">Woman</option>
<option value="Tonight I'm Gonna Rock You Tonight">Tonight I'm Gonna Rock 

You Tonight</option>
<option value=""></option>
<option value="">-----Amp-Warmers-----</option>
<option value="Strutter">Strutter</option>
<option value="Heart-Shaped Box">Heart-Shaped Box</option>
<option value="Message in a Bottle">Message in a Bottle</option>
<option value="You Really Got Me">You Really Got Me</option>
<option value="Carry on Wayward Son">Carry on Wayward Son</option>
<option value=""></option>
<option value="">-----String-Snappers-----</option>
<option value="Monkey Wrench">Monkey Wrench</option>
<option value="Them Bones">Them Bones</option>
<option value="Search and Destroy">Search and Destroy</option>
<option value="Tattooed Love Boys">Tattooed Love Boys</option>
<option value="War Pigs">War Pigs</option>
<option value=""></option>
<option value="">-----Thrash and Burn-----</option>
<option value="Cherry Pie">Cherry Pie</option>
<option value="Who Was in My Room Last Night">Who Was in My Room Last 

Night</option>
<option value="Girlfriend">Girlfriend</option>
<option value="Can't You Hear Me Knockin'">Can't You Hear Me 

Knockin'</option>
<option value="Sweet Child O' Mine">Sweet Child O' Mine</option>
<option value=""></option>
<option value="">-----Return of the Shred-----</option>
<option value="Killing in the Name">Killing in the Name</option>
<option value="John the Fisherman">John the Fisherman</option>
<option value="Freya">Freya</option>
<option value="Bad Reputation">Bad Reputation</option>
<option value="Last Child">Last Child</option>
<option value=""></option>
<option value="">-----Relentless Riffs-----</option>
<option value="Crazy on You">Crazy on You</option>
<option value="Trippin' On a Hole in a Paper Heart">Trippin' On a Hole in a 

Paper Heart</option>
<option value="Rock This Town">Rock This Town</option>
<option value="Jessica">Jessica</option>
<option value="Stop">Stop</option>
<option value=""></option>
<option value="">-----Furious Fretwork-----</option>
<option value="Madhouse">Madhouse</option>
<option value="Carry Me Home">Carry Me Home</option>
<option value="Laid to Rest">Laid to Rest</option>
<option value="Psychobilly Freakout">Psychobilly Freakout</option>
<option value="YYZ">YYZ</option>
<option value=""></option>
<option value="">-----Face-Melters-----</option>
<option value="Beast and the Harlot">Beast and the Harlot</option>
<option value="Institutionalized">Institutionalized</option>
<option value="Misirlou">Misirlou</option>
<option value="Hangar 18">Hangar 18</option>
<option value="Free Bird">Free Bird</option>
<option value=""></option>
<option value="">-----Bonus Tracks-----</option>
<option value="Raw Dog">Raw Dog</option>
<option value="Arterial Black">Arterial Black</option>
<option value="Collide">Collide</option>
<option value="Elephant Bones">Elephant Bones</option>
<option value="Fall of Pangea">Fall of Pangea</option>
<option value="FTK">FTK</option>
<option value="Gemini">Gemini</option>
<option value="Push Push (Lady Lightning)"> Push Push (Lady Lightning)

</option>
<option value="Laughtrack">Laughtrack</option>
<option value="Less Talk More Rokk">Less Talk More Rokk</option>
<option value="Jordan">Jordan</option>
<option value="Mr. Fix It">Mr. Fix It</option>
<option value="The New Black">The New Black</option>
<option value="One for the Road">One for the Road</option>
<option value="Parasite">Parasite</option>
<option value="Radium Eyes">Radium Eyes</option>
<option value="Red Lottery">Red Lottery</option>
<option value="Six">Six</option>
<option value="Soy Bomb">Soy Bomb</option>
<option value="The Light That Blinds">The Light That Blinds</option>
<option value="Thunderhorse">Thunderhorse</option>
<option value="Trogdor">Trogdor</option>
<option value="X-Stream">X-Stream</option>
<option value="Yes We Can">Yes We Can</option>
</select>
<br />
Score*:
<input type="text" name="score" /> <br />
Streak:
<input type="text" name="streak" /> <br />
Notes Hit:
<input type="text" name="noteshit" /> <br />
Picture:
<input type="text" name="picture" /> <br />
Video:
<input type="text" name="video" /> <br />
Comment:
<input type="text" name="comment" /> <br />
<input type="Submit" value="Submit" name="submit" /> <br />
<?php
}
else {
//process form
$host = "localhost";
$user = "****";
$pass = "****";
$db = "GHScores";

$conn = mysql_connect($host, $user, $pass) or die("Unable to connect!") ;

mysql_select_db($db) or die("Unable to select database!");

$diff = $_GET['diff'];
$console = $_GET['console'];

$user = "klance";
$song = $_POST['song'];
$streak = $_POST['streak'];
$score = $_POST['score'];
$noteshit = $_POST['noteshit'];
$picture = $_POST['picture'];
$video = $_POST['video'];
$comment = $_POST['comment'];
$timestamp = date("d/m/y : H:i:s", time());

$query = "INSERT INTO gh2 (Song, User, Score, NotesHit, Streak, Timestamp, Console, 

Diff, Comment, Picture, Video) VALUES ('$song', '$user', '$score', '$noteshit', 

'$streak', '$timestamp', '$console', '$diff', '$comment', '$picture', '$video')";

$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
echo "Score Submitted";

mysql_close($conn);

}
?>

Link to comment
https://forums.phpfreaks.com/topic/99464-help-with-_get/
Share on other sites

When loading the page via your link diff IS set to Expert.  But when the form is submitted, you have it's method set to POST.

 

<form action="scores.php" method="post">

 

If you want the method to be POST, then you need to retrieve the values with the $_POST array.

 

$diff = $_POST['diff'];

 

Otherwise you can change the method to get and leave the PHP code unchanged.

 

 

<form action="scores.php" method="get">

Link to comment
https://forums.phpfreaks.com/topic/99464-help-with-_get/#findComment-508969
Share on other sites

When loading the page via your link diff IS set to Expert.  But when the form is submitted, you have it's method set to POST.

 

<form action="scores.php" method="post">

 

If you want the method to be POST, then you need to retrieve the values with the $_POST array.

 

$diff = $_POST['diff'];

 

Otherwise you can change the method to get and leave the PHP code unchanged.

 

 

<form action="scores.php" method="get">

 

diff does not get set in that form, it gets set on PS2.php here it is:

Difficulty: <a href="<?php echo $_SERVER['PHP_SELF'] ?>?game=<?php echo $_GET['game']; ?>&console=<?php echo $_GET['console']; ?>&diff=Easy">Easy</a> |
<a href="<?php echo $_SERVER['PHP_SELF'] ?>?game=<?php echo $_GET['game']; ?>&console=<?php echo $_GET['console']; ?>&diff=Medium">Medium</a> |
<a href="<?php echo $_SERVER['PHP_SELF'] ?>?game=<?php echo $_GET['game']; ?>&console=<?php echo $_GET['console']; ?>&diff=Hard">Hard</a> |
<a href="<?php echo $_SERVER['PHP_SELF'] ?>?game=<?php echo $_GET['game']; ?>&console=<?php echo $_GET['console']; ?>&diff=Expert">Expert</a> |
<br />
<?php
if (!empty($_GET['diff'])) {
include("scores.php");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/99464-help-with-_get/#findComment-509086
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.