Toy Posted March 3, 2011 Share Posted March 3, 2011 I'm trying to $_GET a value and then input it into my database but this obviously doesn't work, I have no idea why. As soon as I run a "if (isset($_POST['submit']" action the value of the $_GET dissapears completly, I have no idea why, I've tried both XAMPP and WAMP with Apache and MySQL but it doesn't seem to work. Is this simply just not possible or am I doing something wrong...Help me!!! Quote Link to comment https://forums.phpfreaks.com/topic/229496-hello-guys/ Share on other sites More sharing options...
Pikachu2000 Posted March 3, 2011 Share Posted March 3, 2011 There's probably something wrong with your code. Quote Link to comment https://forums.phpfreaks.com/topic/229496-hello-guys/#findComment-1182411 Share on other sites More sharing options...
shlumph Posted March 3, 2011 Share Posted March 3, 2011 You're doing something wrong. But if you post the relevant code we can probably help you out. In general practice, information retrieved via $_GET should only be used to display certain information. Not really used for inserting. Quote Link to comment https://forums.phpfreaks.com/topic/229496-hello-guys/#findComment-1182416 Share on other sites More sharing options...
Toy Posted March 3, 2011 Author Share Posted March 3, 2011 I'm pretty certain I'm not doing anything wrong, other values such as the session information was successfully inserted, only the GET data that just left a blank... :/ If you still want I can post my code if that would be to any help. Quote Link to comment https://forums.phpfreaks.com/topic/229496-hello-guys/#findComment-1182420 Share on other sites More sharing options...
Muddy_Funster Posted March 3, 2011 Share Posted March 3, 2011 if you still want help - we still want your code Quote Link to comment https://forums.phpfreaks.com/topic/229496-hello-guys/#findComment-1182467 Share on other sites More sharing options...
Toy Posted March 3, 2011 Author Share Posted March 3, 2011 <?php include("include/connect.php"); if (isset($_GET['value'])) { echo $_GET['value']; // still works and outputs the value fine if (isset($_POST['submit'])) { // here the value of "value" dissapears! mysql_query('insert into test (one, two) values("'.$_GET['value'].'", "normal text")'); } } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="submit" name="submit"> </form> .php?value=hamburger will now output a lovely onetwo (BLANK FIELD)normal text Quote Link to comment https://forums.phpfreaks.com/topic/229496-hello-guys/#findComment-1182488 Share on other sites More sharing options...
cunoodle2 Posted March 3, 2011 Share Posted March 3, 2011 You seem to be mixing up double and single quotes. Try this.. if (isset($_GET['value'])) { echo $_GET['value']; // still works and outputs the value fine if (isset($_POST['submit'])) { // here the value of "value" dissapears! echo "<br /><b>SECOND TIME:</b>".$_GET['value']; // try echoing again as I be it is still there. $query = "insert into `test` (one, two) values('".$_GET['value']."', 'normal text');"; mysql_query($query); } } There for sure were issues in your query with formatting and mixing up of single and double quotes. Quote Link to comment https://forums.phpfreaks.com/topic/229496-hello-guys/#findComment-1182499 Share on other sites More sharing options...
kenrbnsn Posted March 3, 2011 Share Posted March 3, 2011 When the form is generated, you are not using the value of $_GET['value'], so it's not there when the form is submitted. You only do the query after the form is submittted. You need to send the value of $_GET['value'] with the form: <?php include("include/connect.php"); if (isset($_GET['value'])) { echo $_GET['value']; // still works and outputs the value fine if (isset($_POST['submit'])) { // here the value of "value" dissapears! $q = "insert into test (one, two) values('{$_GET['value']}', 'normal text')"; mysql_query($q); } } ?> <form action="?value=<?php echo $_GET['value']?>" method="post"> <input type="submit" name="submit"> </form> Ken Quote Link to comment https://forums.phpfreaks.com/topic/229496-hello-guys/#findComment-1182504 Share on other sites More sharing options...
gizmola Posted March 3, 2011 Share Posted March 3, 2011 To Ken's point, you seem confused about the diffrence between get and post. There's really no reason to be mixing them together. $_GET values come from url parameters .... ?somekey=value&somekey2=value2 Post values come from a form where the method= POST. We have no idea what you are doing or why based on your code, but if you just want to use GET values, you can do that easily enough by having your form use method="get". That will cause all the form data to be turned into get parameters when the form is submitted. These days most people reserve get params for application flow of control (the controller part of Model view controller pattern). Data that you're getting from a user and which you eventually would want to insert is kept inside the post mechanism. Mixing the two, while it can be done, is confusing and not the best practice at all. Quote Link to comment https://forums.phpfreaks.com/topic/229496-hello-guys/#findComment-1182515 Share on other sites More sharing options...
Toy Posted March 3, 2011 Author Share Posted March 3, 2011 sorry, I'm not that familiar with all edges off php, anyways thank you all:) much appreciated EDIT: why can't I mark it as solved? :S Quote Link to comment https://forums.phpfreaks.com/topic/229496-hello-guys/#findComment-1182538 Share on other sites More sharing options...
gizmola Posted March 3, 2011 Share Posted March 3, 2011 The solved system is an SMF forum modification that was created by a mod for the use of phpfreaks. Recently the forum was upgraded, and the customizations would need to be re-installed. I don't know what the plans are in terms of the customization at this point. Quote Link to comment https://forums.phpfreaks.com/topic/229496-hello-guys/#findComment-1182543 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.