Jump to content

[SOLVED] form isnt passing my variable?


aebstract

Recommended Posts

Hey guys, been awhile since I have been around these parts, but I am having a little trouble.

I got a form with two simple inputs. I put a check at the top of my page to see if the field has information entered or not. Well it is returning false when it has information and when it doesn't.

 

Here is what I have:  (file - account2.php)

 

<?php
session_start();
header("Cache-control: private");

if (isset ($_POST['submit'])) {
$problem = FALSE;



if (empty ($_POST['plantloc'])) {
$problem = TRUE;
$error .= 'Must enter a plant location<br />';
}







mysql_connect("*","*","*");
mysql_select_db("*");


if (!$problem) {

$plantloc  = $_POST['plantloc'];

$length = 6;
$password = "";
$possible = "0123456789bcdfghjkmnpqrstvwxyz"; 
$i = 0; 
    
while ($i < $length) { 
    $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
    if (!strstr($password, $char)) { 
      $password .= $char;
      $i++;
    }

  }

$password2 = md5($_POST['password1']);
$address = $_POST['address'];


$result = MYSQL_QUERY("INSERT INTO plants (plantloc,password,address)".
"VALUES ('$plantloc, '$password2', '$address,')");


$sendmail = "
$password2
";

mail ('[email protected]', 'Thank You', $sendmail, 'From: [email protected]');



} else {
$content .= "$error";
}
}
?>

 

 

 

 

and the form area:

 


<?php
$content .= '<form action="account2.php?menu=create" method="post">
<br />
Plant Location: <br /><input type="text" maxlength="100" class="textfield" name="username" size="40" value="' . $_POST[plantloc] . '" /><br /><br />

Address:<br />
<textarea cols="50" rows="4" name="address" value="' . $_POST[address] . '"></textarea>
<br /><br />

<input type="submit" name="submit" value="submit" class="textfield" /></form>';



echo "$content";
?>

Link to comment
https://forums.phpfreaks.com/topic/86486-solved-form-isnt-passing-my-variable/
Share on other sites

I noticed you seem to be missing a '}'

 

<?php
if (isset ($_POST['submit'])) {
    $problem = FALSE;
}      //This was missing


if (empty ($_POST['plantloc'])) {
    $problem = TRUE;
    $error .= 'Must enter a plant location<br />';
}
?>

 

 

Actually when fiile transfers data from one page to another page 'name' is used to retrieve the value.

 

 

So, it will work,

instead of $_POST['plantloc'] ==> use =>>&_POST['username'];

 

If any problem Then PM me.

Reply it works.

 

 

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.