Jump to content

phpfan28

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Everything posted by phpfan28

  1. Okay, since I'm still new to php, could you provide me where the exact spot I should put the header() function, that will help me a lot since I'm a little lost. Thanks!
  2. I having trouble with my re-direct code on my php registration form. The form does submit data to the database but I'm getting the following error. "Warning: Cannot modify header information - headers already sent by (output started at /homepages/25/d232402382/htdocs/testencourage/registration.php:15) in /homepages/25/d232402382/htdocs/testencourage/registration.php on line 87" I would like the form goes to the thanks.php after submitting the data but its not doing its job. Here is the code. <?php if ($_SERVER['HTTPS']) { header('location: https://www.fakewebsite.com'); } the regular html syntax <title>, site navigation, etc... ?> <?php if (isset($_POST['submitted'])){ $fields = array( 'email', 'state', 'district', 'gender', 'age', 'profession', ); if (safe($_POST['survey']=="Yes")){ $survey = "Yes"; } else{ $survey = "No"; } foreach($fields as $fieldName) { if(isset($_POST[$fieldName]) and safe(trim(stripslashes($_POST[$fieldName]))) !==''){ $$fieldName = safe(trim(stripslashes($_POST[$fieldName]))); }else { $errors[] = "Please enter your". $fieldName .""; //code to validate fields } } if(!isset($errors)){ require_once('Connections/encourage.php'); $query = "INSERT INTO participants (email, state, district, gender, age, profession, survey, registration_date) VALUES ('$email', '$state', '$district', '$gender', '$age', '$profession','$survey', NOW())"; //databasse connection $result = mysql_query ($query); if ($result){ $url = 'http://'. $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); if ((substr($url, -1) == '/') || (substr($url, -1) == '\\')) { $url = substr ($url, 0 -1); } $url .= '/thanks.php'; header("Location: $url");// this is line 87 exit(); }else{ echo '<h1 id="mainhead">System Error</hl> <p>Your registration could not be completed due to a system error We apologize for any incovience</p>';//gives system error echo 'p' . mysql_error(). '<br /><br />Query: ' . $query . '</p>'; exit(); } mysql_close(); } else { echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach($errors as $msg) { echo " - $msg<br/>\n"; } echo '</p><p>Please try again.</p><p><br/></p>'; } } function safe($string) { $pattern = "/\r|\n|\%0a|\%0d|Content\-Type:|bcc:|to:|cc:/i"; return preg_replace($pattern, '', $string); } ?> Also I'm going to set up my ssl on the server so I'm planning to use that https redirect syntax but since I'm very new at this, am I missing something. Your help will be greatly appreciated, thanks!
  3. Thanks. I've inserted the comma into the syntax and still no luck. $query = "INSERT INTO participants (email, state, district, gender, age, profession, survey, registration_date) VALUES ('$email', '$state', '$district', '$gender', '$age', '$profession','$survey', ADDDATE())";
  4. Awesome, now my last issue is this error here. "Your registration could not be completed due to a system error We apologize for any incovience pYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ADDDATE())' at line 2 Query: INSERT INTO participants (email, state, district, gender, age, profession, survey, registration_date) VALUES ('fakeemail', 'Arizona', 'mesa', 'female', '20', 'something','' ADDDATE())" It seems to me that this has to do with the mysql syntax of "date" my previous mysql syntax was $query = "INSERT INTO participants (email, state, district, gender, age, profession, survey, registration_date) VALUES ('$email', '$state', '$district', '$gender', '$age', '$profession','$survey' ADDDATE())"; I added the registration_date and it was NOW instead of ADDDATE()) since my version of mysql is 5.0. I am just trying to add a date stamp whenever a user submits their data to the database.
  5. Thanks for your response, It worked but partially. The data does submits but when I click on the checkbox, I get an error message. "Error! The following error(s) occurred: Warning: Invalid argument supplied for foreach() in /homepages/25/d232402382/htdocs/encourage/registration.php on line 79 Please try again." Line 79 points to this line of syntax. echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach($errors as $msg) { echo " - $msg<br/>\n"; } echo '</p><p>Please try again.</p><p><br/></p>'; I've made the checkbox optional, so its not required for the user to check it.
  6. Hello, I'm new to this forum and I need some help. I'm creating a simple database that it submits data from a user input. Unfortunatly, it's not sending any data to mysql also the form is not validating each field. <?php if (isset($_POST['submitted'])){ $fields = array( 'email', 'state', 'district', 'gender', 'age', 'profession', 'survey', ); foreach($fields as $fieldName) { if(isset($_POST[$fieldName]) and trim($_POST[$fieldName]) !==''){ $fieldName = trim($_POST[$fieldName]); }else { $errors[] = "Please enter your". $fieldName .""; //code to validate fields } } if(isset($errors)){ require_once('Connections/encourage.php'); $query = "INSERT INTO participants (email, state, district, gender, age, profession, survey) VALUES ('$email', '$state', '$district', '$gender', '$age', '$profession','$survey')"; //databasse connection $result = mysql_query ($query); if ($result){ echo '<h1 id="mainhead">Thanks for submitting</hl> <p>You are now registered</p>'; exit(); }else{ echo '<h1 id="mainhead">System Error</hl> <p>Your registration could not be completed due to a system error We apologize for any incovience</p>';//gives system error echo 'p' . mysql_error(). '<br /><br />Query: ' . $query . '</p>'; exit(); } mysql_close(); } else { echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach($errors as $msg) { echo " - $msg<br/>\n"; } echo '</p><p>Please try again.</p><p><br/></p>'; } } ?> <form id="form1" name="form1" method="post" action"registration.php"> <fieldset class="first"> <label class="lableone" for="email">Email:* </label> <input name="email" value="<?php if(isset($_POST['email'])) echo $_POST['name'];?>"/> <label for="state"/>State:* </label> <input name="state" value="<?php if(isset($_POST['state'])) echo $_POST['state'];?>"/> <label for="schooldistrict"/>School District:* </label> <input name="schooldistrict" value="<?php if(isset($_POST['district'])) echo $_POST['district'];?>" /> <label for="gender">Gender:* </label> <select name="gender"> <option>Choose Your Gender</option> <option value="male" <?php echo ($form['gender'] == 'male' ? ' selected' : ''); ?>>Male</option> <option value="female"<?php echo ($form['gender'] == 'female' ? ' selected' : ''); ?>>Female</option> </select> <label for="age"/>Your Age:* </label> <input name="age" type="text" class="age" maxlength="2" value="<?php if(isset($_POST['age'])) echo $_POST['age'];?>" /> <label for="profession"/>Profession:* </label> <input name="profession" value="<?php if(isset($_POST['age'])) echo $_POST['age'];?>" /> <label for="surveys"/>Willingness to participate in future surveys: </label> <input name="surveys" type="checkbox" id="surveys" value="yes" <?php echo ($form['survey'] == 'yes' ? 'checked' : '');?>/> </fieldset> <fieldset> <input class="btn" name="submit" type="submit" value="Submit" /> <input class="btn" name="reset" type="reset" value="Clear Form" /> <input type="hidden" name="submitted" value="TRUE" /> </fieldset> </form> Can someone help me out? Thanks in advanced!
  7. Most def i'll have them re-direct so they can enter their info again. the reason why i have the echo part empty, if I return them if the info is correct then the returned value of (i.g) name, phone,comments will come like this. jane doe84993333heyhoware you. So i prefer the thanks for submitting output. One more thing. When the user submits the form to me, the validation and the captcha prevents the form to return any data to me. I'm just receiving blank emails, period. But much appreciated for your assistance guys!
  8. Hey guys, Got bit of a dilemma. I've created a form in php for my website, somehow i'm getting blank emails every 2 or 3 weeks. The form works great when people enter data but at times, I just receive nothing. I tested the form on different computers to confirm it works. Here is what I have done on the html contact form. I've used the built in javascript dreamweaver cs4 validation for the fields and used captcha for a layer of security (it saved as contact.php). Now here is the php code. <?php $errors = array(); if(empty($_POST['name'])){ $errors[] = 'Please enter your name'; } else { echo ""; } if(empty($_POST['email'])){ $errors[] = 'Please enter your email'; } else { echo ""; } if(empty($_POST['comments'])){ $errors[] = 'Please enter your comments'; } else { echo ""; } $emailPattern = '/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i'; $to = "fake@email.com"; $subject = 'huuh'; $from = 'whaat?'; $name = safe (stripslashes( $_POST['name']) ); $email = safe($_POST['email'] ); $phone = safe($_POST['phone'] ); $reasons = safe ($_POST['reasons']); $search = safe( $_POST['search']); $facebook = safe($_POST['facebook'] ); $wsb = safe ( $_POST['wsb']); $other = safe( $_POST['other']); $comments = safe(stripslashes($_POST['comments']) ); $headers = "From: ". $from . "<" . $to. ">\r\n"; $headers .= "Reply-To: " . $email . "\r\n"; $headers .= "Return-path: ". $email; $message .= "Name: " . $name . "\n"; $message .= "Email: " . $email . "\n\n"; $message .= "Phone Number: " . $number . "\n\n\n"; $message .= "Reasons: " . $reasons . "\n\n\n\n"; $message .= "Facebook: " . $facebook . "\n\n\n\n\n";; $message .= "WSB-TV: " . $wsb . "\n\n\n\n\n\n"; $message .= "Other: " . $other . "\n\n\n\n\n\n\n"; $message .= "Comments: " . $comments . "\n\n\n\n\n\n\n\n"; if (mail($to,$subject,$message,$headers)){ echo "Thank you so much for your Inquiry. I'm looking forward in serving you soon!"; } else { echo "&Result=error"; } function safe($string) { $pattern = "/\r|\n|\%0a|\%0d|Content\-Type:|bcc:|to:|cc:/i"; return preg_replace($pattern, '', $string); } ?> Please help and thanks in advanced!
×
×
  • 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.