problem getting form data / mysql query INSERTs null

Discussion in 'PHP' started by advancedfuture, Jan 10, 2008.

  1. #1
    Been working on my message reply form. For some reason after the user hits the reply button I can't get data out of it! All the variables show up blank... So when they hit reply it just puts a new line in my database with all the values set to 0.....

    
    <?php
    //HOLDS THE $username && $token VALUE'S / and SESSION_START()
    include 'session.php';
    
    //Get the username / token / msg ID from the reply button on the message.
    $_GET['user'];
    $_GET['my_token'];
    $msgid = $_GET['messageid'];
    
    include 'dbconnect.php';
    
    //MAKE SURE THAT ONLY THE CORRECT USER CAN REPLY TO AND SEE THE MESSAGE
    if($username == $_GET['user'] && $token == $_GET['my_token'])
    {
    	//Retrieve the message from the database so that we can
    	//see what we are replying to!
    
    	$query = "SELECT message, mailSubject, mailFrom FROM mail WHERE msgid = '$msgid'";
    	$results = mysql_query($query);
    
    	while($row=mysql_fetch_array($results))
    	{
    		$msg = $row['message'];
    		$subj = $row['mailSubject'];
    		$mailFrom = $row['mailFron'];
    	}
    	
    	//HTML output box so we can see the message and reply.
    	echo "<center>";
    	echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" enctype=\"multipart/form-data\" name=\"replyMessage\" id=\"replyMessage\">";
    	echo "<strong>Subject:</strong><br /><textarea name=\"mailSubject\" cols=\"40\" rows=\"1\" value=\"\">RE: ".$subj."</textarea><br />";
    	echo "<strong>Message:</strong><br /><textarea name=\"message\" cols=\"40\" rows=\"4\" value=\"\">".$msg."</textarea><br />";
    	echo '<input type="submit" name="replySubmit" id="replySubmit" value="Reply" />';
    	echo "</form></center>";
    }
    
    //If the Reply button is hit execute this code
    //********************************************
    if($_POST['replySubmit'] == 'Reply')
    {
    	echo $mailFrom; //SHOWING UP NULL VALUE ?????
    	echo $username;
    	echo $_GET['message']; //SHOWING UP NULL VALUE?????
    	echo $_GET['mailSubject']; //SHOWING UP NULL VALUE?????
    	
    	
    	//Send the reply message	
    	$query = "INSERT INTO mail (rcpt, mailFrom, mailSubject, message, opened, timeOpened, timeSent) VALUES (rcpt = '$mailFrom',
    	mailFrom = '$username', mailSubject = '$mailSubject', message = '$message', opened='n', timeOpened = '', timeSent='time()')";
    	$results = mysql_query($query);
    
    	//IF MESSAGE SUCCESSFULLY SENT
    	if($results)
    	{
    		echo "Thank you, your response has been sent! <br />";
    		header ( "Refresh: 10; inbox.php" );
    	}
    
    	//ANY OTHER REASON REDIRECT TO MESSAGE TO TRY AGAIN
    	else
    	{
    		echo "Sorry Message Reply Failed <br />";
    		header( "Refresh: 0; ".$_SERVER['REQUEST_URI']."" );
    	}
    }
    	
    //THIS SECTION IS NOW HANDLED IN SESSION.PHP
    //******************************************
    //******************************************
    
    //else
    //{
    	//IF TOKEN AND USER ARE NOT AUTHENTICATED THEN
    	//DONT SHOW THEM ANYTHING!
    	//echo "Sorry you are not allowed to be here!";
    	//echo "Redirecting to login page!";
    	//header( "Refresh: 3; login.php" );
    //}
    ?>
    
    Code (markup):
     
    advancedfuture, Jan 10, 2008 IP
  2. advancedfuture

    advancedfuture Banned

    Messages:
    481
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Figured it out... guess I have to pass all variables via $_POST and my INSERT query was malformed.
     
    advancedfuture, Jan 10, 2008 IP
  3. lfhost

    lfhost Peon

    Messages:
    232
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you wanted the $_GET data to work, you would need to change the method to GET in the form.
    But I would only use a $_GET and method get for search and not for posting things like username/password etc.
     
    lfhost, Jan 10, 2008 IP