PHP - Still Can't Get My Basic Form To Post Properly
Hi there,
I've built a form that should generate an e-mail, but it's not working properly. At first the page wouldn't display at all due to a problem with the EOD tags, that's fixed and I can now see a page, but when I type something in and hit submit, it's just not doing what it's supposed to do. Like I said it's supposed to e-mail me the data and leave the form filled with the data just submitted; it's doing neither. It is however posting the info into the address bar, so something is happening at least.
here's a link to the page: http://www.remembert...hp/testform.php
here's the code:
<?php
if ($_POST['parse_var'] == "testform"){
Similar TutorialsHey y'all, I'm trying to write a PHP script for a login function. There are three elements, two text fields (username and password) and a button which calls the script. Segment from index.php file: <form action = "login.php" method = "POST"> Admin Login: <br> Username: <input type = "text" name = "usernameField"/><br> <!-- Password field--> Password: <input type = "password" name = "passwordField"/><br> <!-- Username field --> <input type = "button" value = "Login" name = "submitButton"/> <!-- Login button --> </form> Segment from login.php file: <?php $connect = mysql_connect("localhost", "root", "root"); if(!$connect){//If user can't connect to database die('Could not connect: ' . mysql_error()); //Throw an error } mysql_select_db("colin_db", $connect); //Get given username and password from username field and password field $givenUsername = $_POST["usernameField"]; $givenPassword = $_POST["passwordField"]; $myQuery = "SELECT * FROM ADMINS WHERE USERNAME = '$givenUsername' AND PASSWORD = '$givenPassword'"; $queryResult = mysql_query($myQuery); $numRows = mysql_num_rows($queryResult); if($numRows == 1){ //If the details are correct... //Reload the page and login echo "<script type = 'text/javascript'> window.location.reload() </script>"; } elseif($numRows == 0){ //Else if the details are not found //Display error accordingly echo "Details not correct!"; } mysql_close($connect); ?> The problem is, when I click the login button, it doesn't do anything. What am I missing? (The information in the database is correct) Thanks, Jake Hi, I'm trying to get HTTP post to work on my server but even the most basic script does not work. Can anyone help me? PHP script: <?php echo 'Hello ' . htmlspecialchars($_POST["name"]) . '!'; ?> I try and POST data to the script using: http://www.czoryk.co.uk/post_test.php?name=Chris But when I try and do that only ' Hello ! ' is displayed. I'm sure this is just a simple error but I can't figure out what's wrong. Thanks, Chris Hey Guys. I am working with a form that shows the grand total on the checkout page. The value of the grand total is inside a hidden field. When click on submit, the _POST array doesn't get back the last value of the grand total. I need to hit the button twice to get the last value. The weird thing is when I echo the value of the grand total it display the latest value, but not with the POST array
For example. If the grand total is $10.00 and I click on submit. It will show the POST['grand_total'] as empty. If I click on submit again it will show the grand total of $10.00.
Below is my code that I am working with. Any help would be really appreciated.
if(isset($_POST['submit'])) { /* Doesn't show if i put it after if($_POST['submit'] */ if(isset($_POST['grand_total'])) { echo $_POST['grand_total']; } } //A bunch of other html/php code. Another class calculates the subtotal assigns it the variable $subtotal $cart_totals = new cartTotals($subtotal, $discounted_amount,$post_values->tip); // Cart class is shown below /* Doesn't show if i put it before if($_POST['submit'] */ if(isset($_POST['grand_total'])) { echo $_POST['grand_total']; } echo "<input name='grand_total' type='hidden' value='$cart_totals->grand_total' />"; // Shows the grand total after second from submission echo "$cart_totals->grand_total"; // Shows grand total after the first submissionCart Totals Class class cartTotals { public $subtotal; public $sales_tax; public $tip; public $grand_total; public $discount_amount; public $href_page; public $invalidCouponMessage; const TEST_ENVIORMENT = FALSE; /** * [ Function gets constructed in the order summary where the [$discount_amount= ""] arg does need to be passed. * But does get passed in when called on the checkout.php page. Therefore we set the default value to an empty string.] * @param [float] $subtotal [subtotal get passed in from the parent class coreCartFunction] * @param string $discount_amount [The class checkCouponCode calculates this discount amount based on the * subtotal and the discount amount. It gets instantiated on the clients side and passed is this construction function. * This is all done on the checkout page.] */ /*The way the construct function works is by invoking all the methods the passed arguments When the methods get invoked the do all the work and set the properties its values. The properties then get echoed out on the client side. */ function __construct($subtotal="", $discount_amount= "", $tip=""){ $this->subTotal($subtotal, $discount_amount);//SubTotal method takes the discount amount and subtracts it from the subtotal. $this->salesTax($subtotal, $discount_amount); $this->tip = $tip; $this->grandTotal(); } private function subTotal($subtotal,$discount_amount) { $rounded_subtotal = round($subtotal-$discount_amount,2); $money_format_subtotal = money_format('%i',$rounded_subtotal); $this->subtotal = $money_format_subtotal; } private function salesTax($subtotal, $discount_amount =""){ $sales_tax = (STORE_SALES_TAX)?(float)STORE_SALES_TAX:8.875; $sales_tax =(($this->subtotal)*$sales_tax)/100; $sales_tax = round($sales_tax,2); $this->sales_tax = $sales_tax; } public function Tip() { //global $post_values; //$last_tip_selected = $post_values->tip > 0 ? $post_values->tip : "" ; $tip_output = "<select id='tip' name='tip'>"; for($tip=0.00; $tip<=11.75; $tip+=0.25){ if( $tip == "2") {$selected = " selected";} else {$selected ="";} $formatted_tip = money_format('%i',$tip); $tip_output .= "<option {$selected} id='selected_tip' value='$formatted_tip'>"."$".$formatted_tip ."</option>".PHP_EOL; } $tip_output .= "</select>"; return $tip_output; } private function grandTotal(){ $grand_total = round($this->sales_tax+$this->subtotal+$this->tip,2); $grand_total_formatted = money_format('%i',$grand_total); $this->grand_total = $grand_total_formatted; } I'm trying to do a basic form with php which asks for first, last name, and age with validation. I'm having trouble with my validation and the error counter. I want it to redisplay the form with the errors and entered input. My formhandler.php is he Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Form Handler</title> </head> <body> <?php $fName = validateInput($_POST['fName']); $lName = validateInput($_POST['lName']); $age = validateAge($_POST['age']); function displayRequired($fieldName){ echo "The field \"$fieldName\" is required.<br />n"; } function validateInput($fName, $lName){ if ($errorCountInput>0){ echo "Please re-enter the information below.<br />\n"; redisplayForm($firstName, $lastName); } else{ if(empty($fName, $lName)){ displayRequired($fieldName); ++$errorCount; $returnval = ""; } else{ $returnval = trim($fName,$lName); $returnval = stripslashes($returnval); } return($returnval); } } $erorrCount= 0; function validateAge($age){ global $errorCount; if ($errorCount>0){ echo "Please re-enter the information below.<br />\n"; redisplayForm($age); } else{ if(empty($age)){ echo "<p>The age field is required!</p>\n"; ++$errorCount; $returnval = ""; redisplayForm($fName, $lName, $age); } else{ $age = trim($age); $age = stripslashes($age); if(is_numeric($age)){ $age = round($age); if(($age >= 1) && ($age <= 130)){ $agereturnval = $age; } else { echo "<p>The age field must be between 1 and 130.</p>\n"; ++$errorCount; $agereturnval = ""; } }else { echo "<p>The age field must be a number between 1 and 130.</p>\n"; ++$errorCount; $returnval = ""; } } return($returnval); } $errorcount = 0; echo "Hi ".$fName." ".$lName."."."<br />"; echo "You are ".$age." years old. <br />"; echo $_SERVER['SCRIPT_FILENAME']; ?> </body> </html> Any help would be much appreciated. I've looked at this for hours and I just need another set of eyes to pick some things out. Once you get too close to code it gets hard to figure it out. Okay, the following php form is "somewhat" working. .I am not receiving all of the variables to my inbox.
This is the current form that i'm working on.
http://www.rodriguez...cr/schedule.php
The following fields are the ones are not passing through.
The Drop Down Menu: am, pm, the all day
Video
Case Option:
Additional Requests:
Firm Physical Address:
Fax No:
Here is the code
<?php function displayRequired($fieldName) { echo " \".$fieldName\"is required.<br />n"; } function validateInput($data, $fieldName){ global $errorCount; if (empty($data)){ displayRequired($fieldName); ++$errorCount; $retval = ""; } else { $retval = trim($data); $retval = stripslashes($retval); } return ($retval); } $Deposition = validateInput(safe($_POST['deposition']), "Deposition"); $Time = validateInput(safe($_POST['time']), "Time"); $Delivery = validateInput(safe($_POST['delivery']), "Delivery"); $Witness = validateInput(safe($_POST['witness']), "Witness"); $Location = validateInput(safe($_POST['location']), "Location"); $Attorney = validateInput(safe($_POST['attorney']), "Attorney"); $Name = validateInput(safe($_POST['name']), "First Name"); $Firm = validateInput(safe($_POST['firm']), "Firm Name"); $Phone = validateInput(safe($_POST['phone']), "Phone"); $Email = validateInput(safe($_POST['email']), "Email"); if ($errorCount>0){ echo "Please re-enter the information below.<br />\n"; redisplayForm($Deposition, $Time , $Ampm, $Timeday, $Delivery, $Video, $Co1, $Co2, $Witness, $Location, $Additional, $Attorney, $Name, $Firm, $Address, $Phone, $Fax, $Email); } else { $To = "service@rodriguezstudios.com"; $Subject = "The test"; $From = "Schedule a Deposition - Professional Court Reporters"; $Message .= "Deposition Date: " . $Deposition . "\n"; $Message .= "Time: " . $Time . $Ampm. $Timeday . "\n\n"; $Message .= "Transcript Delivery: " . $Delivery . "\n\n\n"; $Message .= "Video: " . $Video . "\n\n\n\n"; $Message .= "Case Option: " . $Co1. "vs: " . $Co2 . "\n\n\n\n\n"; $Message .= "Witness: " . $Witness . "\n\n\n\n\n\n"; $Message .= "Location: " . $Location . "\n\n\n\n\n\n\n"; $Message .= "Additional Requests: " . $Additional. "\n\n\n\n\n\n\n\n"; $Message .= "Attorney Name: " . $Attorney . "\n\n\n\n\n\n\n\n\n"; $Message .= "Your Name: " . $Name . "\n\n\n\n\n\n\n\n\n\n"; $Message .= "Firm Name: " . $Firm. "\n\n\n\n\n\n\n\n\n\n\n"; $Message .= "Firm Physical Address: " . $Address . "\n\n\n\n\n\n\n\n\n\n\n\n"; $Message .= "Phone No: " . $Phone . "\n\n\n\n\n\n\n\n\n\n\n\n\n"; $Message .= "Fax No: " . $Fax. "\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; $Message .= "Email: " . $Email . "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; $Headers = "From: ". $From . "<" . $To. ">\r\n"; $Headers .= "Reply-To: " . $Email . "\r\n"; $Headers .= "Return-path: ". $Email; $result = mail($To, $Subject, $Message, $Headers); if ($result) $resultMsg = "You message was sucessfully sent."; else $resultMsg = "There was a problem sending your message."; /*insert anti spam fragement here */ ?> <p style="line-height:200%; text-align:center; font-family:Verdana, Geneva, sans-serif; color:#000000">Your deposition has been scheduled<?php if(!empty($fieldName)) { echo " , {$fieldName}. {$resultMsg}"; } echo "</p>"; } ?> <?php function redisplayForm($Deposition, $Time , $Ampm, $Timeday, $Delivery, $Video, $Co1, $Co2, $Witness, $Location, $Additional, $Attorney, $Name, $Firm, $Address, $Phone, $Fax, $Email){ ?> <form action="" method="POST"> <fieldset class="first"> <fieldset class="first"> <p> <label class="labelone"for="deposition">*Deposition Date:</label> <input type="text" id="datepicker" name="deposition" value="<?php echo $Deposition; ?>" /> </p> <p> <label for="*Time:" name="time">*Time: </label> <input type="text" name="time" value="<?php echo $Time; ?>"> <select name="ampm" id="Ampm"> <option value="am">A.M.</option> <option value="pm">P.M.</option> </select> <select name="timeday" id="Timeday"> <option value="all">All Day</option> <option value="half">Half Day</option> <option value="hours">1-2 hrs</option> </select> </p> <p> <label for="*Transcript Delivery:" name="transcript"/> *Transcript Delivery:</label> <select> <option value="regular">Regular Delivery (10 day)</option> <option value="same">Same Day</option> <option value="1day">1 Day</option> <option value="2day">2 Day</option> <option value="3day">3 Day</option> <option value="4day">4 Day</option> <option value="5day">5 Day</option> </select> </p> <p> <label for="*Video" name="video">*Video:</label> <select name="video" id="video"> <option value="yes">Yes</option> <option value="no">No</option> </select> </label> </p> <p> <label for ="caseoption">Case Option:</label> <input type="text" name="co1" value="<?php echo $Co1; ?>"/> vs. <input type="text" name="co2" value="<?php echo $Co2; ?>" /> </p> <p> <label for ="witness">*Witness:</label> <input type="text" name="witness" value="<?php echo $Witness; ?>" /> </p> </fieldset> <fieldset> <legend>LOCATION OF DEPOSITION, TELEPHONE NUMBER, AND NAME OF CONTACT PERSON:</legend> <p> <label for="location">*Location:</label> <textarea name="location" id="Location" value="<?php echo $Location; ?>"></textarea> </p> <p> <label for="additional">Addtional Requests (i.e. Realtime):</label> <input type="text" name="additional" value="<?php echo $Additional; ?>" /> </p> <p> <label for ="attorney">*Attorney Name:</label> <input type="text" name="attorney" value="<?php echo $Attorney; ?>" /> <p> <label for ="name">*Your Name:</label> <input type="text" name="name" value="<?php echo $Name; ?>" /> </p> <label for ="firm">*Firm Name:</label> <input type="text" name="firm" value="<?php echo $Firm; ?>" /> </p> <p> <label for ="firmaddress">Firm's Physical Address:</label> <input type="text" name="address" value="<?php echo $Address; ?>" /> </p> <p> <label for ="phone">*Phone No:</label> <input type="text" name="phone" value="<?php echo $Phone; ?>"/> </p> <p> <label for ="fax">Fax No:</label> <input type="text" name="fax" value="<?php echo $Fax; ?>"/> </p> <p> <label for ="email">*Email:</label> <input type="text" name="email" value="<?php echo $Email; ?>" /> </p> </fieldset> <fieldset> <input class="btn" name="submit" type="submit" value="Send Email"/> <input class="btn" name="reset" type="reset" value="Clear Form" /> </fieldset> </form> <?php } ?> <?php function safe($string) { $pattern = "/\r|\n|\%0a|\%0d|Content\-Type:|bcc:|to:|cc:/i"; return preg_replace($pattern, '', $string); } ?>The extra pair of eyes would be greatly appreciated! This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347360.0 Hi all, I have a basic question for anyone that can help me. Ive added a captcha input field to the form below, as Im having problems with spam appearing on my testimonial page. 1) How can I prevent the form from being sent if the wrong or no answer is in the form field. 2) How can i have a message appear saying "Sorry wrong answer" if the from isnt sent for the above reason? add.php Code: [Select] <form method="post" action="process2.php" > <textarea rows="25" cols="100" wrap="physical" name="data"> </textarea> <input type="hidden" name="area" value="testimonial"/> What is 5+5? <input type="text" name="captcha"/> <input type="submit" value="Add "> </form> process2.php Code: [Select] <p class="add">Thankyou for submitting your testimonial;</br> <?php $data="<br><br>" . $_POST["data"]; ?><br /> <?php $area=$_POST["area"]; ?> <?php echo $data; ?></p> <?php mysql_query("UPDATE wheelchairwizard SET data = CONCAT(data, '$data') WHERE area = '$area'"); ?> </br> Return to the testimonial page - <a href="http://www.wheelchairwizard.co.uk/testimonials.php">click here</a> I have a form-to-email that I am trying to use. I'm testing, but I am not getting the orders that I send. Everything else I send to that email I get fine, so something definately wrong with my code somewhere. Thought I was ok (as a beginner) with PHP, but now my ego is taking a beating It is contained all on 1 page - the below coding is the entire page: Code: [Select] <?php if(isset($_POST['t1'])){ // **** CHANGE EMAIL, AFFILIATE ID & AFFILIATE LINK! **** $mymail = 'rjmatthews15@cfl.rr.com'; $cc = 'Website installation (plus124)'; $BoDy = ' '; $FrOm = "From: $_POST[t2]"; $FrOm .= "\r\nReply-To: $_POST[t2]"; $FrOm .= "\r\nX-MAILER: PHP".phpversion(); //Body sends all the sign up info to the $mymail address $BoDy .= 'Website Chosen: '; $BoDy .= $_POST['t1']; $BoDy .= "\n"; $BoDy .= 'eMail Address: '; $BoDy .= $_POST['t2']; $BoDy .= "\n"; $BoDy .= 'Confirm eMail: '; $BoDy .= $_POST['t3']; $BoDy .= "\n"; $BoDy .= 'Hosting Info: '; $BoDy .= $_POST['t4']; $BoDy .= "\n"; $BoDy .= 'Hosting Password: '; $BoDy .= $_POST['t5']; $BoDy .= "\n"; $BoDy .= 'Sign Up Method: '; $BoDy .= $_POST['t6']; $BoDy .= "\n"; $send = mail("$mymail", "$cc", "$BoDy", "$FrOm"); ///Redirect user to your homepage.... if($send) { echo '<html><head>'; echo '<meta http-equiv="refresh" content="0;URL=http://www.affiliscripts.com/124-thanks.php">'; echo '</head><body>Email send....'; echo '</body></html>'; } }else{ ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <link href="style.css" rel="stylesheet" type="text/css" /> <link href="layout.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="jquery.js"></script> <script> function toggle1(id){ if(id == 1){$('#method1').slideDown('slow'); $('#method2').slideUp('slow'); } if(id == 2){$('#method2').slideDown('slow'); $('#method1').slideUp('slow'); } } </script> </head> **** ALL BODY COING HERE <?php include 'footer.php'; ?> <?php } ?> If anyone can see what I am doing wrong, I would LOVE it if you could let me know. I am sure it's something stupid... but I've looked at this coding for 2 days now and can't find a thing! Thanks, Rob G'day All, Firstly i appologise if this a simple question but I am new to PHP (litterally 2 days), I just have a basic structure question. I have implemented a php script to solve a problem (irrelevant) and have made a form to enter the required data and written validation code and then processing code to produce the results. Currently my validation and processing code is in a seperate file 'process.php' which at this point just echos the results, the form is in 'form.php' and posts the data to 'process.php'. What I want to do is direct the user to a results page after processing (maybe this will be the page with the processing code? dont know if i can post results to another page) and back to form.php if it fails validation with the correct entries still entered and an appropraite error message. I have searched extensively and cant seem to find a standard or really even any relavant way of doing this. All I am considering is combing it all into one file and having a 'display form' function and a 'display results' function but this doesnt seem like very good or modulated coding. Any help would be grealy appreciated. Unable to submit choosing a file. This feature should be optional, Please assist. Thank you. php code ========= <?php $page = 'contact'; require "header.php"; ?> <?php $statusMsg=''; if(isset($_FILES["file"]["name"])){ $email = $_POST['email']; $fname = $_POST['fname']; $lname = $_POST['lname']; $phone = $_POST['phone']; $company = $_POST['company']; $option = $_POST['option']; $message = $_POST['message']; if(!empty($_POST['check_list'])) { $checks = array(); foreach($_POST['check_list'] as $check) { $checks[] = $check; } $check = implode('</br>•', $checks); } $fromemail = $email; $subject="MyGeo - Contact Us"; $email_message = '<h2>User Information</h2> <p><b>First Name:</b> '.$fname.'</p> <p><b>Last Name:</b> '.$lname.'</p> <p><b>Email:</b> '.$email.'</p> <p><b>Phone:</b> '.$phone.'</p> <p><b>Company:</b> '.$company.'</p> <p><b>Please choose a category :</b> '.$option.'</p> <p><b>Your message to MyGeo :</b> '.$message.'</p>'; $email_message.="Please find the attachment"; $semi_rand = md5(uniqid(time())); $headers = "From: ".$fromemail; $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; if($_FILES["file"]["name"]!= ""){ $strFilesName = $_FILES["file"]["name"]; $strContent = chunk_split(base64_encode(file_get_contents($_FILES["file"]["tmp_name"]))); $email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message .= "\n\n"; $email_message .= "--{$mime_boundary}\n" . "Content-Type: application/octet-stream;\n" . " name=\"{$strFilesName}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $strContent .= "\n\n" . "--{$mime_boundary}--\n"; } $toemail="jasmin.ambrose@mygeo.my"; if(mail($toemail, $subject, $email_message, $headers)){ $statusMsg= "Submission succesful, thank you for contacting MyGeo"; }else{ $statusMsg= "SUBMISSION FAILED, please submit again later, thank you"; } } ?> <!-- Display submission status --> <?php if(!empty($statusMsg)){ ?> <h1 class="container jumbotron text-uppercase text-center mx-auto" style=" font-size: 25px; color: green;"><?php echo $statusMsg; ?></h1> <?php } ?> <!-- Sectio-one --> <div class="col-md-12 square"> <h3 class="font-weight-bold"></h3> <h4 class="font-weight-bold">MyGeo Sdn. Bhd. (1367062-K)</h4> <h5>Level 2, Suite IIC Resource Centre, Technology Park Malaysia, Bukit Jalil, 57000 Kuala Lumpur, MALAYSIA</h5> <i class="fa fa-envelope-o" aria-hidden="true"></i> contactus@mygeo.my <i class="fa fa-phone" aria-hidden="true"></i> +6012 345 3263 </div> <div class="section-service py-5 my-1"> <div class="container"> <div class="row p-1"> <div class="col-xs-6"> <h1>HOW CAN WE HELP YOU</h1> </div> </div> <div class="row p-1"> <div class="col-md-12"> <p id="sep">Contact us below with new project requests, feedback and general questions</p> <form method="post" action="" enctype="multipart/form-data"> <div class="form-row"> <div class="form-group col-md-6"> <label class="font-weight-bold" for="fname">First Name</label> <input name="fname" type="text" class="form-control" placeholder="First name" required> </div> <div class="form-group col-md-6"> <label class="font-weight-bold" for="lname">Last Name</label> <input name="lname" type="text" class="form-control" placeholder="Last name" > </div> </div> <div class="form-row"> <div class="form-group col-md-6"> <label class="font-weight-bold" for="inputEmail4">Email</label> <input name="email" type="email" class="form-control" id="inputEmail4" placeholder="Email" required> </div> <div class="form-group col-md-6"> <label class="font-weight-bold" for="Phone">Phone</label> <input name="phone" type="tel" class="form-control" id="phone" placeholder="Enter phone number" required> </div> </div> <div class="form-row"> <div class="form-group col-md-6"> <label class="font-weight-bold" for="company">Company</label> <input name="company" type="text" class="form-control" placeholder="Company" > </div> </div> <div class="form-row"> <div class="form-group"> <label class="font-weight-bold" for="input" required>Please choose a category :</label> <div class="form-check"> <input class="form-check-input" <?php if (isset($option) && $option=="General Questions") echo "checked";?> value="General Questions" type="radio" name="option" id="exampleRadios1" checked> <label class="form-check-label" for="exampleRadios1"> General Questions </label> </div> <div class="form-check"> <input class="form-check-input" <?php if (isset($option) && $option=="New Project Request") echo "checked";?> value="New Project Request" type="radio" name="option" id="exampleRadios1" checked> <label class="form-check-label" for="exampleRadios1"> New Project Request </label> </div> <div class="form-check"> <input class="form-check-input" <?php if (isset($option) && $option=="Feedback") echo "checked";?> value="Feedback" type="radio" name="option" id="exampleRadios1" checked> <label class="form-check-label" for="exampleRadios1"> Feedback </label> </div> </div> </div> <div class="form-group"> <label class="font-weight-bold" for="Textarea1">Your message to MyGeo</label> <textarea class="form-control" id="FormTextarea1" rows="3" name="message" required></textarea> <small id="emailHelp" class="form-text text-muted">0 of 4000 max charaacters</small> </div> <p></p> <p></p> <div class="form-group"> <label class="font-weight-bold" for="File1"></label> <input type="file" name="file" class="form-control-file" id="exampleFormControlFile1" required =""> </div> <button type="submit" class="btn btn-success" name="submit">Submit</button> </form> </div> </div> </div> </div> <?php require "footer.php"; ?>
footer.php ======= <!-- Footer --> <section id="footer"> <div class="container text-center"> <div class="row social"> <div class="col-xs-12 col-sm-12 col-md-12 mt-2 mt-sm-2"> <ul> <li class="list-inline-item"> <a href="#"><i class="fa fa-linkedin"></i></a></li> <li class="list-inline-item"> <a href="#"><i class="fa fa-twitter"></i></a></li> <li class="list-inline-item"> <a href="https://www.facebook.com/MyGeo-100967235334783"><i class="fa fa-facebook"></i></a></li> </ul> </div> </div> <div class="row"> <div class="col-xs-12 col-md-12 mt-2 mt-sm-2 text center text-white"> <p>© All Rights Reserved (2020)<a href="#"> MyGeo</a> Sdn. Bhd. (1367062-K)</p> <p>Level 2 Suite IIC Resource Centre Technology Park Malaysia, Bukit Jalil, 57000 Kuala Lumpur, MALAYSIA.</p> </div> </div> </div> </section> <script> function myFunction() { var input, filter, ul, li, a, i; input = document.getElementById("mySearch"); filter = input.value.toUpperCase(); ul = document.getElementById("myMenu"); li = ul.getElementsByTagName("li"); for (i = 0; i < li.length; i++) { a = li.getElementsByTagName("a")[0]; if (a.innerHTML.toUpperCase().indexOf(filter) > -1) { li.style.display = ""; } else { li.style.display = "none"; } } } </script> <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script> </body> </html>
header.php ======== <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>My GEO</title> <link rel="shortcut icon" type="image/png" href="images/mygeo logo2.png"> <link rel="stylesheet" href="./css/style.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous"> <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous"> </head> <body> <!-- Simple Responsive Navbar --> <nav class="navbar navbar-expand-xl text-success font-weight-600 pt-2"> <div class="container"> <a class="navbar-brand" href="index.php"><img style="width: 15vh;" src="images/mygeo logo2.png"></a> <button class="navbar-toggler navbar-light" data-toggle="collapse" data-target="#Nav"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="Nav"> <ul class="navbar-nav" id="myMenu"> <li class="nav-item <?php if($page=='about'){echo 'active';}?>"> <a class="nav-link" href="about.php">ABOUT US</a> </li> <li class="nav-item <?php if($page=='services'){echo 'active';}?>"> <a class="nav-link" href="services.php">SERVICES</a> </li> <li class="nav-item <?php if($page=='projects'){echo 'active';}?>"> <a class="nav-link" href="projects.php">PROJECTS</a> </li> <li class="nav-item <?php if($page=='people'){echo 'active';}?>"> <a class="nav-link" href="people.php">MYGEO PEOPLE</a> </li> <li class="nav-item dropdown <?php if($page=='careers'){echo 'active';}?>"> <a class="nav-link dropdown-toggle " data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">CAREERS</a> <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink"> <a class="dropdown-item" href="career-a.php">TELL US ABOUT YOURSELF</a> <a class="dropdown-item" href="career-b.php">JOB OPENINGS</a> </div> </li> <li class="nav-item <?php if($page=='blog'){echo 'active';}?>"> <a class="nav-link" href="https://mygeomalaysia.wordpress.com/">BLOG</a> </li> <li class="nav-item <?php if($page=='webmail'){echo 'active';}?>"> <a class="nav-link" target="_blank" href="https://mygeo.my/webmail">WEBMAIL</a> </li> <li class="nav-item <?php if($page=='contact'){echo 'active';}?>"> <a class="nav-link" href="contact-a.php">CONTACT US</a> </li> </ul> </div> </div> </nav>
Edited April 19 by requinix please use the Code <> button when posting code Gday, I'm trying to add a contact form on my site using a PHP script I downloaded from the web. I have tweaked the script, but I have never used PHP before and haven't got the time to learn it yet. Could someone please help me to get this working, I have added a subject drop down field that I would like to add validation to force the user to choose one, and I'd like the subject they choose to appear in the subject field of the resulting email. Once the PHP script has run and the email has been sent I'd like the text at the bottom to appear on the original page. At the moment when i click submit it just goes to the php page and shows three lines of the error message text. Here is the relevant code: This form is placed within a static html page: Code: [Select] <form name="contactform" method="post" action="send_form_email.php" style="text-align:left;"> <label for="first_name">First name <span class="red">*</span></label> <input name="first_name" type="text" value="please enter your first name" size="30" maxlength="75" onclick="document.contactform.first_name.value='';" /> <br/> <label for="last_name">Last name <span class="red">*</span></label> <input name="last_name" type="text" value="please enter your last name" size="30" maxlength="75" onclick="document.contactform.last_name.value='';" /> <br/> <label for="email" style="margin-right:32px;">Email <span class="red">*</span></label> <input name="email" type="text" value="please enter your email address" size="30" maxlength="75" onclick="document.contactform.email.value='';" /> <br/> <label for="phone_number" style="margin-right:34px;">Phone</label> <input name="phone_number" type="text" value="please enter your phone number" size="30" maxlength="75" onclick="document.contactform.phone_number.value='';" /> <br/> <label for="email_subject" style="margin-right:19px;">Subject <span class="red">*</span></label> <select name="email_subject" style="margin-bottom:10px;"> <option value="Choose one">Choose one</option> <option value="Lost my password">Lost my password</option> <option value="Gardening advice">Gardening advice</option> <option value="Order status">Order status</option> <option value="Web feedback">Web feedback</option> <option value="Customer Service">Customer Service</option> <option value="Product feedback">Product feedback</option> <option value="Other">Other</option> </select> <br/> <label for="comments">Queries/Comments <span class="red">*</span></label> <textarea rows="10" cols="50" wrap="virtual" name="comments" onclick="document.contactform.comments.value='';" style="margin-bottom:5px;">Please type your query or comments here</textarea> <input type="submit" value="Submit" /> </form> and here is the seperate php script that is used: <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "johnc@diggers.com.au"; $email_subject = $_REQUEST['email_subject']; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['email_subject']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $telephone = $_POST['email_subject']; // required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!eregi($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } $string_exp = "^[0-9 .-]+$"; if(!eregi($string_exp,$telephone)) { $error_message .= 'The Telephone Number you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting us. We will be in touch within 72 hours of the next working day. <? } ?> Any help on how to get this going would be greatly appreciated, thanks Hi. Can someone show me the proper way to do a feedback form (like a "Contact US" form). I have read about SQL injections and would like to know I am protecting against it. And the proper way to store the submitted data in a database for a client's records. I have a basic form I use, but I am unable to store the data properly. Any help or a code idea would be appreciated. Thanks much. Hey guys, New to the forum and a newer user of PHP / MySQL. I am having trouble with some code I've written up. I don't seem to get any errors when running it, but it's not updating my database the way that it should. hopefully a simple fix. I am thinking that it must be on the MySQL side of things. Couple of things to start. My html form is comprised completely of drop down list inputs. I'm the only user so I thought this would be the easiest approach. Because of that I've made my PHP as follows: Code: [Select] <?php $season = $_POST['season']; $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $time = $_POST['time']; $event = $_POST['event']; $game = $_POST['game']; $buyin = $_POST['buyin']; $connect = mysql_connect('localhost','root','') or die('can not connect'); if ($connect) { echo "connected to database"; } $db = mysql_select_db('dpl') or die('can not find database'); if ($db) { echo "DPL Selected"; } $query = sprintf("INSERT INTO events (season , month , day , year , time , event , game , buyin) VALUES ('%s' , '%s' , '%s' , '%s' , '%s' , '%s' , '%s' , '%s')", $season , $month , $day , $year , $time , $event , $game , $buyin ); if ($query) { echo "Your event has been added"; } ?> My connection is working, my database is selected and I'm even now getting confirmation that my query is working, but when i go to check my database there are no entries in it? any thoughts? I've tried the drop down variables as both VARCHAR and TEXT inputs in MySQL, but I can't seem to get it to work. Any help is greatly appreciated. Hello, I'm trying to take the value from an HTML form and insert it into a database on a button click. It inserts a null value into the database. The script is called submitColumnDetails.php. This is where I create the text field that I want to take the information from. This is in a separate file. Code: [Select] echo <<<END <form action = "submitColumnDetails.php" method = "POST"> <input type = "text" name = "columnField"/> </form> END; This is the submitColumnDetails.php file Code: [Select] <?php //Submit Column Data //-----------------------------------------------------// //Connect to localhost server $connector = mysql_connect("localhost", "root", "root"); if(!$connector){ //If user can't connect to database die('Could not connect: ' . mysql_error()); //Throw an error } //-----------------------------------------------------// mysql_select_db("colin_db", $connector); $newValue = $_POST["columnField"]; //Data from column field. THIS IS WHAT RETURNS NULL $newColumnQuery = "INSERT INTO `colin_db`.`allColumnFields` (`DATA`) VALUES ('$newValue')"; mysql_query($newColumnQuery); //Query to add form to main table $newColumnIntoMainTableQuery = "ALTER TABLE colin_table ADD ('$newValue' varchar(50))"; mysql_query($newColumnIntoMainTableQuery); //Query to add column to main table mysql_close($connector); //Close database connection echo "<script type = 'text/javascript'> window.location = 'index.php'</script>"; //Go back to original page ?> Even when I print out the $newValue, it does not print anything. What am I doing incorrectly? Basically this is a pretty straight forward application. The values are all best on a set of conditional statements held in a function and when the user presses submit, it SHOULD calculate the form....However, this is not the case, for some reason it keeps returning 0. I have tried and tried and tried....to no avail. I have attached the files so you can sort through a little easier as there are a good amount of lines. Thanks! [attachment deleted by admin] In my invoice system im trying to carry information from 1 page to another, witch i have been successful with, now I am trying to alter table rows on my data tables I need to send the same account number and invoice number, how can i achieve this without putting the account number and invoice number inside a form element? Ok so I've got trouble with a form I'm creating, I've got this: <form id="login" name="login" action="URL" method="post"> and then Input fields like: <input tabindex="3" type="text" class="login-field" name="acc.username" id="login-username" value="" maxlength="48"/> Now, if I go and submit that, and on the "URL" page I've had it echo $_POST['acc.username'] but it doesn't echo anything. I think it may be a problem with the form itself.. although I can't see one. The code I got for URL: <?PHP include('global.php'); if(isset($_POST['acc.username'])) { echo "lol"; } else { echo mysql_error(); } ?> How can i make a send POST FORM from this api: http://pub.tapulous.com/tapplications/coresocial/v1/chat/api/index.php?method=message_send&session={"device_id":+"03decef7aad6fb64fb5c5ed3f1d35a3d16413e490a2874",+"room":+"Songs%253AExtreme"}&message= message here Thanks people |