Jump to content

HELLO GUYS :)


Toy

Recommended Posts

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!!!

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 

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.