PHP - Sticky Form Functions For Text Fields/areas
Assist a newbie!
Similar TutorialsHi Guys, I am attempting to create a program for a local auction house. I arrived at a stand still on a certain issue which is creating a sticky form. On the "enter auction details page" the user will be entering data as the auction is in session. 1. item Description 2. Item Price 3. Bidders Id 4. Qty Of course it would be repetitive to require the user to keep entering the same data for every bidder, so I want to stick the obvious fields which are "item description" & "Item Price" as these don't change until a new item comes up for sale. As of know I am processing the input on a separate page which records all input to the database with a redirect back to the "enter auction details page". I have tried many times to get the item description and item price fields to stick. These would need to change as the user moves onto the next item in which the description and price would change as well. Here is my current code for this part: Code: [Select] <?php session_start(); $field_itemDescription = ""; //iyem description, default as blank if (isset($_SESSION['itemDescription'])) $itemDescription = $_SESSION['itemDescription']; ?> <form action="record_trans.php" method="post"> <font face= "calibri" size= "4"> <table> <tr> <td><b>Item Description:</b></td> <td><input type= "text" name= "itemDescription" size= "30" value="<?php echo $itemDescription;?>"></td> </tr> <tr> <td><b>Item Price:</b></td> <td><input type= "text" name= "itemPrice" size= "5" value="<?php echo $itemPrice;?>"> </td> </tr> </tr> <td><b>Winning Bidders:</b></td> <td><input type="text" name= "bidderId" size= "5" /> </td> </tr> <tr> <td><b>How many deals?:</b></td> <td><input type="text" name= "itemQty" size= "3" value= "1" /></td> </tr> </table> <center><input type="submit" name="submit" value= "Save & Cont." " /></center> </form></font> Hello all. I'm new here... and new to php... so please be gentle if I'm overlooking something that's blindingly obvious. I have a 'view blog entries' page and an 'edit blog entries' page. When I go to the 'edit blog entries' page, I want the form fields to display the preexisting blog content for whatever entry I'm about to edit. The code below does display the 'title' but it does not display the 'article' content. (However, the 'title' and 'article' content both show when I view the source code.) Can anyone tell me what I could be doing wrong? Thanks in advance. Code: [Select] // Retrieve the blog post's information: $q = "SELECT title, article FROM entries WHERE article_id=$article_id"; $r = @mysqli_query ($dbc, $q); if (mysqli_num_rows($r) == 1) { // Valid blog entry ID, show the form. // Get the blog entry's information: $row = mysqli_fetch_array ($r, MYSQLI_NUM); echo '<form action="edit_entry.php" method="post"> <p>Title:<br /> <input type="text" name="title" size="45" maxlength="80" value="' . $row[0] . '" /></p> <p>Blog entry<br /> <textarea name="article" id="article" cols="45" rows="5" ' . $row[1] . '></textarea> </p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="article_id" value="' . $article_id . '" /> </form>'; } else { // Not a valid entry ID. echo '<p class="error">This page has been accessed in error.</p>'; } mysqli_close($dbc); ?> Here goes.
I am trying to retrieve info. from mySql database and update 3 textfields.
I also have 4 selects on the form that need populating during the running of the program. My problem is using console I can see the info - Customer name - but it does not appear in the text field. The onchange request in the DIV container seems to be where it fails. Here are the files I am using:
1. add_an_order.php
<html> <head> <title>Add an Order</title> <link href = "css/style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="include/jquery-1.11.1.min.js"></script> </head> <body> <div id="header"><img src="images/logo.png" /></div> <div id="nav"> <div id="nav_wrapper"> <ul> <li><a href="index.php">Orders</a></li><li> <a href="customers.php">Customers</a></li><li> <a href="contacts.php">Contacts</a></li><li> <a href="batteries.php">Batteries</a></li><li> <a href="#">Queries</a> </li> </ul> </div> </div> <div id="main"> <?php echo '<h3 id="menOpt">Add an Order</h3><hr>'; // Check for a form submission. /* if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); $required_fields = array('customer_name', 'customer_address', 'city', 'telephone'); foreach ($required_fields as $fieldname) { if (!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) { $errors[] = strtoupper($fieldname); } } if (empty($errors)) { include ('include/dbconnect.php'); $name = mysqli_real_escape_string($con, trim(strip_tags($_POST['customer_name']))); $contact = mysqli_real_escape_string($con, trim(strip_tags($_POST['contact']))); $address = mysqli_real_escape_string($con, trim(strip_tags($_POST['customer_address']))); $city = mysqli_real_escape_string($con, trim(strip_tags($_POST['city']))); $telephone = mysqli_real_escape_string($con, trim(strip_tags($_POST['telephone']))); $telephone = preg_replace('/[^0-9]/', '', $telephone); if (isset($_POST['deepc'])) { $deepc = 1; } else { $deepc = 0; } if (isset($_POST['problemc'])) { $problemc = 1; } else { $problemc = 0; } $problem = mysqli_real_escape_string($con, trim(strip_tags($_POST['problem']))); if (isset($_POST['blacklist'])) { $blacklist = 1; } else { $blacklist = 0; } if (isset($_POST['pickup'])) { $pickup = 1; } else { $pickup = 0; } $query = "INSERT INTO customers ( customer_name, contact, customer_address, city, telephone, deep_cycle, problem_customer, problem, blacklist, pickup) VALUES ('$name', '$contact', '$address', '$city', '$telephone', $deepc, $problemc, '$problem', $blacklist, $pickup)"; $r = mysqli_query($con, $query); if (mysqli_affected_rows($con) == 1) { echo '<p class="success">Customer has been successfully added.</p>'; } else { $message = "Could not add customer."; $message .= "<br />" . mysqli_error($con); } mysqli_close($con); } else { // We have errors. $message = count($errors) . " error(s) on the form."; } } // End: if ($_SERVER['REQUEST_METHOD'] == 'POST'). */ // Leave PHP and display the form. ?> <?php if (!empty($message)) { echo '<p class="error">' . $message . '</p>'; } ?> <?php // Output list of fields that have errors. if (!empty($errors)) { echo '<p class="error">'; foreach ($errors as $error) { echo $error . '<br />'; } echo '</p>'; } ?> <div class="container"> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset> <label>Business: <span class="important"> *</span><select name="customer_name" id="customer_name" onchange="request_fill(this.value)" value="<?php if (isset($_POST['customer_name'])) echo $_POST['customer_name']; ?>" ></select></label> <label>Address: <input type="text" name="address" id="add_a" value="<?php if (isset($_POST['customer_address'])) echo $_POST['customer_address']; ?>" /></label> <label>City: <input type="text" name="city" id="city" value="<?php if (isset($_POST['city'])) echo $_POST['city']; ?>" /></label> <label>Phone: <input type="text" name="telephone" value="<?php if (isset($_POST['telephone'])) echo $_POST['telephone']; ?>" /></label> <label>Manufacturer: <span class="important"> *</span><select name="manufacturer" id="manufacturer" onchange="request_mod(this.value)" value="<?php if (isset($_POST['manufacturer'])) echo $_POST['manufacturer']; ?>" ></select></label> <label>Model: <span class="important"> *</span><select name="model" id="model" onchange="form_yr(this.value)" value="<?php if (isset($_POST['model'])) echo $_POST['model']; ?>" ></select></label> <label>Year: <span class="important"> *</span><select name="battery" id="bat_disp" value="<?php if (isset($_POST['battery'])) echo $_POST['year'] ?>" ></select></label> <label>Quantity: <span class="important"> *</span><input type="text" name="quantity" id="quantity" value="<?php if (isset($_POST['quantity'])) echo $_POST['quantity']; ?>" /></label> <label>Warranty ? <input type="checkbox" name="warranty" <?php if ($_POST['warranty']) echo " checked"; ?> /></label> <label>Exchange ? <input type="checkbox" name="exchange" <?php if ($_POST['exchange']) echo " checked"; ?> /></label> <input type="submit" name="submit" value="Add Order" /> or <a href="index.php">Cancel</a> </fieldset> </form> </div> <script type="text/javascript" src="include/functions.js"></script> <script> $(document).ready(function() { $('.container').hide(); $('.container').fadeIn(1000); request_cust(); request_man(); }); </script> <?php include ('include/footer.php'); 2. request_fill function request_fill() { var cust2 = 'customer'; var ad = document.getElementById("add_a"); var hr = new XMLHttpRequest(); hr.open("POST", "battery_parser.php", true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function() { if(hr.readyState == 4 && hr.status == 200) { var dataArray = hr.responseText; ad.innerHTML = dataArray[1]; } } hr.send("&cust2="+cust2); } 3. battery_parser.php <?php include_once("include/dbconnect.php"); if (isset($_POST['cust2'])) { $cust2 = $_POST['cust2']; $sql = "SELECT customer_address FROM customers WHERE customer_id = 2"; $query = mysqli_query($con, $sql); $dataString = ''; while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ $add = $row["customer_address"]; $dataString = $add; } mysqli_close($con); echo $dataString; exit(); } else { exit(); } ?> Hi there, I got some good advice from Harristweed the other day about how to export from Mysql to excel, so that each field appears in a different column in excel. I expanded the code Harristweed gave me to cover all fields in my database, and all went well until the 2nd last field, when I hit a brick wall. Unlike previous fields, which were based on info inputted via radio buttons, dropdown lists, or text boxes, the field causing problems was based on data that came from a text area on the web form. A few tests revealed that the problem was related to when a user pressed the "Enter" key while filling in that field, to begin a new paragraph. When this happens, it would go into the database fine. However, when I used the code to export it to excel, anything after the "Enter" key had been pressed would appear in a new cell on a new row, thereby putting the table out of alignment. I could get around this by rewording the question into a few questions which each use a text box rather than a text area box. However, if there is a way to get around this by tweaking the php code, I'd love to know. The field with which I'm having the problem is the one called "experience". Thanks for your time, Dave <?PHP $db = mysql_connect("localhost", "MYUSERNAME", "MYPASSWORD"); mysql_select_db("MYDATABASE",$db); $query="SELECT * FROM applications2010"; $result=mysql_query($query); $header=" date\t firstname\t lastname\t sex\t dobday\t dobmonth\t dobyear\t streetaddress\t suburb\t state\t postcode\t country\t preferredphone\t secondphone\t thirdphone\t emailaddress\t emconname\t emconphone\t experience\t "; while($row = mysql_fetch_assoc($result)) { if(empty($row[date]))$row[date]=" "; if(empty($row[firstname]))$row[firstname]=" "; if(empty($row[lastname]))$row[lastname]=" "; if(empty($row[sex]))$row[sex]=" "; if(empty($row[dobday]))$row[dobday]=" "; if(empty($row[dobmonth]))$row[dobmonth]=" "; if(empty($row[dobyear]))$row[dobyear]=" "; if(empty($row[streetaddress]))$row[streetaddress]=" "; if(empty($row[suburb]))$row[suburb]=" "; if(empty($row[state]))$row[state]=" "; if(empty($row[postcode]))$row[postcode]=" "; if(empty($row[country]))$row[country]=" "; if(empty($row[preferredphone]))$row[preferredphone]=" "; if(empty($row[secondphone]))$row[secondphone]=" "; if(empty($row[thirdphone]))$row[thirdphone]=" "; if(empty($row[emailaddress]))$row[emailaddress]=" "; if(empty($row[emconname]))$row[emconname]=" "; if(empty($row[emconphone]))$row[emconphone]=" "; if(empty($row[experience]))$row[experience]=" "; $line = ''; $line .= "$row[date]\t $row[firstname]\t $row[lastname]\t $row[sex]\t $row[dobday]\t $row[dobmonth]\t $row[dobyear]\t $row[streetaddress]\t $row[suburb]\t $row[state]\t $row[postcode]\t $row[country]\t $row[preferredphone]\t $row[secondphone]\t $row[thirdphone]\t $row[emailaddress]\t $row[emconname]\t $row[emconphone]\t $row[experience]\t "; $data .= trim($line)."\n"; } $data = str_replace("\r","",$data); if ($data == "") { $data = "\n(0) Records Found!\n"; } header("Content-type: application/x-msdownload"); header("Content-Disposition: attachment; filename=filename=".date("d-m-Y")."-export.xls"); header("Pragma: no-cache"); header("Expires: 0"); print "$header\n$data";exit; ?> I apologize in advance, I know pretty much nothing about PHP - don't hate me, please! But I'm working on a form mailer, and it functions, but what I don't like is it leaves all the text fields, blank or not, in my email, which makes it difficult for my client to read, so theres a long list of txt field1: another text field: blah blah: all the way down the email - and I want it gone! haha. I've researched how to do this, but basically, I have no idea how to implement it into my code and don't have time right now to up and learn PHP. My code is as follows: Code: [Select] <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'PCI Tour/Excursion Request'; // Your email address. This is where the form information will be sent. $emailadd = 'MY EMAIL HERE'; // Where to redirect after form is processed. $url = 'FORWARDING URL'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // --------------------------Do not edit below this line-------------------------- $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 20) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 20 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> IT was a very simple copy-paste form, but I have no idea what on earth I'm doing. If anyone has any ideas I would GREATLY appriciate the help! Thanks! -Austin Hello All: Trying to work with PHP on a contact form with a jQuery Validation to make certain that the visitors fill out the required information. I'll try to show everything that I have, and then the error I am getting when the visitor hits "submit." I don't know PHP all that well, and trying to learn my way through it. I used a couple of tutorials to add the features I needed and did my own styling on the live site. Here is the PHP that is currently in the header of my markup: <?php //If the form is submitted if(isset($_POST['submit'])) { //Check to make sure that the First name field is not empty if(trim($_POST['firstname']) == '') { $hasError = true; } else { $firstname = trim($_POST['firstname']); } //Check to make sure that the Last name field is not empty if(trim($_POST['lastname']) == '') { $hasError = true; } else { $lastname = trim($_POST['lastname']); } //Check to make sure that the Street Address 01 field is not empty if(trim($_POST['street01']) == '') { $hasError = true; } else { $street01 = trim($_POST['street01']); } //If Street02 is filled out, give it a value $street02 = $_POST['street02']; //Check to make sure that the City field is not empty if(trim($_POST['city']) == '') { $hasError = true; } else { $city = trim($_POST['city']); } //Check to make sure that the State field is not empty if(trim($_POST['state']) == '') { $hasError = true; } else { $state = trim($_POST['state']); } //Check to make sure that the Zip field is not empty if(trim($_POST['zip']) == '') { $hasError = true; } else { $zip = trim($_POST['zip']); } //If Email is filled out, give it a value $email = $_POST['email']; //If Telephone is filled out, give it a value $telephone = $_POST['telephone']; //Default Subject Value $subject = "VMC Inquiry"; //Check checkboxes foreach($_POST['check'] as $value) { $check_msg = "Checked: $value\n"; } //If Message is filled out, give it a value $comment = $_POST['comment']; //If there is no error, send the email if(!isset($hasError)) { $emailTo = 'xxxx.xxxx@gmail.com'; //Put your own email address here $body = "Name: $firstname $lastname \n\nStreet Address: $street01 \n\nStreet Address*: $street02 \n\nCity: $city \n\nState: $state \n\nZip: $zip \n\nEmail*: $email \n\nTelephone*: $telephone \n\nCheck Box: $check_msg \n\nMessage:\n $comment"; $headers = 'From: XXXXX <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ?> So basically I am using classes to say whether or not something is required, which ties into the jQuery validation. If it isn't required, whatever the visitor types into the box is put into something like "$telephone" which is then printed in the e-mail. The markup for the forms in the body is the following: Code: [Select] <p class="contact-text-right">For more information, or to have a list of our properties mailed to you, please fill out the form below.</p> <div id="contact-wrapper"> <?php if(isset($hasError)) { //If errors are found ?> <p class="error">Please check if you've filled all the fields with valid information. Thank you.</p> <?php } ?> <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?> <p class="accept"><strong><?php echo $firstname;?>,Your Email Successfully Sent!</strong></p> <?php } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform"> <div id="names"> <label for="firstname"><strong>First Name:</strong></label> <input type="text" name="firstname" id="firstname" value="" class="required" /> <label for="lastname"><strong>Last Name:</strong></label> <input type="text" name="lastname" id="lastname" value="" class="required" /> </div> <div id="address01"> <label for="street01"><strong>Street Address:</strong></label> <input type="text" name="street01" id="street01" value="" class="required" /> </div> <div id="address02"> <label for="street02"><strong>Street Address*:</strong></label> <input type="text" name="street02" id="street02" value="" /> </div> <div id="city"> <label for="city"><strong>City:</strong></label> <input type="text" name="city" id="city" value="" class="required city" /> <label for="state"><strong>State:</strong></label> <input type="text" name="state" id="state" value="" class="required state" /> <label for="zip"><strong>Zip Code:</strong></label> <input type="text" name="zip" id="zip" value="" class="required zip" /> </div> <div id="email"> <label for="email"><strong>E-mail*:</strong></label> <input type="text" name="email" id="email" value="" class="email"/> <label for="telephone"><strong>Telephone*:</strong></label> <input type="text" name="telephone" id="telephone" value="" class="telephone" /> <p class="bottom">*Optional fields.</p> </div> <div class="checkbox"> <p><input type="checkbox" name="check[]" value="properties">XXX</p> <p><input type="checkbox" name="check[]" value="contact-regarding">XXXX</p> <p class="indent">(Please list properties or ask specific questions in the space below.)</p> </div> <div id="comment"> <label for="comment"></label> <textarea name="comment" id="comment" ></textarea> </div> <div id="button"> <input type="submit" value="Send Message" name="submit" /> </div> </form> All seems well until I hit submit on the live site. I think get this error returned to me: Warning: Invalid argument supplied for foreach() in ......./html/development/contact.php on line 64 The e-mail goes through, with all the information, no problems! I just can't get this error message to go away. Line 64 of contact.php is where the checkbox coding is: //Check checkboxes foreach($_POST['check'] as $value) { $check_msg = "Checked: $value\n"; } I know I've submitted a lot of code here, and tried to narrow you down to the exact spot I think the problem is, but hopefully some of you PHP gurus can pick out the flaw in a heartbeat. I really appreciate all the help. B I want a Text Area on my form where I can enter the body of an article. It should be sticky so the input is not lost if there are form issues and the form has to be re-loaded. The problem is that when I type "mmm" into this field, after I click "Submit" my form is reloaded - because I didn't complete it - and several blank lines appear before and after the text "mmm"?! Here is my code... Code: [Select] <!-- Body --> <li> <label for="body"><span class="required">*</span>Body:</label> <textarea id="body" name="body" class="text" cols="20" rows="5" wrap="soft"> <?php if(isset($body)){echo htmlentities($body, ENT_QUOTES);} ?> </textarea> <?php if (!empty($errors['body'])){ echo '<span class="error">' . $errors['body'] . '</span>'; } ?> </li> What seems to be the problem?! Debbie Hi, I'm trying to make a form sticky but when I display it on the web I get a blank page. I'm following the example given in my PHP book I'm wondering if there 's an error in the book because it has 2 opening form tags which I didn't think was right. 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>Untitled Document</title> </head> <body> <?php $errors=array(); if(isset($_POST['submit'])){ validate_input(); //checks for empty fields if(count($errors) !=0){ display_form(); } else { display_form(); } } function validate_input(){ global $errors; if($_POST["name"] == ""){ $errors['name']="<font color='red'> please enter your name </font>"; } } function display_form(){ global $errors; ?> <form action="" method="post"> Name: <input name="name" type="text" size="10" maxlength="10" value = "<?php echo $_POST[name]; ?>"/> <br /> <?php echo $errors['name']; ?> <br /> Email: <input name="email" type="text" size="15" maxlength="30" /><br /> <input name="submit " type="submit" value="submit " /> </form> <?php } ?> </body> </html> Hi- the code below lets me upload a CSV file to my database if I have 1 field in my database and 1 column in my CSV. I need to add to my db "player_id" from the CVS file and "event_name" and "event_type" from the form... any ideas??? here's the code: Code: [Select] <?php $hoststring =""; $database = ""; $username = ""; $password = ""; $makeconnection = mysql_pconnect($hoststring, $username, $password); ?> <?php ob_start(); mysql_select_db($database, $makeconnection); $sql_get_players=" SELECT * FROM tabel ORDER BY player_id ASC"; // $get_players = mysql_query($sql_get_players, $makeconnection) or die(mysql_error()); $row_get_players = mysql_fetch_assoc($get_players); // $message = null; $allowed_extensions = array('csv'); $upload_path = '.'; //same directory if (!empty($_FILES['file'])) { if ($_FILES['file']['error'] == 0) { // check extension $file = explode(".", $_FILES['file']['name']); $extension = array_pop($file); if (in_array($extension, $allowed_extensions)) { if (move_uploaded_file($_FILES['file']['tmp_name'], $upload_path.'/'.$_FILES['file']['name'])) { if (($handle = fopen($upload_path.'/'.$_FILES['file']['name'], "r")) !== false) { $keys = array(); $out = array(); $insert = array(); $line = 1; while (($row = fgetcsv($handle, 0, ',', '"')) !== FALSE) { foreach($row as $key => $value) { if ($line === 1) { $keys[$key] = $value; } else { $out[$line][$key] = $value; } } $line++; } fclose($handle); if (!empty($keys) && !empty($out)) { $db = new PDO( 'mysql:host=host;dbname=db', 'user', 'pw'); $db->exec("SET CHARACTER SET utf8"); foreach($out as $key => $value) { $sql = "INSERT INTO `table` (`"; $sql .= implode("`player_id`", $keys); $sql .= "`) VALUES ("; $sql .= implode(", ", array_fill(0, count($keys), "?")); $sql .= ")"; $statement = $db->prepare($sql); $statement->execute($value); } $message = '<span>File has been uploaded successfully</span>'; } } } } else { $message = '<span>Only .csv file format is allowed</span>'; } } else { $message = '<span>There was a problem with your file</span>'; } } ob_flush();?> <!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>CSV File Upload</title> </head> <body> <form class="form" action="" method="post" enctype="multipart/form-data"> <h3>Select Your File</h3> <p><?php echo $message; ?></p> <input type="file" name="file" id="file" size="30" /> <br/> <label>Event Name:</label><input name="event_name" type="text" value="" /> <br/> <label>Event Type:</label><input name="event_type" type="text" value="" /> <br/> <input type="submit" id="btn" class="button" value="Submit" /> </form> <br/> <h3>Results:</h3> <?php do { ?> <p><?php echo $row_get_players['player_id'];?></p> <?php } while ($row_get_players = mysql_fetch_assoc($get_players)); ?> </body> </html> I have problem that only last text field is updated, how should I fix this? Here's the code <?php if(isset($_POST["update"])){ mysql_query("UPDATE categories SET name_category = '".$_POST['category']."' WHERE ID= ".$_POST['currentCat']." ") or die(mysql_error()); mysql_query("UPDATE podkategorije SET name_subcategory = '".$_POST['subcategory']."' WHERE id_subCat= ".$_POST['currentSubCat']." ") or die(mysql_error()); } ?> <form action="" method="post" > <?php //creating texfields from db $query = "SELECT k.ID, k.name_category, pk.name_subcategory, pk.id_subCat FROM `categories` AS k JOIN `subcategories` AS pk ON pk.id_mainCat = k.ID"; $result = mysql_query($query) or die(mysql_error()); $currentCat = false; while($row = mysql_fetch_array($result)) { //so it doesn't repeat itself if($currentCat != $row['ID']) { //display of main Categories ?> <ul> <li> <br/><input name="categories" type="text" value="<?php echo $row['name_category']; ?>" /> </li> </ul> <? $currentCat = $row['ID']; } //display subcategories ?> <input name="subcategories" type="text" value="<?php echo $row['name_category']; ?>" /><br/> <input type="hidden" name="currentCat" value="<?php echo $row['ID']; ?>" /> <input type="hidden" name="currentSubCat" value="<?php echo $row['id_subCat']; ?>" /> <? } ?> <br /> <input type="button" value="Back" onClick="history.go(-1);return true;"> <input type="submit" value="Update" name="update"/> </form> Hi, So i have a form with 4 text inputs (input1,input2,input3,input4). When the user puts in 4 correct words, they are redirected to another page. The words can be checked either via a field in a database or a variable. Any wrong word in any of the text fields returns the user back to the page. In other words: When the user clicks submit, we need to make sure all of the words are correct. If they are not correct, nothing should happen. The user will remain on the page until they enter the correct words. If the words ARE correct, they are directed to a new page with an image. I am not sure how to approach this, I tried using if and case, however I am not sure of the combination to make all 4 fields checked before an out is given (ie, the page redirect). Any help is appreciated. Hi Guys i need help on a small matter. if you go to https://www.mywebchambers.co.uk/invoiceman/form.php when submitted all works ok. However if you delete rows 3, 4 and 5 and submit the page shows a value of 0.00 in the total column on rows 3, 4 and 5. How do i get this value removed so it is blank same as the rest ?
My form action is toolstation3.php code below
<!doctype html> <?php
{$orderno =($_POST["orderno"]);}
{$code3 =($_POST["code3"]);}
{$code4 =($_POST["code4"]);}
{$code5 =($_POST["code5"]);}
{$sum1 =($_POST["sum1"]);} {$nil =($_POST["nil"]);}
$net=$sum1+$sum2+$sum3+$sum4+$sum5;
$total=$net+$vat;
$sum1 = number_format($sum1, 2, '.', '');
if(empty($_POST['quantity3']) && empty($_POST['price3'])) {echo " $nil";}
echo "<br>   ____________________________________________________________________________________________________<br><br>"; echo "<H3>    Address                                                                                                                     Details "; echo "<br>   ___________________________________________________________          ____________________________________<br><br>";
echo "<tr>
echo "<tr> echo "<table cellpadding=3 border=0 style='float:left'>";
echo "<tr> echo "<table cellpadding=3 border=0 style='float:left'>";
echo "<tr> echo "<table cellpadding=3 border=0>";
echo "<tr> echo "<H3>    Items"; echo "<br>   __________________________________________<br><br>";
echo "<tr><th>Code</th><th>Name</th><th>Quantity</th><th>Price</th><th>Total</th><th>Vat Band</th></tr>"; echo "<tr><td>$code1</td><td>$name1</td><td>$quantity1</td><td>$price1</td><td>$sum1</td><td>$vatband1</td> "; echo "<tr><td>$code2</td><td>$name2</td><td>$quantity2</td><td>$price2</td><td>$sum2</td><td>$vatband2</td> "; echo "<tr><td>$code3</td><td>$name3</td><td>$quantity3</td><td>$price3</td><td>$sum3</td><td>$vatband3</td> "; echo "<tr><td>$code4</td><td>$name4</td><td>$quantity4</td><td>$price4</td><td>$sum4</td><td>$vatband4</td> "; echo "<tr><td>$code5</td><td>$name5</td><td>$quantity5</td><td>$price5</td><td>$sum5</td><td>$vatband5</td> ";
echo "<br>"; echo "<H3>    VAT Analysis"; echo "<br>   __________________________________________<br><br>"; echo "<table cellpadding=5 border=1>"; echo "<tr><th>Band</th><th>Rate</th><th>Net</th><th>VAT</th><th>Total</th></tr>"; echo "<tr><td>5</td><td>20%</td><td>$net</td><td>$vat</td><td>$total</td> ";
<div id="container">
I need help with a form .. My form needs to allow an additional drop down field for Groups. This form also needs to save the extra fields chosen into my MySQL DB. Here is my form.. Code: [Select] <form action='' method='post' class='assessment'> <h1>Create User</h1> <div class='label'>First Name</div> <div class='field'><input type='text' name='firstname' value='<?=$preUser->firstname?>' /></div> <div class='cb'></div> <div class='label'>Last Name</div> <div class='field'><input type='text' name='lastname' value='<?=$preUser->lastname?>' /></div> <div class='cb'></div> <div class='label'>Password</div> <div class='field'><input type='text' name='password' value='<?=$preUser->password?>' /></div> <div class='cb'></div> <div class='label'>Company</div> <div class='field'><input type='text' name='company' value='<?=$preUser->company?>' /></div> <div class='cb'></div> <div class='label'>Job Title</div> <div class='field'><input type='text' name='job' value='<?=$preUser->job?>' /></div> <div class='cb'></div> <div class='label'>Group Name</div> <div class='field'><select name='group'><?=$groupSelect?></select></div> <div class='cb'></div> <div class='label'>Address</div> <div class='field'><input type='text' name='street1' value='<?=$preUser->street1?>' /></div> <div class='cb'></div> <div class='label'>Address (optional)</div> <div class='field'><input type='text' name='street2' value='<?=$preUser->street2?>' /></div> <div class='cb'></div> <div class='label'>City</div> <div class='field'><input type='text' name='city' value='<?=$preUser->city?>' /></div> <div class='cb'></div> <div class='label'>State</div> <div class='field'><input type='text' name='state' value='<?=$preUser->state?>' /></div> <div class='cb'></div> <div class='label'>Postal Code</div> <div class='field'><input type='text' name='postal' value='<?=$preUser->postal?>' /></div> <div class='cb'></div> <div class='label'>Country</div> <div class='field'><input type='text' name='country' value='<?=$preUser->country?>' /></div> <div class='cb'></div> <div class='label'>Fax</div> <div class='field'><input type='text' name='fax' value='<?=$preUser->fax?>' /></div> <div class='cb'></div> <div class='label'>Phone</div> <div class='field'><input type='text' name='phone1' value='<?=$preUser->phone1?>' /></div> <div class='cb'></div> <div class='label'>Phone 2</div> <div class='field'><input type='text' name='phone2' value='<?=$preUser->phone2?>' /></div> <div class='cb'></div> <div class='label'>Email</div> <div class='field'><input type='text' name='email' value='<?=$preUser->email?>' /></div> <div class='cb'></div> <div class='label'>Website</div> <div class='field'><input type='text' name='website' value='<?=$preUser->website?>' /></div> <div class='cb'></div> <div class='label'>Photo</div> <div class='field imgupload'> <input type='hidden' name='photo' /> <? if( $preUser->photo ){ ?> <img src="../<?=$preUser->photo?>" style="height:300px; float:left;" /> <span class="rmimage" style="color:red; cursor:pointer; font-size:20px;padding-left:15px;" alt="<?=$preUser->photo?>">x</span> <? }else{ ?> <iframe src="../view/photo_upload.php" frameborder="0" scrolling="no" width="300" height="30"></iframe> <? } ?> </div> <div class='cb'></div> <div class='label'>Payment Option</div> <div class='field'> <input type='radio' name='payment' value='Pay' <? if( $preUser->payment == 'Pay' ) echo "checked='checked'"; ?> />Pay<br /> <input type='radio' name='payment' value='NonPaid' <? if( $preUser->payment == 'NonPaid' ) echo "checked='checked'"; ?> />NonPaid </div> <div class='cb'></div> <div class='label'>Dashboard Options</div> <div class='field'> <div><input type='checkbox' name='mysteps' <? if( $preUser->mysteps ) echo "checked='checked'"; ?> value='1' />My Steps</div> <div><input type='checkbox' name='mycalendar' <? if( $preUser->mycalendar ) echo "checked='checked'"; ?> value='1' />My Calendar</div> <div><input type='checkbox' name='myprofiles' <? if( $preUser->myprofiles ) echo "checked='checked'"; ?> value='1' />My Profile</div> <div><input type='checkbox' name='myplans' <? if( $preUser->myplans ) echo "checked='checked'"; ?> value='1' />My Plans</div> </div> <div class='cb'></div> <div class='submit_assessment'><input type='submit' name='create_user' class='submit' value='Create User' /> <input type='button' value='Back' class='back' name='admin_create' /></div> <div class='cb'></div> </form> <script> function setUploadedImage(flink){ $('.imgupload > input:first').after('<img src="../'+flink+'" style="height:300px; float:left;" /><span class="rmimage" style="color:red; cursor:pointer; font-size:20px;padding-left:15px;" alt="'+flink+'">x</span>'); $('.imgupload > iframe:first').remove(); $('.imgupload > input:first').val(flink); } $('.rmimage').live('click', function (){ $(this).prev().prev().val(''); $(this).prev().remove(); $(this).after('<iframe src="../view/photo_upload.php" frameborder="0" scrolling="no" width="300" height="30"></iframe>'); $.post('../ajax/admin.php',{remove_image:$(this).attr("alt")}); $(this).remove(); }); </script> the specific area in question is this... Code: [Select] <div class='label'>Group Name</div> <div class='field'><select name='group'><?=$groupSelect?></select></div> I need to be able to add another dropdown list to allow for multiple group selections that get saved into the DB once submitted. How do I go about doing this?????? I have got another of those problems that should be easy to solve but I cannot get my head round it! I have a form to enter data into a table and one of the fields can be left blank. However, I'd data is entered in the field it can be a Zero. This is leaving me a problem as I cannot find a way to get the script to insert NULL if the field is blank but actually put the Zero in if that is what is entered. I have tried several permutations of nested if's using empty or isset, but whatever I try, the same result is inserted in both scenarios. The arguments I need to pass are...... If field is empty INSERT null If field is 0 INSERT 0 If field is not empty and not 0 INSERT field Thanks in advance for any suggestions. Steve Hello. So I already know an extremely elementary way to check to see if a form field is blank using PHP. For example: Code: [Select] if ($subject == "") The question I have is, is there a way to have php check every field in a form to make sure it has some sort of value? I want to create an 'if' statement which basically says, "If all form fields have something filled in, then do this" For example Code: [Select] if ($subject == "any value") & ($name == "any value") & ($comment == "any value") Not sure if that makes sense. Any help would be greatly appreciated!!! Is there anything wrong (or insecure) with using hidden form fields? I am working on a page where the user can choose one of 4 different subscription options. The approach I was going to use is to have a separate form for each plan, and when the user chooses one, submit a hidden form value so my script knows which subscription plan to grab out of the database. Thoughts? Hi i would like to submit the following code to my database as a mutiple selection box. when i submit i just get the last selected value for example if i hold ctrl and press 1 2 3 4 i am only receiving 4 on my database. any ideas? thanks in advance for any help! Code: [Select] Hours Of Availability:<br> <select name="availability" multiple="multiple" size="9"> <option value="Monday - Period 1">Monday - Period 1</option> <option value="Monday - Period 2">Monday - Period 2</option> <option value="Monday - Period 3">Monday - Period 3</option> <option value="Monday - Period 4">Monday - Period 4</option> <option value="Monday - Period 5">Monday - Period 5</option> <option value="Monday - Period 6">Monday - Period 6</option> <option value="Monday - Period 7">Monday - Period 7</option> <option value="Monday - Period 8">Monday - Period 8</option> <option value="Monday - Period 9">Monday - Period 9</option> </select> <select name="availability" multiple="multiple" size="9"> <option value="Tuesday - Period 1">Tuesday - Period 1</option> <option value="Tuesday - Period 2">Tuesday - Period 2</option> <option value="Tuesday - Period 3">Tuesday - Period 3</option> <option value="Tuesday - Period 4">Tuesday - Period 4</option> <option value="Tuesday - Period 5">Tuesday - Period 5</option> <option value="Tuesday - Period 6">Tuesday - Period 6</option> <option value="Tuesday - Period 7">Tuesday - Period 7</option> <option value="Tuesday - Period 8">Tuesday - Period 8</option> <option value="Tuesday - Period 9">Tuesday - Period 9</option> </select> <select name="availability" multiple="multiple" size="9"> <option value="Wednesday - Period 1">Wednesday - Period 1</option> <option value="Wednesday - Period 2">Wednesday - Period 2</option> <option value="Wednesday - Period 3">Wednesday - Period 3</option> <option value="Wednesday - Period 4">Wednesday - Period 4</option> <option value="Wednesday - Period 5">Wednesday - Period 5</option> <option value="Wednesday - Period 6">Wednesday - Period 6</option> <option value="Wednesday - Period 7">Wednesday - Period 7</option> <option value="Wednesday - Period 8">Wednesday - Period 8</option> <option value="Wednesday - Period 9">Wednesday - Period 9</option> </select> <select name="availability" multiple="multiple" size="9"> <option value="Thursday - Period 1">Thursday - Period 1</option> <option value="Thursday - Period 2">Thursday - Period 2</option> <option value="Thursday - Period 3">Thursday - Period 3</option> <option value="Thursday - Period 4">Thursday - Period 4</option> <option value="Thursday - Period 5">Thursday - Period 5</option> <option value="Thursday - Period 6">Thursday - Period 6</option> <option value="Thursday - Period 7">Thursday - Period 7</option> <option value="Thursday - Period 8">Thursday - Period 8</option> <option value="Thursday - Period 9">Thursday - Period 9</option> </select> <select name="availability" multiple="multiple" size="9"> <option value="Friday - Period 1">Friday - Period 1</option> <option value="Friday - Period 2">Friday - Period 2</option> <option value="Friday - Period 3">Friday - Period 3</option> <option value="Friday - Period 4">Friday - Period 4</option> <option value="Friday - Period 5">Friday - Period 5</option> <option value="Friday - Period 6">Friday - Period 6</option> <option value="Friday - Period 7">Friday - Period 7</option> <option value="Friday - Period 8">Friday - Period 8</option> <option value="Friday - Period 9">Friday - Period 9</option> </select> <select name="availability" multiple="multiple" size="9"> <option value="Saturday - Period 1">Saturday - Period 1</option> <option value="Saturday - Period 2">Saturday - Period 2</option> <option value="Saturday - Period 3">Saturday - Period 3</option> <option value="Saturday - Period 4">Saturday - Period 4</option> <option value="Saturday - Period 5">Saturday - Period 5</option> <option value="Saturday - Period 6">Saturday - Period 6</option> <option value="Saturday - Period 7">Saturday - Period 7</option> <option value="Saturday - Period 8">Saturday - Period 8</option> <option value="Saturday - Period 9">Saturday - Period 9</option> </select> <br>Press + Hold Ctrl For Multiple</p> I'm making a contact form using PHP, I've got the look of the form done and I'm very happy with the look - but the actual email bit is a bit challenging. I'm using the code from a contact form on css-tricks.com, and the script does send emails... and I receive them but the emails are completely blank apart from the 'name: email: message:' stuff and the subject. What am I doing wrong? Here is the code I am using: contact.html Code: [Select] <form method="post" action="contactengine.php" id="commentForm"> <div class="form"> <p><input type="text" name="fullName" id="firstName" class="required" title="Full name" /></p> <p><input type="text" name="emailAddress" id="emailAddress" class="required" title="Email Address" /></p> <p><textarea type="text" name="message" id="message" class="required" title="Message"></textarea></p> </div> <p><input type="submit" name="submit" value="Submit" class="submit-button" title="Send" /></p> </form> contactengine.php $EmailFrom = "enquiries@aplinnovations.co.uk"; $EmailTo = "info@aplinnovations.co.uk"; $Subject = "Contact Form Submission"; $fullName = Trim(stripslashes($_POST['Name'])); $emailAddress = Trim(stripslashes($_POST['Email'])); $message = Trim(stripslashes($_POST['Message'])); $Body = ""; $Body .= "Name: "; $Body .= $fullName; $Body .= "\n"; $Body .= "Email: "; $Body .= $emailAddress; $Body .= "\n"; $Body .= "Message: "; $Body .= $message; $Body .= "\n"; $success = mail($EmailTo, $Subject, $Body, "From: $emailAddress"); I really have no idea how to code in PHP, I know I'm a newbie and I'm sure this is a really dumb question... but please help! Thanks I have a database field `color` enum('red','blue','green','white') DEFAULT NULL, and php form <label for="color">Colors</label><br /> <input type="text" name="color" /> How do i display enum value on the php form from mysql database? Please help php mysql The ID field doesn't display the data but it must be there because it was the key for the query. It is an int if that makes any difference. <html> <head> </head> <body> <?php // Connect to database===================================================== include("connect_db.php"); // retrieve form data ====================================================== $id = $_POST['id']; // sending query =========================================================== $query = "SELECT ama,model_name,model_mfg,wingspan,engine,decibels FROM airplanes WHERE id='$id'"; if( !$result = mysql_query($query) ) { echo "<br>Query $query<br>Failed with error: " . mysql_error() . '<br>'; } else { $fetch = mysql_fetch_array( $result ); } // Output form with retrieved data ========================================== ?> <h3>Change the data and then click the CHANGE button</h3><br> <form name="Form51" action="update_db_airplane.php" method="post"> ID #:<input type="text" name="id" value="<?=$fetch[id]?>" /><br> AMA #:<input type="text" name="ama" value="<?=$fetch[ama]?>" /><br> Model Name:<input type="text" name="model_name" value="<?=$fetch[model_name]?>" /><br> Model Mfg:<input type="text" name="model_mfg" value="<?=$fetch[model_mfg]?>" /><br> Wingspan:<input type="text" name="wingspan" value="<?=$fetch[wingspan]?>" /><br> Engine:<input type="text" name="engine" value="<?=$fetch[engine]?>" /><br> Decibels:<input type="text" name="decibels" value="<?=$fetch[decibels]?>" /><br><br> <input name="submit" id="submit" value="CHANGE!" type="submit"> </form> <br> <body> </html> |