Jump to content

[SOLVED] $_GET only works at the top of my script...


Klance

Recommended Posts

For some reason $_GET only works at the top of my script. This is the URL: http://24.177.36.183/test/Submit/index.php?game=GH2&console=PS2&diff=Expert

 

and I want to get out the console and difficulty so I used

 

$diff = $_GET['diff'];

$console = $_GET['console'];

 

And those work, but for some reason by the time it's ready to enter them into mysql they turn blank. I've tried using the $_GET right before they were entered into mysql and that doesn't make a difference, their still blank.

 

Well heres the script, I hope somone can help.

 

Thanks in advance

 

<?php

$diff = $_GET['diff'];
$console = $_GET['console'];
echo $diff . '<br />';
echo $console;

//check to see if form is submitted, if not, show form
if (!isset($_POST['submit'])) {
?>
<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 = "root";
$pass = "";
$db = "GHScores";

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

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

echo $diff;
echo $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
Share on other sites

That's because the values are not persistant across different requests. When the page first loads, your variables are in the $_GET array. You then submit a form. When that request is made, the variables are not sent, hence why they do not get entered into the database.

 

You can either add them to the form action URL or add hidden fields. I'd probably go with the first method:

 

<form action="scores.php?diff=<?php echo $diff;?>&console=<?php echo $console;?>" method="post">

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.