jrschafer Posted July 6, 2010 Share Posted July 6, 2010 Hi, I'm new to PHP and programming in general... just going through some simple testing. I am getting an error on line 8 (regarding the empty operator). Any advice is much appreciated. Thanks! <?php if (isset($_POST['submit'])) { $first = $_POST['first']; $last = $_POST['last']; $email = $_POST['email']; $ouput_form = false; if (empty($first)) && (empty($last)) { echo 'First or Last Name are empty.<br />'; $output_form = true; } if (!empty($first) && (!empty($last)){ $dbc = mysqli_connect ('localhost',root,'','elvis_store') or die('Error connecting to MYSQL server'); $query = "INSERT INTO email_list (first_name, last_name, email) VALUE('$first', '$last', '$email')"; mysqli_query($dbc, $query) or die('Error querying the database.'); echo 'Customer added.'; mysqli_close($dbc); } } else { $output_form = true; } if ($output_form) { ?> <p>Enter your first name, last name, and email to be added to the Make Me Elvis mailing list.</p> <form method="post" action="<?php echo $_server['php_self']; ?>"> <label for="first">First Name:</label> <input type="text" id="first" name="first" value="<?php echo $first; ?>" /><br /> <label for="last">Last Name:</label> <input type="text" id="last" name="last" value="<?php echo $last; ?>" /><br /> <label for="email">Email:</label> <input type="text" id="email" name="email" value="<?php echo $email; ?>" /><br /> <input type="submit" name="submit" value="submit" /> </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/206843-pulling-from-post/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 6, 2010 Share Posted July 6, 2010 You have an extra - ) Link to comment https://forums.phpfreaks.com/topic/206843-pulling-from-post/#findComment-1081733 Share on other sites More sharing options...
Pikachu2000 Posted July 6, 2010 Share Posted July 6, 2010 Not the cause of your current problem, but in line 6 ( $ouput_form = false; ), $output is misspelled. As for the error, you have too many parentheses in the first part of the conditional, and the 'and' (&&) operator should really be an 'or' ( || ) operator. There's actually more code that could easily be cut out of that script, but I'm off to bed now . . . //This: if (empty($first)) && (empty($last)) { //Should be: if ( empty($first) || empty($last) ) { Link to comment https://forums.phpfreaks.com/topic/206843-pulling-from-post/#findComment-1081734 Share on other sites More sharing options...
jrschafer Posted July 6, 2010 Author Share Posted July 6, 2010 Thanks guys I appreciate it! This is a great forum. Link to comment https://forums.phpfreaks.com/topic/206843-pulling-from-post/#findComment-1081736 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.