PHP - User Updating A Form With Drop Down Menus In It
Hi I have a single page submission update page which incorporates 7 drop down menus and 2 text input fields, everything works fine with the data updating back to the database, the only thing is that when the page is updated all the drop down menus are updated which includes ones that I don't want updated?
I need to only update the drop down menus that have been selected? but am unsure how I do it? This is the code from the page, sorry if its a mess but I am not that experienced at the moment. This is a snippet of one of the drop down menus Code: [Select] <tr> <td class="heading">Current Status</td> <td><?php echo $statusdescrip ['status_description']; ?> <select name="status_id" > <?php $status_set = findstatus(); $statuslist = mysql_fetch_assoc ($status_set); ?> <?php do { ?> <option value="<?php echo $statuslist ['status_id']; ?>" ><?php echo $statuslist ['status_description']; ?></option> <?php } while ($statuslist = mysql_fetch_assoc ($status_set)); ?></select> <span class="compuls">*</span></td> </tr> Similar TutorialsOk, I have one database three tables. Table 1 is ncmr the main table where everything is to be entered. Table 2 is companies, where all the companies in pull down menu 1 is located. Table 3 is fabricators, where all the people who have had hands on the product are residing. I want the selected choices of table 2 and 3 to be inputed into table 1. I know this has to be possible, but I don't know how. I thought I wrote the code correctly, but it seems not. Can someone review my code and show me where my mistake is? Here is the page: http://kaboomlabs.com/PDI/post2.php Thanks. Code: [Select] <?php require_once('connectvars.php'); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>PDI Non-Conforming Materials Report</title> <link rel="stylesheet" type="text/css" href="CSS/postie.css" /> </head> <body> <div id="logo"> <img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" /> </div> <div id="title"> <h3 id="NCMR2">Non-Conforming Materials Report (NCMR)</h3> </div> <?php //Post Data if (isset($_POST['submit'])) { $ab = mysqli_real_escape_string($dbc,$_POST['ab']); $date = mysqli_real_escape_string($dbc,date('Y-m-d',strtotime ($_POST['date']))); $part = mysqli_real_escape_string($dbc,$_POST['part']); $rev = mysqli_real_escape_string($dbc,$_POST['rev']); $partdesc = mysqli_real_escape_string($dbc,$_POST['partdesc']); $ncmrqty = mysqli_real_escape_string($dbc,$_POST['ncmrqty']); $comp = mysqli_real_escape_string($dbc,$_POST['comp']); $ncmrid = mysqli_real_escape_string($dbc,$_POST['ncmrid']); $rma = mysqli_real_escape_string($dbc,$_POST['rma']); $jno = mysqli_real_escape_string($dbc,$_POST['jno']); $fdt = mysqli_real_escape_string($dbc,$_POST['fdt']); $cof = mysqli_real_escape_string($dbc,$_POST['cof']); $fab1= mysqli_real_escape_string($dbc,$_POST['fab1']); $fab2= mysqli_real_escape_string($dbc,$_POST['fab2']); $fab3= mysqli_real_escape_string($dbc,$_POST['fab3']); $non= mysqli_real_escape_string($dbc,$_POST['non']); $dis= mysqli_real_escape_string($dbc,$_POST['dis']); $comm= mysqli_real_escape_string($dbc,$_POST['comm']); $caad= mysqli_real_escape_string($dbc,$_POST['caad']); $po= mysqli_real_escape_string($dbc,$_POST['po']); $pod = mysqli_real_escape_string($dbc,date('Y-m-d',strtotime($_POST['pod']))); $dri = mysqli_real_escape_string($dbc,date('Y-m-d',strtotime($_POST['dri']))); $output_form = 'no'; if (empty($ab) || empty($date) || empty($part) || empty($partdesc)){ // We know at least one of the input fields is blank echo '<div id="alert">'; echo 'Please fill out all of the required NCMR information.<br />'; echo '</div>'; } $output_form = 'yes'; } //Access the Database if (!empty($ab) && !empty($date) && !empty($pod)) { $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); $query = "INSERT INTO ncmr (ab, date, part, rev, partdesc, ncmrqty, comp, ncmrid, rma, jno, fdt, cof, fab1, fab2, fab3, non, dis, comm, caad, po, pod, dri) VALUES ('$ab','$date','$part','$rev','$partdesc','$ncmrqty','$comp','$ncmrid','$rma','$jno','$fdt','$cof','$fab1','$fab2','$fab3','$non','$dis','$comm','$caad','$po','$pod','$dri')"; $data = mysqli_query($dbc, $query) or die("MySQL error: " . mysqli_error($dbc) . "<hr>\nQuery: $query"); // Confirm success with the user echo '<tr><td class="thank">'; echo '<p>Thank you for adding the NCRM, the correct person will be informed.</p>'; echo '<p><a href="post.php"><< Back to the form</a></p>'; $output_form = 'no'; echo '</td></tr>'; mysqli_close($dbc); } if ($output_form == 'yes') { echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>"; echo '<fieldset>'; //Part, Rev, Part Description, NCMR Qty echo '<div id="box1">'; echo '<div id="ab"><span class="b">Added By: </span><input type="text" name="ab" value="" /></div>'; echo '<div id="date"><span class="b">Date Filed: </span><input type="text" name="date" value="" /></div>'; echo '<div id="part"><span class="b">Part Number: </span><input type="text" name="part" value="" /></div>'; echo '<div id="rev"><span class="b">Part Revision: </span><input type="text" name="rev" value="" /></div>'; echo '<div id="partdesc"><span class="b">Part Description: </span><textarea name="partdesc" rows="3" cols="22" ></textarea></div>'; echo '<div id="ncmrqty"><span class="b">NCMR Qty: </span><input type="text" name="ncmrqty" value="" /></div>'; echo '</div>'; //Company, Customer NCMR, Internal RMA, and Job Number echo '<div id="box2">'; echo'<div id="comp">'; echo '<span class="b">Company: </span>'; $mysqli->select_db('comp'); $result = $mysqli->query("SELECT * FROM comp"); $i = 0; echo "<SELECT name='comp'>\n"; while($row = $result->fetch_assoc()) { if ($i == 4) echo '<option value="lines">-----</option>'; echo "<option value='{$row['user_id']}'>{$row['name']}</option>\n"; $i++; } echo "</select>\n"; echo '</div>'; echo '<div id="ncmrid"><span class="b">Customer NCMR ID: </span><input type="text" name="ncmrid" value="" /></div>'; echo '<div id="rma"><span class="b">Internal RMA #: </span><input type="text" name="rma" value="" /></div>'; echo '<div id="jno"><span class="b">Job #: </span><input type="text" name="jno" value="" /></div>'; echo '</div>'; //Type of Failure and Class of Failure echo '<div id="box3">'; echo '<h2>Failure</h2>'; echo '<div id="fdt">'; echo '<span class="b">Failure Due To: </span><br />'; echo '<select name="fdt">'; echo '<option value="none">----None----</option>'; echo '<option value="In House">In House</option>'; echo '<option value="Third Party">Third Party</option>'; echo '</select>'; echo '</div>'; echo'<div id="cof">'; echo '<span class="b">Class of Failu </span><br />'; echo '<select name="cof">'; echo '<option value="none">----None----</option>'; echo '<option value="Materials">Materials</option>'; echo '<option value="Fabrication">Fabrication</option>'; echo '<option value="Drawing">Drawing</option>'; echo '<option value="Assembly">Assembly</option>'; echo '<option value="Testing">Testing</option>'; echo '<option value="Electrical">Electrical</option>'; echo '<option value="Programming">Programming</option>'; echo '<option value="Machining">Machining</option>'; echo '<option value="Inspection">Inspection</option>'; echo '<option value="Purchasing">Purchasing</option>'; echo '<option value="Administrator">Administrator</option>'; echo '</select>'; echo '</div>'; echo '</div>'; //Fabricators echo '<div id="box4">'; echo '<h2>Fabricators</h2>'; echo'<div id="fab1">'; $mysqli->select_db('user'); $result = $mysqli->query("SELECT * FROM user"); echo "<SELECT name='fab1'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['user_id']}'>{$row['user']}</option>\n";} echo "</select>\n"; echo '</div>'; echo'<div id="fab2">'; $mysqli->select_db('user'); $result = $mysqli->query("SELECT * FROM user"); echo "<SELECT name='fab2'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['user_id']}'>{$row['user']}</option>\n";} echo "</select>\n"; echo '</div>'; echo'<div id="fab3">'; $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $mysqli->select_db('user'); $result = $mysqli->query("SELECT * FROM user"); echo "<SELECT name='fab3'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['user_id']}'>{$row['user']}</option>\n";} echo "</select>\n"; echo '</div>'; echo '</div>'; //Nonconformity, Disposition, Comments and Comments & Additional Details echo '<div id="box5">'; echo '<div id="non"><span class="b">Nonconformity: </span><br /><textarea name="non" rows="3" cols="110" ></textarea><br /></div>'; echo '<div id="dis"><span class="b">Disposition: </span><br /><textarea name="dis" rows="3" cols="110" ></textarea></div>'; echo '<div id="comm"><span class="b">Comments: </span><br /><textarea name="comm" rows="3" cols="110" ></textarea></div>'; echo '<div id="caad"><span class="b">Comments and/or Additional Details: </span><br /><textarea name="caad" rows="3" cols="110" ></textarea></div>'; //PO, PO Date, and Date Recieved echo '<div id="podr">'; echo '<div id="po"><span class="b">PO: </span><input type="text" name="po" size="7" value="" /></div>'; echo '<div id="pod"><span class="b">PO Date: </span><input type="text" name="pod" size="7" value="" /></div>'; echo '<div id="dri"><span class="b">Date Received: </span><input type="text" name="dri" size="7" value=""'; echo '</div>'; echo '<div id="button"><input type="submit" value="Submit NCMR" name="submit" /></div>'; echo '</div>'; echo '</fieldset>'; echo '</form>'; } ?> </body> </html>
Hello I have an issue with a form that has been built by someone else on Wordpress. <div class="steps"> <div class="step gap-large step-1"> <h2 class="step-title"><span class="gold">Step 1.</span> Calculate the value of your <span class="gold">gold</span></h2> [gold_calculator your-items] </div> <div class="step gap-large step-2"> <h2 class="step-title"><span class="gold">Step 2.</span> Submit your details</h2> <div class="row"> <div class="column col-xs-12 col-sm-2 col-lg-4"> <label class="required" for="sell-title">Title</label> [select* your-title id:sell-title class:form-control "Mr" "Mrs" "Miss" "Ms"] </div> <div class="column col-first-name col-xs-12 col-sm-5 col-lg-4"> <label class="required" for="sell-first-name">First Name</label> [text* your-first-name id:sell-first-name class:form-control placeholder "Enter your first name"] </div> <div class="column col-last-name col-xs-12 col-sm-5 col-lg-4"> <label class="required" for="sell-last-name">Last Name</label> [text* your-last-name id:sell-last-name class:form-control placeholder "Enter your last name"] </div> <div class="column col-xs-12 col-sm-12 col-lg-4"> <label class="required" for="sell-email">Email Address</label> [email* your-email id:sell-email class:form-control placeholder "Enter your email address"] </div> <div class="column col-xs-12 col-sm-6 col-lg-4"> <label class="required" for="sell-daytime-phone">Daytime Telephone</label> [tel* your-daytime-phone id:sell-daytime-phone class:form-control placeholder "Enter your telephone number"] </div> <div class="column col-xs-12 col-sm-6 col-lg-4"> <label class="" for="sell-mobile-phone">Mobile Telephone</label> [tel your-mobile-phone id:sell-mobile-phone class:form-control placeholder "Enter your mobile number"] </div> <div class="column col-xs-12 col-sm-6 col-lg-6"> <label class="required" for="sell-address-1">Address Line 1</label> [text* your-address-1 id:sell-address-1 class:form-control placeholder "Enter your address"] </div> <div class="column col-xs-12 col-sm-6 col-lg-6"> <label class="" for="sell-address-2">Address Line 2</label> [text your-address-2 id:sell-address-2 class:form-control placeholder "Enter your address"] </div> <div class="column col-xs-12 col-sm-12 col-lg-4"> <label class="required" for="sell-city">Town/City</label> [text* your-city id:sell-city class:form-control placeholder "Enter your town/city"] </div> <div class="column col-xs-12 col-sm-6 col-lg-4"> <label class="required" for="sell-county">County</label> [text* your-county id:sell-county class:form-control placeholder "Enter your county"] </div> <div class="column col-xs-12 col-sm-6 col-lg-4"> <label class="required" for="sell-postcode">Postcode</label> [text* your-postcode id:sell-postcode class:form-control placeholder "Enter your postcode"] </div> <div class="column col-xs-12 col-sm-12 col-lg-6"> <label class="required" for="sell-method">Choose your method of payment</label> [select* your-method id:sell-method class:form-control "Instant Bank Transfer" "Cash" "Cheque"] </div> <div class="column col-xs-12 ccol-sm-12 col-lg-6"> <div class="input-label required">Terms & Conditions</div> [acceptance your-price-acceptance id:sell-price-acceptance]I accept the price offered above for my gold.[/acceptance] [acceptance your-terms-acceptance id:sell-terms-acceptance]I accept the <a href="/terms-conditions/" target="_blank">terms & conditions</a>.[/acceptance] [acceptance your-acknowledgement id:sell-acknowledgement]I declare and acknowledge that: 1. I confirm the property enclosed is mine to sell, 2. I believe the items(s) to be genuine gold or platinum 3. You will contact me if the value calculated upon receipt differs in weight or carat 4. I accept payment will only be made to the person named on the submission form.[/acceptance] </div> <div class="column col-submit col-xs-12 col-sm-12"> <div class="alert alert-info">After clicking the ‘Submit’ button below, we'll email you a form to print off and include with the package you send to us. If you wish to be paid by bank transfer, please write your bank details on the form once printed.</div> <div class="submit">[submit class:btn class:btn-gold "Submit"]</div> </div> </div> </div> </div>
<?php /** @var \Strive\Sections\Pdf_Form $this */ ?> <head> <style> h1, h2 { margin-top: 0; } th, td { text-align: left; vertical-align: top; } .section { padding: 20px 0; } .border-top { border-top: solid 1px #E7E7E7; } .cut-top { border-top: dashed 1px #E7E7E7; } .text-placeholder { background-color: #F7F7F7; } .cut-note { text-align: center; font-size: 80%; margin-bottom: 5px; } </style> </head> <body> <h1>Step 3. Print & post this form with your gold</h1> <div class="section quote border-top"> <h2 class="section-title">Customer Quote:</h2> <div> <?php if ( $this->calculator['empty'] 😞 ?> <p>You didn't weigh your gold - don't worry, we'll do it for you and call you with an offer. </p> <?php else: ?> <ol> <?php foreach ( $this->calculator['items'] as $item 😞 ?> <li><?php echo $item['weight']; ?>g of <?php echo $item['name']; ?> - £<?php echo $item['price']; ?></li> <?php endforeach; ?> </ol> <p>Total: £<?php echo $this->calculator['total']; ?></p> <?php endif; ?> </div> </div> <div class="section details border-top"> <h2 class="section-title">Customer Details:</h2> <table width="100%"> <tr> <td width="50%"> <table width="100%"> <tr> <th>Reference:</th> <td><?php echo $this->reference; ?></td> </tr> <tr> <th>Name:</th> <td></td><?php echo empty( $this->title ) ? '' : $this->title; ?> <?php echo empty( $this->first_name ) ? '' : $this->first_name; ?> <?php echo empty( $this->last_name ) ? '' : $this->last_name; ?></td> </tr> <tr> <th>Email:</th> <td><?php echo empty( $this->email ) ? '-' : $this->email; ?></td> </tr> <tr> <th>Telephone:</th> <td><?php echo empty( $this->daytime_phone ) ? '-' : $this->daytime_phone; ?></td> </tr> <tr> <th>Mobile:</th> <td><?php echo empty( $this->mobile_phone ) ? '-' : $this->mobile_phone; ?></td> </tr> </table> </td> <td width="50%"> <table width="100%"> <tr> <th>Address 1:</th> <td><?php echo empty( $this->address_1 ) ? '' : $this->address_1; ?></td> </tr> <tr> <th>Address 2:</th> <td><?php echo empty( $this->address_2 ) ? '' : $this->address_2; ?></td> </tr> <tr> <th>Town/City:</th> <td><?php echo empty( $this->city ) ? '' : $this->city; ?></td> </tr> <tr> <th>County:</th> <td><?php echo empty( $this->county ) ? '' : $this->county; ?></td> </tr> <tr> <th>Postcode:</th> <td><?php echo empty( $this->postcode ) ? '' : $this->postcode; ?></td> </tr> </table> </td> </tr> </table> </div> <div class="section payment border-top"> <p>Preferred Payment Method: <?php echo empty( $this->method ) ? '' : $this->method; ?></p> <?php if ( $this->method === 'Instant Bank Transfer' 😞 ?> <p>Write down your bank details below for the account in which you wish funds to be deposited.</p> <table width="100%"> <tr> <th width="25%">Bank:</th> <td width="75%" class="text-placeholder"> </td> </tr> <tr> <th>Name on Account:</th> <td width="75%" class="text-placeholder"> </td> </tr> <tr> <th>Sort Code:</th> <td width="75%" class="text-placeholder"> </td> </tr> <tr> <th>Account No:</th> <td width="75%" class="text-placeholder"> </td> </tr> </table> <?php endif; ?> </div> <div class="cut-note">Print this form, include the above part in your package and post to the address below.</div> <div class="section address cut-top"> <p> SMG<br><br> <?php echo empty( $this->send_address ) ? '' : $this->send_address ?> </p> </div> </body>
any help would be appreciated. Edited July 28 by Barandcode tags added Hi all, I'm new to PHP and just looking for any advice anyone might have on the following problem I'm having. I have created a database and tables for registering and logging in users. Each record has three different User Types (or roles): 1, 2 and 3. Once the session has started, I would like to make certain menu items available to certain User Types. I suppose it is some sort of if...elseif statement such as: <?php if($UserType==1) echo {"<p>Menu1</p>"} elseif($UserType==2) echo {"<p>Menu2</p>"} elseif($UserType==3) echo {"<p>Menu3</p>"}; ?> Would anybody be able to point me in the right direction? I'd really appreciate any help at all. Hi, I recently implemented a code to display user profile information. Well, it displays the username and password fine, but the edit function doesn't seem to be working. I edit the information, click submit, get a success message but the username and password didn't change. myprofile.php Code: [Select] <?php session_start(); include('config.php'); $sql = mysql_query( "SELECT * FROM users WHERE id='".$_SESSION['id']."'" ); echo "<h2>Profile</h2> <form method='post' action='editprofile.php'> <table>"; $row = mysql_fetch_array($sql); echo "<tr><th>Name: </th><td>".$row['username']."</td></tr> <tr><th>Password: </th><td><input type='password' value='".$row['password']."' disabled='true' /></td></tr>"; echo "</table><br /> <input type='submit' value='edit profile' /> </form>"; ?> editprofile.php Code: [Select] <?php include('config.php'); if(isset($_POST['btnedit'])){ $username = $_POST['username']; $password = $_POST['password']; $sql = mysql_query( "UPDATE users SET username='".$username."', password='".$password."' WHERE id='".$_SESSION['id']."'" ); if($sql){ echo "<script>alert('profile updated');window.location='myprofile.php'</script>"; }else{ echo "<script>alert('updating profile failed!');</script>"; } } $sql = mysql_query( "SELECT * FROM users WHERE id='".$_SESSION['id']."'" ); $row = mysql_fetch_array($sql); echo "<h2>Edit profile</h2> <form method='post'> <table> <tr><th>registered:</th><td><input type='text' name='username' value='".$row['username']."'/></td></tr> <tr><th>password:</th><td><input type='password' name='password' value='".$row['password']."'/></td></tr> </table><br /> <input type='submit' name='btnedit' value='update' /> </form>"; ?> Hi I was just wondering if someone could send me a good tutorial on pulling several fields from a table and displaying them all in one drop down menu for people to select one of them. I dont know what this is called to I dont know what to research online. I got some help here about 6 months ago with drop down menus & I need a little more. I'm working on a form that has about 20 drop down menus, each populated from a mysql database table with about 50 entries each. I need to keep the selected menu option on the form after the form is submitted but each time the form is submitted the selected menu option reverts back to the first item in the database table. Is there any practical way to fix this problem other than using javascript to finish up? Hi, I want to update user information in the database but it doesn't do anything. No data entered upon form submission. Please anyone if you can help would be great. Thank you. Code: [Select] <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $host = "";//edited out $database = ""; $username = ""; $password = ""; $tbl_name = "users"; $link = mysqli_connect($host, $username, $password); $conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error()); mysql_select_db($database); session_start(); IF (isset($_SESSION['userid'])){ $userid=$_SESSION['userid']; echo $userid; } //$currentUser = $_SESSION['myusername']; //do some cleanup// IF (isset($_POST['submit'])){ $first = $_POST['first']; $last = $_POST['last']; $dob = $_POST['dob']; $gender = $_POST['gender']; $country = $_POST['country']; $state = $_POST['state']; $town = $_POST['town']; $zip = $_POST['zip']; $email = $_POST['email']; $first = mysql_real_escape_string( '$first'); $last = mysql_real_escape_string( '$last'); $dob = mysql_real_escape_string( '$dob'); $gender = mysql_real_escape_string( '$gender'); $country = mysql_real_escape_string( '$country'); $state = mysql_real_escape_string( '$state'); $town = mysql_real_escape_string( '$town'); $zip = mysql_real_escape_string( '$zip'); $email = mysql_real_escape_string( '$email'); }; IF (isset($_SESSION['userid'])){ $userid=$_SESSION['userid']; } ELSE{ $getuserid=mysql_query ("SELECT id FROM users ORDER BY id DESC limit 1") or die(mysql_error()); WHILE ($gtuserid = mysql_fetch_array($getuserid)) { $theuserid=$gtuserid['id']; $userid=$theuserid; $_SESSION['userid']=$theuserid; $userid=$_SESSION['userid']; }//$getuserid }// IF ELSE (isset($_SESSION['userid'])) /////UPDATE SECTION///// IF (isset($_POST['submit'])){ mysql_query ( "UPDATE users SET firstname='$first', lastname='$last', dob = '$dob', gender='$gender', country='$country', state='$state', town='$town', zip='$zip', email='$email' WHERE id=$userid") or die(mysql_error()); }//IF ($_POST['update']=="Update") ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Connection</title> <style type="text/css"> body { font-family:Calibri; font-size:1em; } .title { font-size:1.6em; font-weight:strong; } .links a{ font-size::1.2em; text-decoration:none; } .links a:hover{ font-size::1.2em; color:#0066FF; text-decoration:none; } </style> </head> <body> <p><span class="title">Add your personal information/span></p> <form action="thebeast.php" method="post"> <p> <input type="text" name="first" size="20" id="first" /> First name<br /> <input type="text" name="last" size="20" id="name" /> Last name<br /> <input name="dob" type="text" size="20" id="dob" ; } ?> Date of Birth<br /> <input type="text" name="gender" size="20" id="gender" /> Gender <br /> <input type="text" name="country" size="20" id="country" /> Country<br /> <input type="text" name="state" size="20" id="state" /> State<br /> <input type="text" name="town" size="20" id="town" /> Town<br /> <input type="text" name="zip" size="20" id="zip" /> Zip Code<br /> <input type="text" name="email" size="40" id="email" /> Email<br /> <br /> <input type="submit" name="submit" value="Add your information" /> </form> </body> </html> I added some code last night that updates the "last_activity" field in the "member" table whenever the "body_header.inc.php" script is called, which means that pretty much whenever the User navigates to a new page or submits a form this field is updated. (I use this to kep my "User Online Status" up-to-date.) Everything was working fine until I suddenly started getting a "Cannot modify header" error before bed. Here is ONE sequence causing this error... - I am logged out - I am on http://local.debbie/index.php - I click on the "Log In" link - I am taken to http://local.debbie/members/log_in.php - I log in - I get this error... Quote Warning: Cannot modify header information - headers already sent by (output started at /Users/user1/Documents/DEV/++htdocs/05_Debbie/index.php:22) in /Users/user1/Documents/DEV/++htdocs/05_Debbie/components/body_header.inc.php on line 48 Here is part of my main index.php script... <?php //Build Date: 2012-03-08 // Initialize a session. session_start(); // Access Constants. require_once('config/config.inc.php'); // Set current Script Name. $_SESSION['returnToPage'] = $_SERVER['SCRIPT_NAME']; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!-- ################## DEBBIE ##################### --> <!-- HTML Metadata --> <title>Double Dee, Inc.</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- Page Stylesheets --> <link type="text/css" rel="stylesheet" href="css/_main.css" /> <link type="text/css" rel="stylesheet" href="css/_layout.css" /> <link type="text/css" rel="stylesheet" href="css/top_menu.css" /> <link type="text/css" rel="stylesheet" href="css/components.css" /> </head> <body> <div id="pageWrapper" class="clearfix"> <div id="pageInner"> <!-- BODY HEADER --> <?php require_once('components/body_header.inc.php'); ?> <!-- LEFT COLUMN --> <div id="pageLeftCol"> Here is a snippet from my body_header.inc.php script... <?php //Build Date: 2012-03-08 // ************************ // Update Last Activity. * // ************************ if ((isset($_SESSION['loggedIn'])) && ($_SESSION['loggedIn'] == TRUE)){ // Initialize Session. // session_start(); // Access Constants. // require_once('../config/config.inc.php'); // Initialize variables. $loggedIn = TRUE; $memberID = (isset($_SESSION['memberID']) ? $_SESSION['memberID'] : ''); // ************************ // Update Member Record. * // ************************ // Connect to the database. require_once(WEB_ROOT . 'private/mysqli_connect.php'); // Build query. $q1 = "UPDATE member SET logged_in=?, last_activity=now() WHERE id=? LIMIT 1"; // Prepare statement. $stmt1 = mysqli_prepare($dbc, $q1); // Bind variables to query. mysqli_stmt_bind_param($stmt1, 'si', $loggedIn, $memberID); // Execute query. mysqli_stmt_execute($stmt1); // Verify Update. if (mysqli_stmt_affected_rows($stmt1)!==1){ // Update Failed. $_SESSION['resultsCode'] = 'MEMBER_UPDATE_FAILED_2126'; // Redirect to Display Outcome. header("Location: " . BASE_URL . "members/results.php"); // End script. exit(); }//End of UPDATE MEMBER RECORD // Close prepared statement. mysqli_stmt_close($stmt1); // Close the connection. mysqli_close($dbc); /* */ }//End of UPDATE LAST ACTIVITY /* // Determine Current Script. $page = basename($_SERVER['REQUEST_URI']); if ($page == '') { $page = "index.php"; } */ // Determine Script Name. $scriptName = $_SERVER['SCRIPT_NAME']; ?> <!-- PAGE HEADER --> <div id="pageHeader"> <!-- COMPANY BRANDING --> <h1 id="companyLogo"> <!-- Display Logo if "Images On" --> <a href="/index.php"> <!-- Image Replacement Technique --> <span></span> </a> <!-- Display Text if "Images Off" --> DoubleDee, Inc: Tips on starting a Small-Business </h1> <!-- WELCOME MESSAGE --> <?php $firstName = (isset($_SESSION['memberFirstName']) ? $_SESSION['memberFirstName'] : ''); I was mindful of extra white space possibly causing the issue, but I don't see where it is?! The "Update Last Activity" code was added to my Header last night and is likely the culprit... Any ideas what is wrong?? Thanks, Debbie when i submit it, the only field that updates is the email field. UserEdit.php file <? /** * UserEdit.php * * This page is for users to edit their account information * such as their password, email address, etc. Their * usernames can not be edited. When changing their * password, they must first confirm their current password. * */ include("include/session.php"); ?> <html> <title>Edit Your Details</title> <link rel="stylesheet" type="text/css" href="../assets/css/styles.css" /> <link rel="stylesheet" type="text/css" href="../assets/css/forms.css" /> <link rel="stylesheet" type="text/css" href="../assets/css/layout.css" /> <link rel="stylesheet" type="text/css" href="../assets/css/style.css" /> <style> #form6 input{ margin:0; width:250px; border:1px solid #ddd; padding:3px 5px 3px 25px; } input{ font:100% Trebuchet MS, Arial, Helvetica, Sans-Serif; line-height:160%; color:#FFF; } #form6 input{background:#000; } </style> <body> <? /** * User has submitted form without errors and user's * account has been edited successfully. */ if(isset($_SESSION['useredit'])){ unset($_SESSION['useredit']); echo "<h1>User Account Edit Success!</h1>"; echo "<p><b>$session->username</b>, your account has been successfully updated. " ."<a href=\"index.php\">Main</a>.</p>"; } else{ ?> <? /** * If user is not logged in, then do not display anything. * If user is logged in, then display the form to edit * account information, with the current email address * already in the field. */ if($session->logged_in){ ?> <h2>User Account Edit : <? echo $session->firstname; ?></h2> <? if($form->num_errors > 0){ echo "<td><font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font></td>"; } ?> <form id="form6" action="process.php" method="POST"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr> <td>Email:</td> <td><input type="text" name="email" maxlength="50" value=" <? if($form->value("email") == ""){ echo $session->userinfo['email']; }else{ echo $form->value("email"); } ?>"> </td> <td><? echo $form->error("email"); ?></td> </tr> <tr> <td>Phone:</td> <td><input type="text" name="tel" maxlength="50" value=" <? if($form->value("tel") == ""){ echo $session->userinfo['tel']; }else{ echo $form->value("tel"); } ?>"> </td> <td><? echo $form->error("tel"); ?></td> </tr> <tr> <td>Address:</td> <td> <input type="text" name="address" maxlength="50" value=" <? if($form->value("address") == ""){ echo $session->userinfo['address']; }else{ echo $form->value("address"); } ?>" style="height: 138px"> </td> <td><? echo $form->error("address"); ?></td> </tr> <tr> <td>Company:</td> <td><input type="text" name="company" maxlength="50" value=" <? if($form->value("company") == ""){ echo $session->userinfo['company']; }else{ echo $form->value("company"); } ?>"> </td> <td><? echo $form->error("company"); ?></td> </tr> <tr><td colspan="2" align="right"> <input type="hidden" name="subedit" value="1"> <input type="submit" value="Edit Account"></td></tr> <tr><td colspan="2" align="left"></td></tr> </table> </form> <? } } ?> </body> </html> sends to session.php /** * editAccount - Attempts to edit the user's account information * including the password, which it first makes sure is correct * if entered, if so and the new password is in the right * format, the change is made. All other fields are changed * automatically. */ function editAccount($subcurpass, $subnewpass, $subemail, $subtel, $subaddress, $subcompany){ global $database, $form; //The database and form object /* New password entered */ if($subnewpass){ /* Current Password error checking */ $field = "curpass"; //Use field name for current password if(!$subcurpass){ $form->setError($field, "* Current Password not entered"); } else{ /* Check if password too short or is not alphanumeric */ $subcurpass = stripslashes($subcurpass); if(strlen($subcurpass) < 4 || !eregi("^([0-9a-z])+$", ($subcurpass = trim($subcurpass)))){ $form->setError($field, "* Current Password incorrect"); } /* Password entered is incorrect */ if($database->confirmUserPass($this->username,md5($subcurpass)) != 0){ $form->setError($field, "* Current Password incorrect"); } } /* New Password error checking */ $field = "newpass"; //Use field name for new password /* Spruce up password and check length*/ $subpass = stripslashes($subnewpass); if(strlen($subnewpass) < 4){ $form->setError($field, "* New Password too short"); } /* Check if password is not alphanumeric */ else if(!eregi("^([0-9a-z])+$", ($subnewpass = trim($subnewpass)))){ $form->setError($field, "* New Password not alphanumeric"); } } /* Change password attempted */ else if($subcurpass){ /* New Password error reporting */ $field = "newpass"; //Use field name for new password $form->setError($field, "* New Password not entered"); } /* Email error checking */ $field = "email"; //Use field name for email if($subemail && strlen($subemail = trim($subemail)) > 0){ /* Check if valid email address */ $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*" ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*" ."\.([a-z]{2,}){1}$"; if(!eregi($regex,$subemail)){ $form->setError($field, "* Email invalid"); } $subemail = stripslashes($subemail); } /* Errors exist, have user correct them */ if($form->num_errors > 0){ return false; //Errors with form } /* Update password since there were no errors */ if($subcurpass && $subnewpass){ $database->updateUserField($this->username,"password",md5($subnewpass)); } /* Change Email */ if($subemail){ $database->updateUserField($this->username,"email",$subemail); } /* Change Email */ if($subtel){ $database->updateUserField($this->username,"tel",$subtel); } /* Change Email */ if($subaddress){ $database->updateUserField($this->username,"address",$subaddress); } /* Change Email */ if($subcompany){ $database->updateUserField($this->username,"company",$subcompany); } /* Success! */ return true; } sends to database.php /** * updateUserField - Updates a field, specified by the field * parameter, in the user's row of the database. */ function updateUserField($username, $field, $value){ $q = "UPDATE ".TBL_USERS." SET ".$field." = '$value' WHERE username = '$username'"; return mysql_query($q, $this->connection); } think thats all you should need? Hello everyone, I am trying triple drop down menu first and second menus are working but third one is not working and also the data is not being displayed on the webpage even though I have used "echo" command.. I am unsure what is the problem and how to correct it. So I am attaching my code in this email, could you please look into it and help me with it. I have 1st drop menu for State : Tennessee Alabama Georgia 2nd Drop down list for County: Anderson Bredford Benton 3rd Drop down list for Genus Acer Aristida Eg: Tennnesse -> Anderson, Bredford, Benton and Anderson -> Acer, Aristida and when I select Tennesse->Anderson->Acer it has to display all the information of the table based on these selected values. Could you please help me with this. This is my link for the complete code http://pastebin.com/vvLrpCcr The execution link is http://sozog.utc.edu/~tdv131/MYSQL/genus1c.htm I am trying to insert a date into a mySQL table from html drop downs with php. Right now when I enter the date it goes into the database as 0000-00-00. Can anybody see why it might be doing this? My html: Code: [Select] <label for='birthdate' >Birthdate (Optional):</label><br/> <select name='month' id='month' value='<?php echo $fgmembersite->SafeDisplay('month') ?>'> <option value="01" selected="January">January</option> <option value="02">February</option> <option value="03">March</option> etc... </select> <select name='day' id='day' value='<?php echo $fgmembersite->SafeDisplay('day') ?>'> <option value="01" selected="1">1</option> <option value="02">2</option> <option value="03">3</option> etc... </select> <select name='year' id='year' value='<?php echo $fgmembersite->SafeDisplay('year') ?>'> <option value="2010" selected="2010">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> etc... </select> And my php to collect info: Code: [Select] $formvars['birthdate'] = $this->Sanitize($_POST['year'], $_POST['month'], $_POST['day']); php where I make table: Code: [Select] "birthdate DATE NOT NULL ,". php to insert into mysql: Code: [Select] $insert_query = 'insert into '.$this->tablename.'( name, address, birthdate, sex, program, guide, email, username, password, confirmcode ) values ( "' . $this->SanitizeForSQL($formvars['name']) . '", "' . $this->SanitizeForSQL($formvars['address']) . '", "' . $this->SanitizeForSQL($formvars['birthdate']) . '", "' . $this->SanitizeForSQL($formvars['sex']) . '", "' . $this->SanitizeForSQL($formvars['program']) . '", "' . $this->SanitizeForSQL($formvars['guide']) . '", "' . $this->SanitizeForSQL($formvars['email']) . '", "' . $this->SanitizeForSQL($formvars['username']) . '", "' . md5($formvars['password']) . '", "' . $confirmcode . '" )'; Thank you! I'm simply trying to set up a form where, if when a user clicks 'Submit', and then 'Back', the values from the form are preserved. My question is, how do I preserve the values of drop down menus. The following is a snippet of my code: Code: [Select] <select name="dropdown_dept" id="dept_list"> <option value=0><?php echo "Please select one..."?></option> <?php $dropdown_dept = "select dept_name from departments"; $result_dept = $db_conn->query($dropdown_dept); if (!$result_dept) { echo '<p>Unable to get department data.</p>'; return false; } for($i=0; $i<$result_dept->num_rows; $i++) { $app_name_row = $result_dept -> fetch_array(); ?> <option><?php echo($app_name_row[0]); ?></option> <? } ?> </select> Above is where I have set up a drop down menu of departments. Given that code, how can I preserve the department name after a user clicks 'Submit'? Hi I have an update page with multipule drop down menus, I am looking for a way to allow only the drop down menus that have been altered to be sent to the database. One way was to add the following code, where the $type_id equals 0 then add nothing to the database. Code: [Select] if ($type_id == 0) { $type_id = ""; } However I am getting a syntex error with this, if I enter a value into the $type_id it selects that fine. eg. Code: [Select] if ($type_id == 0) { $type_id = "2"; } What is the right way to send nothing to the database? Fuller code of the page is here <?php require_once("includes/sessions.php"); ?> <?php require_once("includes/connections.php"); ?> <?php require_once("includes/functions.php"); ?> <?php confirm_logged_in();?> <?php usersid(); ?> <?php find_selected_event(); find_selected_region(); ?> <?php $selected_event = getevent_byid ($url_eventid); $orgdescrip = orgdescription($url_eventid); $leveldescrip = leveldescription($url_eventid); $typedescrip = typedescription($url_eventid); $champdescrip = champdescription($url_eventid); $disdescrip = disdescription($url_eventid); $venuedescrip = venuedescription($url_eventid); $statusdescrip = statusdescription($url_eventid); ?> <?php if (!isset($new_event)) {$new_event = false;} ?> <?php // make sure the subject id sent is an integer if (intval($_GET['url_eventid']) == 0) { redirect_to('controlpanel.php'); } include_once("includes/form_functions.inc.php"); // START FORM PROCESSING // only execute the form processing if the form has been submitted if (isset($_POST['submit'])) { // initialize an array to hold our errors $errors = array(); // perform validations on the form data $required_fields = array('title'); $errors = array_merge($errors, check_required_fields($required_fields, $_POST)); $required_numberfields = array(); $errors = array_merge($errors, check_number_fields($required_numberfields, $_POST)); $fields_with_lengths = array(); $errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST)); // clean up the form data before putting it in the database $url_eventid = mysql_prep($_GET['url_eventid']); $user_id = mysql_prep($_POST['user_id']); $title = trim(mysql_prep($_POST['title'])); $event_details = mysql_prep($_POST['event_details']); $type_id = mysql_prep($_POST['type_id']); $champ_id = mysql_prep($_POST['champ_id']); $dis_id = mysql_prep($_POST['dis_id']); $org_id = mysql_prep($_POST['org_id']); $venue_id = mysql_prep($_POST['ven_id']); $level_id = mysql_prep($_POST['level_id']); $status_id = mysql_prep($_POST['status_id']); if ($type_id == 0) { $type_id = ""; } // Database submission only proceeds if there were NO errors. if (empty($errors)) { $sql = "UPDATE events SET \n" . "title = '{$title}',\n" . "event_details = '{$event_details}',\n" . "type_id = {$type_id},\n" . "champ_id = {$champ_id},\n" . "dis_id = {$dis_id},\n" . "org_id = {$org_id},\n" . "ven_id = {$venue_id},\n" . "user_id = {$url_userid},\n" . "level_id = {$level_id},\n" . "status_id = {$status_id}\n" . "WHERE event_id = {$url_eventid} \n" . "LIMIT 1"; if ($result = mysql_query($sql, $connection)) { // as is, $message will still be discarded on the redirect $message = "The event was successfully updated."; // get the last id inserted over the current db connection $new_event_id = mysql_insert_id(); redirect_to("newevent.php"); } else { $message = "I am sorry but the event could not be updated."; $message .= "<br />" . mysql_error(); } } else { if (count($errors) == 1) { $message = "There was 1 error in the form."; } else { $message = "There were " . count($errors) . " errors in the form."; } } // END FORM PROCESSING } ?> <?php /*THIS CODE WITH RETURN IN THE BROWSER THE URLS THAT ARE BEING PULLED DOWN*/ if(empty($_GET)) echo "No GET variables"; else print_r($_GET); ?> <?php include("includes/header.inc.php"); ?> <title>Horse Events</title> <?php include_once("includes/meta.inc.php");?> <?php include_once("includes/cssfavgoogle.inc.php");?> <link href="css/adminpanel.css" rel="stylesheet" type="text/css" /> <style> input[type="number"] { width:40px; } </style> </head> <body> <div id="wrapper"> <div id="header"> <img src="images/horseevents_wheretogo.png" align="right" /> <?php require_once ("includes/adminmenu.inc.php"); ?> </div> <div id="adminleft"> <h2>YOUR UPCOMING EVENTS <?php echo "<a href=\"newevent.php?url_userid={$url_userid}\"><img src=\"images/pink/add_event.png\" align=\"right\" width=\"131\" height=\"19\" /></a>" ?></h2> <table id="datetable" width="300" border="0" > <?php $event_users_set = get_upcomingeventsforuser ($url_userid); while ($eventid = mysql_fetch_array ($event_users_set)){ echo"<tr class=\'date\'>"; echo"<td>" . $eventid["stdate"] ."</td>"; echo"<td><a href=\"editevent.php?url_userid={$url_userid}&url_eventid=". urlencode ($eventid['event_id']) . "\">". $eventid ['title'] . "</td>"; echo"</tr></a>"; } ?> </table> <br /> <h2>YOUR PAST EVENTS</h2> <table id="datetable" width="300" border="0" > <?php $event_users_set = get_pasteventsforuser ($url_userid); while ($eventid = mysql_fetch_array ($event_users_set)){ echo"<tr class=\'date\'>"; echo"<td>" . $eventid["stdate"] ."</td>"; echo"<td><a href=\"editevent.php?url_userid={$url_userid}&url_eventid=". urlencode ($eventid['event_id']) . "\">". $eventid ['title'] . "</td>"; echo"</tr></a>"; } ?> </table> </div> <div id="admincontent"> <span class="h1pln">Edit Your Event</span><a class="delete" href="deleteevent.php?url_eventid=<?php echo $url_eventid; ?>" onClick="return confirm('Are you sure you want to delete?')">Delete</a><br /> <span class="h3pln">Please make sure you complete all the compulary fields<span class="compuls">*</span>.<br /> The more accurately you enter your event the more people will be able to then find it. <br /> <br /> If there are any selections we do not currently have available please click here and I will add them to your drop down menus.</span> <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?> <?php if (!empty($errors)) { display_errors($errors); } ?> <form id="newevent" action="editevent.php?url_eventid=<?php echo urlencode ($selected_event ['event_id']); ?>" method="post"> <table id="neweventdisplay" cellpadding="5" width="400" border="0"> <tr> <td><input type="text" name="event_id" value="<?php echo $url_eventid; ?>" /></td> <td><input type="text" name="user_id" value="<?php echo $url_userid; ?>" /></td> </tr> <tr> <td class="heading">Event Title</td> <td><input id="titleinput" name="title" type="text" value="<?php echo $selected_event ['title']; ?>" /><span class="compuls">*</span><span class="smalltext">Enter up to 36 characters</span></td> </tr> <tr> <td class="heading">Current Status</td> <td><?php echo $statusdescrip ['status_description']; ?> <select name="status_id" > <?php $status_set = findstatus(); $statuslist = mysql_fetch_assoc ($status_set); ?> <?php do { ?> <option value="<?php echo $statuslist ['status_id']; ?>" ><?php echo $statuslist ['status_description']; ?></option> <?php } while ($statuslist = mysql_fetch_assoc ($status_set)); ?></select> <span class="compuls">*</span></td> </tr> <tr> <td class="heading">Organiser</td> <td><?php echo $orgdescrip ['org_name']; ?> <select name="org_id"> <?php $organisers_set = findorganisers(); $orglist = mysql_fetch_assoc ($organisers_set); ?> <?php do { ?> <option value="<?php echo $orglist ['org_id']; ?>" ><?php echo $orglist ['org_name']; ?></option> <?php } while ($orglist = mysql_fetch_assoc ($organisers_set)); ?></select></td> </tr> <tr> <td class="heading">Start Date</td> <td id="dateinput"><?php echo $selected_event ['stdate']; ?></td> </tr> <tr> <td class="heading">Type Of Event</td> <td><?php echo $typedescrip ['type_description']; ?> <select name="type_id"> <?php $type_set = findtype(); $typelist = mysql_fetch_assoc ($type_set); ?> <?php do { ?> <option value="<?php echo $typelist ['type_id']; ?>" ><?php echo $typelist ['type_description'], $typelist ['type_id']; ?></option> <?php } while ($typelist = mysql_fetch_assoc ($type_set)); ?></select><span class="compuls">*</span></td> </tr> <tr> <td class="heading">Venue</td> <td><?php echo $venuedescrip ['ven_name']; ?><select name="ven_id"> <?php $venues_set = findvenues(); $venuelist = mysql_fetch_assoc ($venues_set); ?> <?php do { ?> <option value="<?php echo $venuelist ['ven_id']; ?>" ><?php echo $venuelist ['ven_name'], $venuelist ['ven_id']; ?></option> <?php } while ($venuelist = mysql_fetch_assoc ($venues_set)); ?></select></td> </tr> <tr> <td class="heading">Discipline</td> <td><?php echo $disdescrip ['dis_description']; ?><select name="dis_id"> <?php $discipline_set = finddisciplines(); $dislist = mysql_fetch_assoc ($discipline_set); ?> <?php do { ?> <option value="<?php echo $dislist ['dis_id']; ?>" ><?php echo $dislist ['dis_description'], $dislist ['dis_id']; ?></option> <?php } while ($dislist = mysql_fetch_assoc ($discipline_set)); ?></select><span class="compuls">*</span></td> </tr> <tr> <td class="heading">Level</td> <td><?php echo $leveldescrip ['level_description']; ?> <select name="level_id"> <?php $level_set = findlevels(); $levellist = mysql_fetch_assoc ($level_set); ?> <?php do { ?> <option value="<?php echo $levellist ['level_id']; ?>" ><?php echo $levellist ['level_description'], $levellist ['level_id']; ?></option> <?php } while ($levellist = mysql_fetch_assoc ($level_set)); ?></select></td> </tr> <tr> <td class="heading">Is This A Championship</td> <td><?php echo $champdescrip ['champ_description']; ?><select name="champ_id"> <?php $championship_set = findchampionships(); $champlist = mysql_fetch_assoc ($championship_set); ?> <?php do { ?> <option value="<?php echo $champlist ['champ_id']; ?>" ><?php echo $champlist ['champ_description'], $champlist ['champ_id']; ?></option> <?php } while ($champlist = mysql_fetch_assoc ($championship_set)); ?></select></td> </tr> <tr> <td class="heading">Event Details</td> <td><textarea name="event_details" cols="45" rows="15" ><?php echo $selected_event ['event_details']; ?> </textarea></td> </tr> <tr> <td class="heading">Upload Schedule</td> <td></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" id="convert" value="Update Your Event"></td> </tr> </table> <a class="delete" href="controlpanel.php">Cancel</a> </form> </div> <div id="adminright"> </div> <br clear="all" /> <?php require("includes/lowerlistings.inc.php"); ?> <?php require("includes/footer.inc.php"); ?> </div><!--End of Wrapper--> </body> </html> Hello,, I have looked for numerous examples, and have only got part of the answer. I have successfully populated a drop down list by reading the database. It populates with a list of quest titles. Once the user selects the quest. I want a textbox to populate with the Quest Description. I found an example that uses AJAX/PHP to do this, but it doesn't access a db to read/populate. The main code is in index.html The original example you select a country, and it populates a text field with the currency code. It passes a variable called $country to another file called find_ccode.php. I changed the first case in find_ccode.php to access my database, and populate the text box with quest description. Ideally I will like to make this case dynamic based off QuestID, would populate textbox with corresponding Quest Description (QDescrip). I then tried the other way in index.php I dynamically populated the dropdown list, and gave the option values the QuestIDs to be passed to $country, but something isn't working. I have a write files command to let me know what the $country variable is passing, and it never writes. It works in index.html though. I apologize in advance for my amateurish coding. I still have a lot to learn. I have included the code below, but if you know a more elegant way of doing it. I am creating a role-playing game, as you probably have figured out by now. I hope to one day put it on the web, but right now using it as a way of learning html, and PHP. I really want to know how to catch the value of the dropdown box. I would like to know what it is before sending over. also what is this.value. I assume this is what the value of the dropdown box is when you have selected something. I have been beating my head for days trying to figure this out. Any help is very much appreciated! Index.html <html> <head> <title>Changing textbox value based on dropdown list using Ajax and PHP</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script> // Developed by Roshan Bhattarai // Visit http://roshanbh.com.np for this script and more. // This notice MUST stay intact for legal use //fuction to return the xml http object function getXMLHTTP() { var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getCurrencyCode(strURL) { var req = getXMLHTTP(); if (req) { //function to be called when state is changed req.onreadystatechange = function() { //when state is completed i.e 4 if (req.readyState == 4) { // only if http status is "OK" if (req.status == 200) { document.getElementById('cur_code').value=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> </head> <body style="font: 12px Verdana, Arial, Helvetica, sans-serif;"> <form style="text-align:center" method="post" action="" name="form1"> <p style="color:#000099 ">When you change the dropdown list, the respective currency code of the country will be displayed in the textbox which is fetched from PHP using Ajax. </p> <p>Country : <select name="country" onChange="getCurrencyCode('find_ccode.php?country='+this.value)" <?php mysql_connect('localhost', '$user', '$password'); mysql_select_db('sok'); $result = mysql_query('select QuestID,QTitle, QDescrip from QuestList'); $options=""; while ($row=mysql_fetch_array($result)) { $QuestID=$row["QuestID"]; $QTitle=$row["QTitle"]; $options.="<OPTION VALUE=\"$QuestID\">".$QTitle; } ?> <option value="">Select Country</option> <option value="1">USA</option> <option value="2">UK</option> <option value="3">Nepal</option> </select><br/><br/> Currency : <input type="text" name="cur_code" id="cur_code" ></p> </form> </body> </html> Index.php <html> <head> <title>Changing textbox value based on dropdown list using Ajax and PHP</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script> // Developed by Roshan Bhattarai // Visit http://roshanbh.com.np for this script and more. // This notice MUST stay intact for legal use //fuction to return the xml http object function getXMLHTTP() { var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getCurrencyCode(strURL) { var req = getXMLHTTP(); if (req) { //function to be called when state is changed req.onreadystatechange = function() { //when state is completed i.e 4 if (req.readyState == 4) { // only if http status is "OK" if (req.status == 200) { document.getElementById('cur_code').value=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> </head> <body style="font: 12px Verdana, Arial, Helvetica, sans-serif;"> <form style="text-align:center" method="post" action="" name="form1"> <p style="color:#000099 ">When you change the dropdown list, the respective currency code of the country will be displayed in the textbox which is fetched from PHP using Ajax. </p> <p>Quest : <select name="country" getCurrencyCode('find_ccode.php?country='+this.value)">' <?php mysql_connect('localhost', '$user', '$password'); mysql_select_db('sok'); $result = mysql_query('select QuestID,QTitle, QDescrip from QuestList'); $options=""; while ($row=mysql_fetch_array($result)) { $QuestID=$row["QuestID"]; $QTitle=$row["QTitle"]; $options.="<OPTION VALUE=\"$QuestID\">".$QTitle; } $myFile = "test_catchoption.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $options); fclose($fh); ?> Choose your Quest <?=$options?> </SELECT> <br/><br/> Quest Description : <input type="text" name="cur_code" id="cur_code" ></p> </form> </body> </html> find_ccode.php <?php // Developed by Roshan Bhattarai // Visit http://roshanbh.com.np for this script and more. // This notice MUST stay intact for legal use $country=$_REQUEST['country']; $myFile = "testFilefindcc.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $country); fclose($fh); switch($country) { case "1" : mysql_connect('localhost', '$user', '$password'); mysql_select_db('sok'); $result = mysql_query("select * from QuestList where QuestID = '1'"); $row = mysql_fetch_assoc($result); echo $row['QDescrip']; break; case "2" : echo "GBP"; break; case "3" : echo "NPR"; break; } ?> Hey can anyone please help? I making this form on my website and I have two drop down lists, one is for sizes and the other is for colors. They both have an option for "other" and I'm wanting a textbox to appear when "other" is selected. I got the first drop down to work but I can't figure out how to get the second one to work without messing with the first. Here is the code I have please help: <form name="form1" method="post" action=""> <script type="text/javascript"> function showfield(name){ if(name=='Other')document.getElementById('div1').innerHTML='Other: <input type="text" name="other" />'; else document.getElementById('div1').innerHTML=''; } </script> <p>Size: <select name="size" id="size" onchange="showfield(this.options[this.selectedIndex].value)"> <option selected="selected">Please select ...</option> <option value="1' H X 6" W">2' H X 1' 6" W</option> <option value="1' H X 2' W">1' H X 2' W</option> <option value="1' H X 1' 4" W">1' H X 1' 4" W</option> <option value="Other">Other</option> </select> <div id="div1"></div> <p>Color: <select name="Color" id="Color" onchange="showfield(this.options[this.selectedIndex].value)"> <option selected="selected">Please select ...</option> <option value="Walnut Stain/Dark Brown">Walnut Stain/Dark Brown</option> <option value="Tan">Tan</option> <option value="Walnut">Walnut</option> <option value="Other">Other</option> </select> <div id="div1"></div> </p> Hello guys I've hit a problem whicle trying to validate my form. I have 3 drop down boxes where the user chooses from three options. But I can't seem to figure out how to set the validation so the user does not select the same option in each drop down. Can anyone help me solve this please. Thank you. <p><b>Course Choice 1</b> <select name="course1"> <option value="0"></option> <option value="Business computer Systems">Business computer Systems</option> <option value="Business computer Science">Business computer Science</option> <option value="Business computer Science (Games)">Business computer Science (Games)</option> <option value="Business Information Systems">Business Information Systems</option> <option value="Digital Media Development">Digital Media Development</option> <option value="Digital Media">Digital Media</option> </select></p> <p><b>Course Choice 2</b> <select name="course2"> <option value="Leave Blank">Leave Blank</option> <option value="Business computer Systems">Business computer Systems</option> <option value="Business computer Science">Business computer Science</option> <option value="Business computer Science (Games)">Business computer Science (Games)</option> <option value="Business Information Systems">Business Information Systems</option> <option value="Digital Media Development">Digital Media Development</option> <option value="Digital Media">Digital Media</option> </select></p> <p><b>Course Choice 3</b> <select name="course3"> <option value="Leave Blank">Leave Blank</option> <option value="Business computer Systems">Business computer Systems</option> <option value="Business computer Science">Business computer Science</option> <option value="Business computer Science (Games)">Business computer Science (Games)</option> <option value="Business Information Systems">Business Information Systems</option> <option value="Digital Media Development">Digital Media Development</option> <option value="Digital Media">Digital Media</option> </select></p> <div align="centre"><input type="submit" name="submit" value="send request" /></div> //Validate course choice 1 if (!empty($_REQUEST['course1'])) { $course1 = $_REQUEST['course1']; } else { $course1 = NULL; echo '<p><font color="red">Please enter your first choice</font></p>'; } //Validate course choice 2 if (!empty($_REQUEST['course2'])) { $course2 = $_REQUEST['course2']; } else { $course2 = NULL; echo '<p><font color="red">Please enter your second choice</font></p>'; } //Validate course choice 3 if (!empty($_REQUEST['course3'])) { $course3 = $_REQUEST['course3']; } else { $course3 = NULL; echo '<p><font color="red">Please enter your third choice</font></p>'; } //If everything is ok, print the message if ($name && $email && $course1 && $course2 && $course3) { echo "<p>Thank you, <b>$name</b>, You have chosen the following courses for information:<br /><br /> <b>$course1</b><br /> <b>$course2</b><br /> <b>$course3</b></p> <p>We will reply to you at <i>$email</i>.</p>\n"; } else { // One form element was not filled out properly echo '<p><font color="red">Please go back and fill out the form again.</font></p>'; } Hi there im going a little bit mad now.... i spent a while trying to work out why my form didnt update or redirect... After head scratching i remade a test form... That also doesnt update or redirect?? I must be missing something here?? So basically when the user clicks submit nothing happens, why?? Code: [Select] <?php require_once('Connections/swb.php'); ?> <?php session_start(); if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE player SET `Day`=%s WHERE PlayerName=%s", GetSQLValueString($_POST['days'], "int"), GetSQLValueString($_POST['playername'], "text")); mysql_select_db($database_swb, $swb); $Result1 = mysql_query($updateSQL, $swb) or die(mysql_error()); $updateGoTo = "logout.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST"> <input type="button" value="End Turn" /> <input name="days" type="hidden" id="days" value="1"/> <input name="playername" type="hidden" id="playername" value="<?php echo $_SESSION['MM_Username']; ?>"> <input type="hidden" name="MM_update" value="form1"> </form> </body> </html> Thanks I can't get my form to update the database with user personal information. Any help greatly appreciated. Upon submitting the form, it just reloads the page, no information added to the DB. I used the update statement because I want the users to be able to update the info at a later date. Not sure if that was the right thing to do. thank you. Code: [Select] <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); include('bouncer.php'); $host = ""; $database = ""; $username = ""; $password = ""; $tbl_name = "users"; $conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error()); if($conn) { mysql_select_db($database); } else { echo "failed to select database"; } $currentUser = $_SESSION['myusername']; // get user from login and make it current user to use for update statement echo "Login success!<br/>"; echo "Please fill out the form below to add your personal information to the database<br/>"; ////////////////////////////////////////////////////////////////////////////////////////////////// if(isset($_POST['submit'])) { $firstname = mysql_real_escape_string( $_POST['first']); $lastname = mysql_real_escape_string( $_POST['last']); $dob = mysql_real_escape_string( $_POST['dob']); $gender = mysql_real_escape_string( $_POST['gender']); $result= mysql_query ( "UPDATE users SET firstname = '$firstname', lastname = '$lastname', dob = '$dob', gender='$gender' WHERE username='$currentUser'") or die(mysql_error()); if($result) { echo "your information was updated in the database and is as follows <br/>"; //put the results on the screen echo "<br/> $firstname <br/>"; echo "<br/>$lastname <br/>"; echo "<br>$dob <br/> "; echo ">$gender <br>"; } else { echo "error, could not update your info to the database </br>";//end if result } }//end if sumbit post statement at top ?> <html> <body> <p> </p> <p> </p> <p> <form action="login_successERROR.php" method="post"> <p> <input type="text" name="first" size="20" /> First name<br /> <input type="text" name="last" size="20" /> Last name<br /> <input name="dob" type="text" size="20" id="dob" /> Date of Birth<br /> <input type="text" name="gender" size="20" id="gender" /> Gender <br /> <input type="submit" value="Add personal information to database" /> <input type="reset" value="Reset fields" /> </p> </p> </form> <p><a href="index.php">HOME</a></p> <p> </p> </body> </html> Code: [Select] <?php $host="xxxx"; // Host name $username="xxxx"; // Mysql username $password="xxxx"; // Mysql password $db_name="xxxx"; // Database name $tbl_name="xxxx"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // get value of id that sent from address bar $model_id=$_GET['model_id']; // Retrieve data from database $sql="SELECT model_id, model_name, location, email_1 FROM $tbl_name WHERE model_id='$model_id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <form name="form1" method="post" action="updated.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td> </td> <td colspan="3"><strong>Update data in mysql</strong> </td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> </tr> <tr> <td align="center"> </td> <td align="center"><strong>Name</strong></td> <td align="center"><strong>Location</strong></td> <td align="center"><strong>Email</strong></td> </tr> <tr> <td> </td> <td align="center"><input name="name" type="text" id="name" value="<? echo $rows['model_name']; ?>"></td> <td align="center"><input name="location" type="text" id="location" value="<? echo $rows['location']; ?>"></td> <td><input name="email" type="text" id="email" value="<? echo $rows['email_1']; ?>"></td> </tr> <tr> <td> </td> <td><input name="id" type="hidden" id="id" value="<? echo $rows['model_id']; ?>"></td> <td align="center"><input type="submit" name="Submit" value="Submit"></td> <td> </td> </tr> </table> </td> </form> </tr> </table> <? // close connection mysql_close(); ?> This is the part that isn't working Code: [Select] <td align="center"><input name="name" type="text" id="name" value="<? echo $rows['model_name']; ?>"></td> <td align="center"><input name="location" type="text" id="location" value="<? echo $rows['location']; ?>"></td> <td><input name="email" type="text" id="email" value="<? echo $rows['email_1']; ?>"></td> The echo values aren't being fetched and left blank when I run the script. Any ideas? I want to write a guessing game that gives a user four tries to guess a number between 1 and 10. The problem is that every time the user hits submit, count is reset to zero and 1 is added. Please help. Here is my code: <html> <head> <title>Guessing Game </title> </head> <h1>Guessing Game </h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="hidden" name="count" value="<?php $count++; ?>" /> <p><input type="text" name="guess" /></p> <p><input type="submit" value="Guess" /></p> </form> </body> </html> <?php $random = rand(1,10); $guess = $_POST['guess']; if ($guess >= 10) { echo"Guess has to be lower than 10"; } elseif (isset($guess) && ($guess <= 1)) { echo "Guess has to be higher than 1"; } else { if ($guess == $random) { echo "Congratulations. You Win!!!!"; $count = 4; } elseif (isset($guess) && ($guess != $random)) { echo "Try again"; $count++; } elseif (($count == 4) && ($guess != $random)) { echo "Game Over. You Lose!!!"; } } ?> |