undefined variable

Cannot understand been through this 3 times now and still no joy.

below id the index.php page it worked fine until i added this array to the process.php page
[php]index.php

<?php include "process.php"; ini_set('error_reporting', E_ALL); ini_set('display_errors', '1'); ?> Form Sample <?php if (isset($msg)) { echo '

', $msg , '

'; }?>
  1. Name * <?php if (isset($err_myname)) { echo $err_myname; } ?> <?php if (isset($err_patternmatch)) { echo $err_patternmatch; } ?>
  2. Password <?php if (isset($err_passlength)) { echo $err_passlength; } ?>
  3. Password (confirm) <?php if (isset($err_mypassconf)) { echo $err_mypassconf; } ?>
  4. Favorite Music
    1. /> Rock
    2. /> Classical
    3. /> Reggaeton
  5. How did you hear about us? Choose... >A friend >Facebook >Twitter
  6. Request Type
    1. /> Question
    2. /> Comment
    3. /> Suggestion
  7. Comment: (html is not allowed) <?php if (isset($mycomments)) { echo $mycomments; } ?>
send
  process.php
<?php ini_set('error_reporting', E_ALL); ini_set('display_errors', '1'); if (($_SERVER['REQUEST_METHOD'] == 'POST') && (!empty($_POST['action']))): if (isset($_POST['myname'])) { $myname = $_POST['myname']; } if (isset($_POST['mypassword'])) { $mypassword = $_POST['mypassword']; } if (isset($_POST['mypasswordconf'])) { $mypasswordconf = $_POST['mypasswordconf']; } if (isset($_POST['mycomments'])) { $mycomments = filter_var($_POST['mycomments'], FILTER_SANITIZE_STRING ); } if (isset($_POST['reference'])) { $reference = $_POST['reference']; } if (isset($_POST['favoritemusic'])) { $favoritemusic = $_POST['favoritemusic']; } if (isset($_POST['requesttype'])) { $requesttype = $_POST['requesttype']; } $formerrors = false; if ($myname === '') : $err_myname = '
Sorry, your name is a required field
'; endif; // input field empty if (strlen($mypassword) <= 6): $err_passlength = '
Sorry, the password must be at least six characters
'; endif; //password not long enough if ($mypassword !== $mypasswordconf) : $err_mypassconf = '
Sorry, passwords must match
'; endif; //passwords don't match $formdata = array ( 'myname' => $myname, 'mypassword' => $mypassword, 'mypasswordconf' => $mypasswordconf, 'mycomments' => $mycomments, 'reference' => $reference, 'favoritemusic' => $favoritemusic, 'requesttype' => $requesttype ); if ( !(preg_match('/[A-Za-z]+, [A-Za-z]+/', $myname)) ) : $err_patternmatch = '
Sorry, the name must be in the format: Last, First
'; endif; // pattern doesn't match if (!($formerrors)) : $to = " [email protected] "; $subject = " From $myname ----- Signup Page"; $message = json_encode($formdata); $replyto = "From: [email protected] \r\n"; "Reply-To: [email protected]@sky.com"; if (mail($to, $subject, $message)): $msg = "Thanks for filling out our form"; else: $msg = "Problem sending the message"; endif; //mail form data endif; //check for form errors endif; //form submitted ?>[/php]

Like i say it worked fine until i added this to the page

$formdata = array (
‘myname’ => $myname,
‘mypassword’ => $mypassword,
‘mypasswordconf’ => $mypasswordconf,
‘mycomments’ => $mycomments,
‘reference’ => $reference,
‘favoritemusic’ => $favoritemusic,
‘requesttype’ => $requesttype
);

cannot see anything wrong as of yet been through it three times and result the same in browser.

Notice: Undefined variable: favoritemusic in C:\xampp\htdocs\webs\06-01\workingfolder\forms\process.php on line 37

Notice: Undefined variable: requesttype in C:\xampp\htdocs\webs\06-01\workingfolder\forms\process.php on line 39

Thanks for filling out our form

I think ur if statement is written wrong.

if (isset($favoritemusic) && in_array(“rock”, $favoritemusic)) { echo “checked”; }

The first part actually closed off the if statement, so the in_array part is just hanging out there, causing the error.

so it is ok to carry on with my form then, i apologise i just do not like error messages when checking my pages it rings alarm bells.

You answered before I could get my answer fixed.

will this send the message to my email as i have tryed and it does not

iam following a lynda tutorial

Lynda Validating and Processing Forms with JavaScript and PHP_2013

and following the php section on validating forms with php

it works now all i had to do was completely fill out the form so all the variables were filled, but why doesn’t it send the message to my email…

Sponsor our Newsletter | Privacy Policy | Terms of Service