Jump to content

Undefined Variable


topflight

Recommended Posts

I am getting an undefined variable error on line 27 for $error. Here is the portion of my code:

<?php
if (!$_POST['lname']){ $error ='No Last  name<br>'; }
if (!$_POST['email']){ $error ='No Email Address<br>'; }
if (!$_POST['vatsimid']){ $error ='No VATSIM ID<br>'; }
if (!$_POST['hub']){ $error ='No Hub<br>'; }
if (!$_POST['pwd']){ $error ='No Password<br>'; }
if (!$_POST['pwdc']){ $error ='No Password Conformation<br>'; }
if (!$_POST['emailc']){ $error ='No Conformation Email Address<br>'; }
if ($_POST['thours']){ if (!$_POST['thoursc']){ $error ='No comments<br>'; }}
if ($_POST['email'] != $_POST['emailc']){ $error ='Email mismatch'; }
if ($_POST['pwd'] != $_POST['pwdc']){ $error ='Password mismatch'; }



if ($error){ echo $error; } else {
?>

 

Line 27:

<?php 
if ($error){ echo $error; } else { ?>

 

I don't know what happen one day it was working the next it wasn't and I haven't done anything to it.

 

Link to comment
https://forums.phpfreaks.com/topic/148042-undefined-variable/
Share on other sites

A better way of doing this (IMHO) would be:

<?php
$error = array();
if (!$_POST['lname']){ $error[] ='No Last  name'; }
if (!$_POST['email']){ $error[]='No Email Address'; }
if (!$_POST['vatsimid']){ $error[] ='No VATSIM ID'; }
if (!$_POST['hub']){ $error[] ='No Hub'; }
if (!$_POST['pwd']){ $error[] ='No Password'; }
if (!$_POST['pwdc']){ $error[] ='No Password Conformation'; }
if (!$_POST['emailc']){ $error[] ='No Conformation Email Address'; }
if ($_POST['thours']){ if (!$_POST['thoursc']){ $error[] ='No comments'; }}
if ($_POST['email'] != $_POST['emailc']){ $error[] ='Email mismatch'; }
if ($_POST['pwd'] != $_POST['pwdc']){ $error[] ='Password mismatch'; }
if (!empty($error))
    echo implode('<br>',$error);
else {
?>

Ken

Link to comment
https://forums.phpfreaks.com/topic/148042-undefined-variable/#findComment-777047
Share on other sites

This is my code:

 

 

 

 

<?php

 

 

include 'db.php';

session_start();

if(isset($_SESSION['LOGGEDIN'])==TRUE){

echo'You are already a member of Simulated Alaska';}

 

if(isset($_POST['apply'])){

$error = array();

if (!$_POST['lname']){ $error[] ='No Last  name'; }

if (!$_POST['email']){ $error[]='No Email Address'; }

if (!$_POST['vatsimid']){ $error[] ='No VATSIM ID'; }

if (!$_POST['hub']){ $error[] ='No Hub'; }

if (!$_POST['pwd']){ $error[] ='No Password'; }

if (!$_POST['pwdc']){ $error[] ='No Password Conformation'; }

if (!$_POST['emailc']){ $error[] ='No Conformation Email Address'; }

if ($_POST['thours']){ if (!$_POST['thoursc']){ $error[] ='No comments'; }}

if ($_POST['email'] != $_POST['emailc']){ $error[] ='Email mismatch'; }

if ($_POST['pwd'] != $_POST['pwdc']){ $error[] ='Password mismatch'; }

if (!empty($error))

    echo implode('<br>',$error);

else {

 

 

if ($error){ echo $error;?> <FORM><INPUT TYPE="BUTTON" VALUE="Fix Errors"

ONCLICK="history.go(-1)"></FORM> <? } else {

 

$cerror = count($error);

$fpwd= $_POST['pwd'];

$pwd = md5($fpwd);

$fname = $_POST['fname'];

$lname = $_POST['lname'];

$email = $_POST['email'];

$pilotl= mysql_query("SELECT * FROM `pilots` WHERE hub='$_POST[hub]' ORDER BY login DESC LIMIT 1") or die(mysql_error());

 

$plrows = mysql_num_rows($pilotl);

if ($plrows=="0"){

if ($_POST['hub']=="KPDX"){ $login = "1000"; }

if ($_POST['hub']=="KLAX"){ $login = "2000"; }

if ($_POST['hub']=="PANC"){ $login = "3000"; }

if ($_POST['hub']=="KSEA"){ $login = "4000"; }} else {

if($cerror =='0'){

while($plr = mysql_fetch_array($pilotl)){ $login = $plr[login]; } $login = $login + 1; 

 

$update = mysql_query("INSERT INTO pilots (login,pwd,fname,lname,email,hub,thours,thoursc,rating,vatsimid,date,ip,status,hm,ed,bm,active) VALUES ('$login','$pwd','$_POST[fname]','$_POST[lname]','$_POST','$_POST[hub]','$_POST[thours]','$_POST[thoursc]','First Officer','$_POST[vatsimid]','$now','$ip','0','0','0',0,0)") or die(mysql_error());

 

 

$jto = "<email_goes_here>";

$jsubject = "A new member has signed up";

$jjmessae = "

message_here ";

$from = "emailaddress_here";

$jheaders = "From: $from";

 

mail($jto, $jsubject, $jmessage, $jheaders);

 

$to = "$email";

$subject = "RE:Application ($fname $lname)";

$messae = "

Dear ($fname $lname),

 

<Welcome email here>

 

 

 

 

Sincerly,

Staff

";

 

$from = "email_will_go_here;

$headers = "From: $from";

mail($to, $subject, $message, $headers);

 

 

echo'<b>Application Sent </b>';

 

} } } }

 

 

Link to comment
https://forums.phpfreaks.com/topic/148042-undefined-variable/#findComment-777778
Share on other sites

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.