PHP - Carrying Hidden Fields In A Form.
Hi
I've got a form that users enter an identification pin in for their first question as well as clicking a radio button(Q1.php) . They click submit and the answers are put through a couple of multiplication function and then placed in a table (alongside the pin) via Q2.php. On the Q2 page I want to place the 2nd question that the user needs to answer. Rather than making them retype the pin I was hoping to process it as a hidden field - being picked up from their Q1.php entry. This 'hidden pin echo ' process will continue throughout Q2- Q10 pages. However - I can't seem to include any php in the page after the Q1 form has been processed. Have I got my php tags messed up? <?php $con = mysql_connect("localhost","ca","d"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("candango", $con); $q1 =$_POST['q1']; $pin =$_POST['pin']; $ans1 = $q1 * 3; $ans2 = $q1 * 5; $ans3 = $q1 * 2; $enter_sql= "INSERT INTO aapcm2 (pin,ans1, ans2, ans3) VALUES ('$pin','$ans1','$ans2','$ans3')"; $enter_query =mysql_query($enter_sql) or die (mysql_error()); ?> <body> <p>Thank you - You have successfully entered your answers.</p><form action="q2.php" method="post"> <p>What do you think the answer to this one is? <input type="radio" name="q2" id="q2" value="-3"> <label for="q2"></label> <input name="Hidden" type="hidden" id="Hidden" value="$pin" /></p> <p> <input type="submit" name="button" id="button" value="Submit"> </p> </form> <p></p> </body> Similar TutorialsIs 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 have an index.php with three drop down boxes on, each drop down uses an SQL statement to pull seatNumber from 'seats' each seat number has a UI and a forgein key field called SrideID. I have the buttons on the dorp down boxes going to dd-check.php, here the seat chosen is posted and a simple echo(just testing it works atm) for me to do any queries I also need the SrideID within the dropdown box, i tried adding it within the <option></option> but it only made the drop down duplicate. 1 1 2 2 3 3 ect..... what i would like is for the SrideID field to be included with in the dropdown box but hidden so i can post it to the dd-check.php and then show the time and price of that particular ride. here is the table and the code so far. Thanks for any help. CREATE TABLE `ride` ( `RrideID` tinyint(1) default NULL, `name` varchar(20) default NULL, `time` tinyint(1) default NULL, `price` varchar(4) default NULL ) INSERT INTO `ride` VALUES (1, 'Swinging Ship', 7, '2.50'); INSERT INTO `ride` VALUES (2, 'Roller Coaster', 5, '3.75'); INSERT INTO `ride` VALUES (3, 'Ice Blast', 4, '3.00'); CREATE TABLE `seats` ( `seatID` int(8) NOT NULL default '0', `SrideID` tinyint(1) default NULL, `seatNumber` int(2) default NULL, PRIMARY KEY (`seatID`) ) INSERT INTO `seats` VALUES (1, 1, 1); INSERT INTO `seats` VALUES (2, 1, 2); INSERT INTO `seats` VALUES (3, 1, 3); INSERT INTO `seats` VALUES (4, 1, 4); INSERT INTO `seats` VALUES (5, 1, 5); INSERT INTO `seats` VALUES (49, 2, 1); INSERT INTO `seats` VALUES (50, 2, 2); INSERT INTO `seats` VALUES (51, 2, 3); INSERT INTO `seats` VALUES (52, 2, 4); INSERT INTO `seats` VALUES (53, 2, 5); INSERT INTO `seats` VALUES (69, 3, 1); INSERT INTO `seats` VALUES (70, 3, 2); INSERT INTO `seats` VALUES (71, 3, 3); INSERT INTO `seats` VALUES (72, 3, 4); INSERT INTO `seats` VALUES (73, 3, 5); code for index.php <table width="200" border="1"> <tr> <h1>Swinging Ship</h1> <?php echo '<form method="post" name="f1" action="dd-check.php">'; $query_s = "SELECT * FROM `seats` WHERE SrideID='1' ORDER BY seatID"; $result = mysql_query($query_s); echo"<select name='seatNumber'><option value=''>Select Seat</option>"; while( $row = mysql_fetch_array($result) ) { echo '<option>'.$row['seatNumber'].'</option>'; } echo '</select>'; mysql_free_result( $result ); echo "<input type='submit' value='Submit'>"; echo "</form>"; ?> </tr> <tr> <h1>Roller Coaster</h1> <?php echo '<form method="post" name="f2" action="dd-check.php">'; $query_r = "SELECT * FROM `seats` WHERE SrideID='2' ORDER BY seatID"; $result = mysql_query($query_r); echo"<select name='seatNumber'><option value=''>Select Seat</option>"; while( $row = mysql_fetch_array($result) ) { echo '<option>'.$row['seatNumber'].'</option>'; } echo '</select>'; mysql_free_result( $result ); echo "<input type='submit' value='Submit'>"; echo "</form>"; ?> </tr> <tr> <h1>Ice Blast</h1> <?php echo '<form method="post" name="f3" action="dd-check.php">'; $query_i = "SELECT * FROM `seats` WHERE SrideID='3' ORDER BY seatID"; $result = mysql_query($query_i); echo"<select name='seatNumber'><option value=''>Select Seat</option>"; while( $row = mysql_fetch_array($result) ) { echo '<option>'.$row['seatNumber'].'</option>'; } echo '</select>'; mysql_free_result( $result ); echo "<input type='submit' value='Submit'>"; echo "</form>"; ?> </tr> </table> code for dd-check.php <?php $result=$_POST['seatNumber']; echo " <p> the seat choosen is : $result <p> "; //TEST PULL ALL QUERY $testPullAll = mysql_query("SELECT * FROM ride"); echo "<table border='1'> <tr> <th>Name</th> <th>Duration</th> <th>Price</th> </tr>"; while($row = mysql_fetch_array($testPullAll)) { echo "<tr>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['time'] . "</td>"; echo "<td>" . $row['price'] . "</td>"; echo "</tr>"; } echo "</table>"; ?> the end result will be a query in dd-check.php that says something like if [hidden SrideID = 1] echo 'the name, time and price of the ride' if [hidden SrideID =2 echo name, time and price if number 3 then echo the rest of the row. any help would be great, i've been using trial and error so far (since yesterday afternoon) with no success =( ps sorry for the long post, i wanted to try and explain everything the best i can. =) Is there any way using only PHP? The problem is that I don't have access to the form processor, or to MySQL. Hey guys, please tell me why the session var $_SESSION['return_url'] is not carrying from test.php to login.php The two echos in this file work perfectly, so i know the session var is registered... test.php <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>SWG:ANH • Bringing PreCU back to life...</title> <link rel="shortcut icon" href="favicon.ico" /> <link rel="stylesheet" type="text/css" media="screen" href="theme/main.css" /> <?php session_start(); // This section will generate a var containing the current page URL. This will be used to allow the language script to redirect users back to the page they // were on, in the language they selected. It is registered as a session variuable that will change every time the page changes. function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } // Here we register the URL we grabbed earlier in the session var. $return_url = curPageURL(); $_SESSION['return_url'] = $return_url; echo $_SESSION['return_url']; echo $return_url; include 'lang/enus.php'; include 'menu.php'; ?> login.php <?php session_start(); echo $_SESSION['return_url'] ; include 'dbconnect.php'; $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $return_url = $_SESSION['return_url']; echo $return_url; $result = mysql_query("SELECT COUNT(*) FROM account WHERE Username='$username' and Pass='$password'") or die(mysql_error()); $result = mysql_fetch_row($result); $result = $result[0]; if($result == 1){ $_SESSION['username'] = $username; header("Location:".$return_url); } else { echo "Wrong Username or Password. Use the back button. If you think this message is incorrect, contact the webmaster."; } ?> I know its not carrying because the echo in login.php is not returning anything and the script cant execute the header function because it has nowhere to go! Ive narrowed it down to the session var not carrying. Hi, I'm having trouble carrying items between two files. The problem is that it works too well. Whenever I include a php file that echos something, the other php files echos the same thing. What are some ways to stop this, but still have access to the variable. Thanks, GEORGE Hey all, i have a little problem. I have a form, and when submitting, i need to use the ID that i put in the $_GET array earlier. When you're entering my site, and clicks a certain link, the $_GET will store show=1, and when you're submitting the form on the page, the value of 'show' is needed on the redirect page.. I thought that it would be smart to transfer it with a hidden textfield, but somehow it fails? <form id="comment-form" action="comment_profile.php" method="POST"> <fieldset> <div class="field"> <textarea name="comment-field" rows="2" cols="66"></textarea> <input type="hidden" name="pofileid-field" value="<?php echo $_GET['show']; ?>" /> // <--- Here is the hidden field. <input type="submit" name="submit-field" class="submit" value=""/><i> (HTML tags kan bruges)</i> </div> </fieldset> </form> Above you can see a piece of my code, and i marked the hidden field aswell. What i do not understand is, why isn't the hidden fields value return the value of show when i check in comment_profile.php, as that is where it returns? Thanks in advance -Niixie I have created a form which allows people to add data to a database. However, I want to replicate the form across several pages and give each page a category. For example, if I have a website based on sport. I have a page which enters information into the baseball category, a page which enters information into the ice hockey category, a page which enters information into the soccer category etc. Can someone advise how I would do this? This is just a snippet of my code. The php script itself is called test.php and so it calls itself once the form is submitted. I keep having problems retrieving the data back correctly; I am testing in retrieving the data on the same script from the same page before retrieving the POST data from another webpage. If $decimalSum is a variable that assigns a value that is hard-coded then I would be able to retrieve the same value. However, if the value is computed I can not retrieve it unless I click on the "Find" button twice. This is such a strange behavior and I don't know why. Does anyone have any suggested solutions to this? <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> <?php echo '<form enctype="multipart/form-data" method="post" action="test.php">'; echo ' <label for="_firstName">First name : </label>'; echo ' <input type="text" id="_firstName" name ="_firstName">'; echo ' <input type="checkbox" value="1" name="_firstNameChecked"/>'; echo ' <label for="_middleName">Middle name : </label>'; echo ' <input type="text" id="_middleName" name ="_middleName">'; echo ' <input type="checkbox" value="1" name="_middleNameChecked" />'; echo ' <label for="_lastName">Last name : </label>'; echo ' <input type="text" id="_lastName" name ="_lastName">'; echo ' <input type="checkbox" value="1" name="_lastNameChecked" />'; echo '<br />'; echo '<input type="submit" name="Find" value="Find" />'; $firstNameChecked = intval(($_POST['_firstNameChecked'])); $middleNameChecked = intval(($_POST['_middleNameChecked'])); $lastNameChecked = intval(($_POST['_lastNameChecked'])); $decimalSum = (int)((2*2*2)*$firstNameChecked + (2*2)*$middleNameChecked + (2*1)*$lastNameChecked); //$decimalSum = 28; echo '<br />'; echo '$decimalSum = ' . $decimalSum . '<br />'; echo '<input type="hidden" name="_decimalSum" value = "' . $decimalSum . '" />'; $decimalSum2 = ($_POST['_decimalSum']); echo '$decimalSum2 = ' . $decimalSum2 . '<br />'; echo '</form>'; echo '</body>'; echo '</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> Here's my PHP form code: Code: [Select] <form method='POST' action="<?php basename($_SERVER['PHP_SELF']);?>" onSubmit="return stripInputBoxes(1)"> <?php echo "<div id = 'purchaseOrderRow1' style = 'display:none;border: 1px solid black;'>"; echo $integrityBuildingProductsPDF; echo '<input type = "hidden" id = "pdf1" value = "" name = "pdf1" />'; echo '<button name = "savePurchaseOrder" type = "submit">Save Purchase Order</button>'; echo "</div>"; ?> </form> Here's my Javascript: Code: [Select] function stripInputBoxes(pdfNumber) { if (!document.getElementsByTagName) return; for (i = 0; i < document.getElementById('tableBody').getElementsByTagName('tr').length - 3; i++) { document.getElementById(i).parentNode.innerHTML = document.getElementById(i).value; } document.getElementById("pdf" + pdfNumber).value = "ljkasdkljf"; return true; } Will this set the value of the hidden variable? I'm trying to echo the value of $_POST['pdf1'] but it comes out to nothing when the page reloads. How do I do this? What I'm trying to do here is display a purchase order on the screen and the user can edit the quantities in the purchase order. They click SAVE to save the new updated quantities and it auto generates a PDF that's saved on the server with those new quantities. The problem is I need to run the stripInputBoxes function to take the <input> tags out of the HTML code before creating the PDF because the PDF generator doesn't recognize the tags. If I store a value in a hidden form control, and then use that as a means to pass the value to another PHP script, could that cause any security issues?
Can someone please tell me what I am doing wrong here? For some reason, the variable doess not seem to be getting passed to the "action" php script this input is in my html form (action=post)... <input type="hidden" name="httpreferer" value="<?php echo $_SERVER['HTTP_REFERER'] ?>" /> this is in the action script... $httpreferer=$_POST['httpreferer']; echo $httpreferer; 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?????? 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 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!!! Hi I am learning PHP and working on a Contact Us page with a required fields. For some reason it works great for the name and email, but always says please enter your phone number. If you guys have a better way of doing this please let me know. Also if the email is sent successfully I want it to goto the page "success.html" this part works good though just need some help please Here is the form: Code: [Select] <form action="contact.php" method="post" id="contactform"> <ol> <li> <label for="name">Full Name <span class="red">*</span></label> <input id="name" name="name" class="text" /> </li> <li> <label for="email">Your email <span class="red">*</span></label> <input id="email" name="email" class="text" /> </li> <li> <label for="phone">Phone Number <span class="red">*</span></label> <input id="phone" name="phone" class="text" /> </li> <li> <label for="company">Company</label> <input id="company" name="company" class="text" /> </li> <li> <label for="topic">Subject<span class="red">*</span></label> <input id="topic" name="topic" class="text" /> </li> <li> <label for="comments">Message <span class="red">*</span></label> <textarea id="comments" name="comments" rows="6" cols="50"></textarea> </li> <li class="buttons"> <input type="image" name="imageField" id="imageField" src="images/send.gif" /> </li> </ol> </form> The PHP code I tried: Code: [Select] <?php // Pick up the form data and assign it to variables $name = check_input ($_POST['name'], "Please enter your name"); $email = check_input ($_POST['email'],"Please enter your email"); $phone = check_input ($_POST['phone'], "Please enter your phone number"); $company = $_POST['company']; $topic = check_input ($_POST['topic'], "Please enter your subject"); $comments = check_input ($_POST['comments'], "Please enter your message"); function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if (strlen($data) == 0) { die($problem); } else { return $data; } } // Build the email (replace the address in the $to section with your own) $to = 'email@email.com"'; $subject = "New message: $topic"; $message = "Email: $email \n Phone: $phone \n Company: $company \n $name said: $comments"; $headers = "From: $email"; // Send the mail using PHPs mail() function mail($to, $subject, $message, $headers); // Redirect header("Location: success.html"); ?> Good morning, I am a beginner at PHP, but trying to write a simple script to use at work and currently stuck on one part, looking for some advice! I have a simple form here > http://jmdostal.com/route2.php (Feel free to use it to test), that returns data on the next page, in a format such as : Jose F - Jose A - 285 Brenda L [Delivery] [Dallas] - Items Job 2 [Pickup] [Arlington] - Items [] [] - [] [] - [] [] - [] [] - [] [] - Gustavo - +1 - 284/pickup Jody W [Delivery] [Keller] - Items [] [] - [] [] - [] [] - [] [] - [] [] - [] [] - My question is how can I get it not to show the fields that are empty, so I dont have a bunch of lines with [] [] - formatting Here is my coding you can view here > http://jmdostal.com/code.txt A friend had suggested to me trying to use isset , so I tried it on a few lines, such as : if(isset($_POST['items14'])){ $items14 = "- ". Trim(stripslashes($_POST['items14'])); } But it didnt seem to change anything. Im sure this is something simply, Any suggestions are appreciated! Thanks ! 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> |