PHP - Default Value In Combobox For Edit Data In Form
I trying to display data from a database for editing
I have 2 table: 1. tbl_proizvodi_karakteristike (Translate: tbl_product_caracteristics) - In this table i have list of product caracteristic relatet to product 'id' in table 'tbl_product_list' (this 'tbl_product_list' is not important now) - field: id, opis, vrednsot, proizvod_id 2. tbl_karakteristike (Translate: tbl_caracteristic) - In this table i have list of all caracteristic - field: id, opis in field 'opis' in table 'tbl_proizvodi_karakteristike' i insert 'id' from 'tbl_karkateristike' and that works ok with combo box. But, when i try to edit value in 'tbl_proizvodi_karakteristike', i do not know how to show current value in combo box (i have list of value from 'tbl_karakteristike' in combox, starting from first) For examle, if i know that value in selected caracteristics is 'opis = 25', it means that i in combo box on load edit form mast have first value 25 and rest of posible value. For now i have value '1 and rest of value' Hiar is current code in edit form Code: [Select] <form action='product_carasteristic.php?product_id=<?php echo $p_id; ?>&product_name=<?php echo $p_name; ?>' method='POST'> <?php $p_id = $_GET['id']; $karakteristike = mysql_query("SELECT * FROM `tbl_proizvodi_karakteristike` WHERE `id`='$p_id'") or die(mysql_error()); while($row = mysql_fetch_array($karakteristike)){ $p_id = $row['id']; $p_opis = $row['opis']; $p_vrednost = $row['vrednost']; $p_proizvod_id = $row['proizvod_id']; ?> <table> <tr> <td > Karakteristika </td> <td> <select name="opis" style="font-family: verdana; font-size:15px; width:342px;"> <?php $tbl_karakteristike = mysql_query("SELECT * FROM `tbl_karakteristike`") or die(mysql_error()); while($row = mysql_fetch_array($tbl_karakteristike)){ $k_id = $row['id']; $k_opis = $row['opis']; ?> <option value='<?php echo $k_id; ?>'><?php echo $k_opis; ?></option> <?php } ?> </select> </td> </tr> <tr> <td> Vrednost karakteristike </td> <td> <input type="text" name="vrednost" value='<?php echo $p_vrednost; ?>'> </td> </tr> <tr> <td> <input type="submit" name="submit" value="Kreiraj"> </td> <td> Neophodno je popuniti sva polja </td> </tr> </table> <?php } ?> </form> thanks forward Similar TutorialsI have a simple form that edits student information. I have several fields that I have a drop down list pulled as an array from a separate table. I would like the information that is already entered on the student to be the default but still have the drop down list available if the item was entered in error. For example: Drop down list of all the states of America, OH was entered for the student, when the edit form comes up for State in Address I would like OH to be the default but still have the list to choose if OH was entered in error. I have tried selected = $selected but then the entire drop down changed to OH. I am very, very much a beginner in this <?php // list of possible modules comes from database $state_array=get_states(); //display as a drop down list for end user to choose if (!is_array($state_array)) { echo "<p>No States are currently available<p>"; return; } foreach ($state_array as $row) { echo "<option value=\"".($row['stateid'])."\""; // if existing state, put in current catgory echo "<strong> ".($row['stateid'])."</strong><br />"; echo "<option select=\"selected\">OH"; } ?> Gang, I'm trying to create a form that allows me to edit table data within a MySQL database. I've been able to display the data, no problem. I want to be able to edit the fields in the database tables but have had no luck. I'm using session variables to connect and gather the information I need. Here's the code for collecting the table data: <?php mysql_select_db($database); if(empty($database)) { echo "<p>You must be connected to a database in order to view any table data.</p>"; }else{ // Show table data start $sql = "SHOW TABLES FROM $database"; $result = mysql_query($sql); $table = array(); while ($row = mysql_fetch_row($result)) { $table[] = $row[0]; } if (count($table) == 0) { echo "<p>The database '" . $database . "' contains no tables.</p>\n"; } else { foreach($table AS $aTable) { echo "<p style='text-align:left;float:left;width:100%;margin-top:15px;'>Table: <font color='green'>$aTable</font>"; if (!mysql_connect($hostname, $user, $passwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // sending query $result = mysql_query("SELECT * FROM {$aTable}"); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); echo "<div style='text-align:left;width:100%;'><table border='0'><tr><td></td>"; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td style='text-align:left;padding:3px;font-size:11px;color:green;'>{$field->name}</td>"; } echo "</tr>\n"; // printing table rows while($row = mysql_fetch_row($result)) { echo "<tr><td style='text-align:center;padding:3px;font-size:10px;border:1px solid #888;background:#fff;'><a href='edit_data.php?=$row[0]' style='color:red;text-decoration:none;'>edit</a></td>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo "<td style='text-align:left;padding:3px;font-size:10px;border:1px solid #888;background:#fff;clear:both;float:left;'>$cell</td>"; echo "</tr>\n"; } mysql_free_result($result); echo "</table></div>"; } } } //end show table data include("includes/footer.php"); ?> I'm not sure how to create a form using the session variables in order to be able to edit the correct information since I want to edit numerous databases. Any help would be great! Thanks This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=322008.0 Hi there I never had any php lessons. But I made a site, and now I'm kinda sorta working on a CMS so that someone else can edit the information on the site. Now I was wondering if there was a simple way of displaying all the data from a table, and editing it (not in phpmyadmin). This is my current method; it's rather sloppy but it works like a charm: Code: [Select] mysql_select_db('yourdatabase')or die(mysql_error()); $query = mysql_query("SELECT * FROM activiteit ORDER BY datum"); if(isset($_POST['editActiviteit'])){ $id = mysql_real_escape_string(htmlentities($_POST['id'])); }else{ $id = ''; } echo "<table border='1'><tr><th>Begindatum</th><th>Einddatum</th><th>Titel</th><th>Omschrijving</th><th>Zichtbaar?</th><th>Aanpassen</th><th>Verwijderen</th><th>Voorbeeld</th></tr>"; while($row = mysql_fetch_array($query)){ if($id == $row['id']){ if(empty($row['einddatum'])){ $einddatum = "<input type='text' size='2' name='activiteitDagEind' placeholder='dd' />/<input type='text' size='2' maxlength='2' name='activiteitMaandEind' placeholder='mm' />/<input typ='text' size='4' maxlength='4' name='activiteitJaarEind' placeholder='jjjj' />"; }else{ $explode = explode('/',$row['einddatum']); $einddatum = "<input type='text' size='2' name='activiteitDagEind' value='$explode[0]' />/<input type='text' size='2' maxlength='2' name='activiteitMaandEind' value='$explode[1]' />/<input typ='text' size='4' maxlength='4' name='activiteitJaarEind' value='$explode[2]' />"; } $explode2 = explode('/',$row['datum']); $datum = "<input type='text' size='2' name='activiteitDag' value='$explode2[0]' />/<input type='text' size='2' maxlength='2' name='activiteitMaand' value='$explode2[1]' />/<input typ='text' size='4' maxlength='4' name='activiteitJaar' value='$explode2[2]' />"; if($row['actief'] == 0){ $actief = "<select name='actief'><option value='1'>1</option><option value='0' selected='selected'>0</option></select>"; }else{ $actief = "<select name='actief'><option value='1' selected='selected'>1</option><option value='0'>0</option></select>"; } echo "<form action='ward.php' method='post'>"; echo "<tr><td>$datum</td><td>$einddatum</td><td><input type='text' name='activiteitTitel' value='".$row['titel']."' /></td><td><textarea name='activiteitOmschrijving'>".$row['omschrijving']."</textarea></td><td>$actief</td><td><input type='hidden' value='".$row['id']."' name='id' /><input type='submit' value='Slaag op' name='saveActiviteit' /></form></td><td><form action='ward.php' method='post'><input type='hidden' value='".$row['id']."' name='id' /><input type='submit' name='verwijderActiviteit' value='verwijderen' /></form></td><td><input type='button' disabled='disabled' value='Voorbeeld' /></td></tr>"; }else{ echo "<tr><td>".$row['datum']."</td><td>".$row['einddatum']."</td><td>" . $row['titel'] . "</td><td>" . bbcode_format($row['omschrijving']) . "</td><td>" . $row['actief']."</td><td><form action='ward.php?fx=activiteit' method='post'><input type='hidden' value='".$row['id']."' name='id' /><input type='submit' value='Pas aan' name='editActiviteit' /></form></td><td><form action='ward.php' method='post'><input type='hidden' value='".$row['id']."' name='id' /><input type='submit' value='verwijderen' name='verwijderActiviteit' /></form></td><td><input type='button' value='Voorbeeld' onClick=\"parent.location='ward.php?fx=activiteit&voorbeeld=".$row['id']."'\" /></td></tr>"; } } echo "</table><br /><br />"; I just copy pasted all the code but I'll explain it in big lines: First I open a table. I manually enter a row with the headers. Then every result of the query gets shown in a cell. The last cells of each row contain a delete and an edit button. The delete button deletes that row with the hidden id and reloads the page. When the edit button is clicked, it sends a form with the name of the button, here 'editActiviteit', and the id of the entry. And then the page gets reloaded. When the query is then done again, it checks if $_POST['editActiviteit'] is set, and if it is, it displays input fields with the values in the cells instead of pure text, and a save button instead of a edit button. The system works just fine, but it's heaps of work every time I implement it, for activities, users, ... Also I've been told that table's are not the correct way for displaying results (and they also get a little stretched). How should it be displayed? Thanks in advance. Hi, I have a webpage that the super administrator log's into. Once the super administrator is logged in he/she can view his/her clients. The super admins clients also have their own clients, once the super admins clients login they can view their own clients details who register with them. What i am trying to do is have a link on that clients name (for the super admins clients) that will bring me to a new page where i can edit his/her details that is stored in the mysql database. I have used INPUT buttons for each clients row in a FORM which works......but i know this is not the right way to do it. This is the code i have used to display the clients with the input button: <?php $query = "SELECT ID FROM clients WHERE username = '$username'"; $result = mysql_query($query); if(mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)){ $userID = $row['ID']; $query = "SELECT * FROM users WHERE userID = '$userID'"; $result = mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table border="0" cellspacing="3" cellpadding="3" width="100%"> <tr> <th width="30%"><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Username</font></th> <th><font face="Arial, Helvetica, sans-serif">Email Address</font></th> <th> </th> </tr> <?php $i=0; while ($i < $num) { $userID=mysql_result($result,$i,"userID"); $name=mysql_result($result,$i,"name"); $username=mysql_result($result,$i,"username"); $email=mysql_result($result,$i,"email"); ?> <tr> <td width="30%"><?php echo $name; ?></td> <td><?php echo $username; ?></td> <td><?php echo $email; ?></td> <td><form action="http://localhost/single-client.php?userID=<?php echo $userID; ?>&name=<?php echo $name; ?>" method="post" style="margin:0px;"> <input type="hidden" name="selectuser" id="selectuser" value="<?php echo $userID; ?>" /><input type="hidden" name="username1" id="username1" value="<?php echo $username; ?>" /><input type="hidden" name="name1" id="name1" value="<?php echo $name; ?>" /><input type="submit" name="submit" value="View Info" class="button" /></form></td> </tr> <?php $i++; }}} ?> </table> From the above code when i use the following code: ?userID=<?php echo $userID; ?>&name=<?php echo $name; ?> It doesn't make a difference .... it just displays the correct userID and name in the link. Once the INPUT button is clicked it will bring you to this page: <?php $query = "SELECT * FROM users WHERE userID = '".$_POST['selectuser']."' AND username = '".$_POST['username1']."'"; $result = mysql_query($query); if(mysql_num_rows($result)) { $userID = $_POST['selectuser']; while($row = mysql_fetch_assoc($result)){ $name = $row['name']; $userID = $row['userID']; $email = $row['email']; $username = $row['username']; $registered = $row['registered']; $last = $row['last']; ?> <?php echo $brokerID; ?> <table border="0" cellspacing="3" cellpadding="3" width="100%" summary="Client table"> <tr> <td><form action="http://localhost/single-client.php?userID=<?php echo $userID; ?>&name=<?php echo $name; ?>" method="post" style="margin:0px;"> <input type="hidden" name="selectuser" id="selectuser" value="<?php echo $userID; ?>" /><input type="hidden" name="username1" id="username1" value="<?php echo $username; ?>" /><input type="hidden" name="name1" id="name1" value="<?php echo $name; ?>" /><input type="submit" name="submit" value="Income" class="button" /></form></td> <td><form action="http://localhost/single-client.php?userID=<?php echo $userID; ?>&name=<?php echo $name; ?>" method="post" style="margin:0px;"> <input type="hidden" name="selectuser" id="selectuser" value="<?php echo $userID; ?>" /><input type="hidden" name="username1" id="username1" value="<?php echo $username; ?>" /><input type="hidden" name="name1" id="name1" value="<?php echo $name; ?>" /><input type="submit" name="submit" value="Bills" class="button" /></form></td> </tr> </table> <h2>Client Profile - <?php echo $_POST['name1']; ?></h2> <table border="0" cellspacing="3" cellpadding="3" width="100%"> <tr> <th><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Username</font></th> <th><font face="Arial, Helvetica, sans-serif">Email Address</font></th> <th><font face="Arial, Helvetica, sans-serif">Registered</font></th> <th><font face="Arial, Helvetica, sans-serif">Last</font></th> </tr> <tr> <td><?php echo $name; ?></td> <td><?php echo $username; ?></td> <td><?php echo $email; ?></td> <td><?php echo $registered; ?></td> <td><?php echo $last; ?></td> </tr> </table> <?php } } else { echo "<p>Error</p>"; } ?> This page displays the correct user info. Is there a way to do it differently instead of using FORMS and INPUT buttons? and rather using links? Any help would be greatly appreciated. I have a form on our website that a user can fill out for custom product. I want the form data to be 1) stored into a mysql database AND after storing said data, 2) email the same data to our sales department. 1) The form data DOES get stored into mysql database (except for the first two fields, for some weird reason) 2) I added a "mail" section to the php file that stores the data into the database, but it is not working correctly. I have stripped the email portion down to sending just one of the fields in the "message" to make it easier for troubleshooting I have included here, both the form section of the html file, and the formdata.php file that processes the data for your analysis. I am relatively new to php so there are going to be some issues with security, but I can work on those after I get the store & email process to work correctly. Please review my code and see if anyone can be of assistance. I looked through the forums and couldn't find another issue that was the same as mine. If I just overlooked, please tell me the thread post #. Thanks THE FORM WHICH COLLECTS THE DATA ******************************* <form method=POST action=formdata.php> <table width="640" border=0 align="center"> <tr> <td align=right><b>First Name</b></td> <td><input type=text name=FName size=25></td> <td><div align="right"><b>Telephone</b></div></td> <td><input type=text name=Tel size=25></td> </tr> <tr> <td align=right><b>Last Name</b></td> <td><input type=text name=LName size=25></td> <td><div align="right"><b>Fax</b></div></td> <td><input type=text name=Fax size=25></td> </tr> <tr> <td align=right><b>Title</b></td> <td><input type=text name=Title size=25></td> <td><div align="right"><b>Email</b></div></td> <td><input type=text name=Email size=50></td> </tr> <tr> <td align=right><b>Company</b></td> <td><input type=text name=Comp size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Address</b></td> <td><input type=text name=Addr size=25></td> <td><div align="right"><b>Estimated Annual Volume</b></div></td> <td><input type=text name=EAV size=25></td> </tr> <tr> <td align=right><b>City</b></td> <td><input type=text name=City size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>State/Province</b></td> <td><input type=text name=SProv size=25></td> <td><div align="right"><b>Application</b></div></td> <td><input type=text name=Appl size=25></td> </tr> <tr> <td align=right><b>Country</b></td> <td><input type=text name=Ctry size=25></td> <td><div align="right"><b>Type of System</b></div></td> <td><input type=text name=Syst size=25></td> </tr> <tr> <td align=right><b>Zip/Postal Code</b></td> <td><input type=text name=ZPC size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td><div align="right"><strong><font color="#FFFF00" face="Arial, Helvetica, sans-serif">COIL DESIGN</font></strong></div></td> <td><font color="#FFFF00" face="Arial, Helvetica, sans-serif"><strong>PARAMETERS</strong></font></td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Primary Resistance (ohms)</b></td> <td><input type=text name=Pres size=25></td> <td><div align="right"><b>Primary Inductance (mH)</b></div></td> <td><input type=text name=Pind size=25></td> </tr> <tr> <td align=right><b>Secondary Resistance (ohms)</b></td> <td><input type=text name=Sres size=25></td> <td><div align="right"><b>Secondary Inductance (H)</b></div></td> <td><input type=text name=Sind size=25></td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Peak Operating Current (Amps)</b></td> <td><input type=text name=POC size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Output Energy (mJ)</b></td> <td><input type=text name=Egy size=25></td> <td><div align="right"><b>Output Voltage (kV)</b></div></td> <td><input type=text name=Volt size=25></td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b># HV Towers per Coil</b></td> <td><input type=text name=TPC size=25></td> <td><div align="right"><b># of Coils per Package</b></div></td> <td><input type=text name=CPP size=25></td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <th colspan=4><b>Please enter any additional information he </b></th> </tr> <tr> <th colspan=4><textarea name=Mess cols=50 rows=10 id="Message"></textarea></th> </tr> </table> </dl> <div align="center"> <p> <input type=hidden name=BodyTag value="<body bgcolor="#484589" text="#FFFFFF" link="#FFFF00" alink="#FFFFFF" vlink="#FF7F00">"> <input type=hidden name=FA value=SendMail> </p> <p><font color="#FFFF00" face="Arial, Helvetica, sans-serif"><strong>PLEASE MAKE SURE ALL INFORMATION<br> IS CORRECT BEFORE SUBMITTING</strong></font></p> <p> <input type=submit value="Submit Form"> </p> </div> </form> THE FILE THAT PROCESSES THE FORM DATA (formdata.php) *********************************************** <?php $con = mysql_connect("localhost","XXX","XXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("customform", $con); $sql="INSERT INTO formdata (Fname, Lname, Title, Comp, Addr, City, SProv, Ctry, ZPC, Tel, Fax, Email, EAV, Appl, Syst, Pres, Pind, Sres, Sind, POC, Egy, Volt, TPC, CPP, Mess) VALUES ('$_POST[Fname]','$_POST[Lname]','$_POST[Title]','$_POST[Comp]','$_POST[Addr]','$_POST[City]','$_POST[SProv]','$_POST[Ctry]','$_POST[ZPC]','$_POST[Tel]','$_POST[Fax]','$_POST[Email]','$_POST[EAV]','$_POST[Appl]','$_POST[Syst]','$_POST[Pres]','$_POST[Pind]','$_POST[Sres]','$_POST[Sind]','$_POST[POC]','$_POST[Egy]','$_POST[Volt]','$_POST[TPC]','$_POST[CPP]','$_POST[Mess]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Your Information Was Successfully Posted"; mysql_close($con); $to = "recipient email address here"; $subject = "Custom Form"; $email = $_POST['Email'] ; $message = $_POST['Comp'] ; $headers = "From: $Email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=316203.0 I HAVE TRIED looking at it but i am new to php so i can't figure out what i did wrong help please !!!!!!!!!!!! Fatal error: Call to undefined method modernCMS::update_form() in C:\wamp\www\test\inc\update-content.php on line 4 ---- Page that's accessing code ----- <?php include '../test/inc/admin/nav.php'; echo $obj->update_form($_GET['id']); ?> ------ function ------ <?php class modernCMS { var $host; var $username; var $password; var $db; function connect() { $con = mysql_connect($this->host, $this->username, $this->password) or die(mysql_error()); mysql_select_db($this->db, $con) or die(mysql_error()); } //end connect function get_content($id = '') { if($id != ""): $id = mysql_real_escape_string($id); $sql = "SELECT * FROM cms_content WHERE id = '$id'"; // $return = "<p><a href=../test/inc/admin/nav.php>Go Back To Content</a></p>"; else: $sql = "SELECT * FROM cms_content ORDER BY id DESC"; endif; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) != 0): while($row = mysql_fetch_assoc($res)) { echo '<table bgcolor="#975627" width="100%" border="0" cellspacing="1" cellpadding="3"> <tr> <td height="25" background="images/menu.gif"><center><strong>' . $row['title'] . '</strong></center></td> </tr> <tr bgcolor="975627"><td height="0"></td></tr> <tr> <td bgcolor="#181818"> '; echo '<br> <div align="center">' . $row['body'] . ' <br><br> </td> </tr> <tr> <td height="25" background="images/menu.gif"> </td> </tr> </table><br><br> '; } else: echo '<p>Uh Oh!!! </p>'; endif; // echo $return; } //end get_content function add_content($p) { $title = mysql_real_escape_string($p['title']); $body = mysql_real_escape_string($p['body']); if(!$title || !$body): if(!$title): echo "<p>The title is required!</p>"; endif; if(!$body): echo "<p>The body is required!</p>"; endif; echo '<p><a href="add-content.php">Try Again!!!</a></p>'; else: $sql = "INSERT INTO cms_content VALUES (null, '$title', '$body')"; $res = mysql_query($sql) or die(mysql_error()); echo "Added Successfully!"; endif; } //end add_content function manage_content() { $sql = "SELECT * FROM cms_content ORDER BY id DESC"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)): ?> <div> <h2 class="title"><?php echo $row['title']; ?></h2> <span class="actions"<a href="../test/update-content.php?id=<?php echo $row['id']?>">Edit</a> | <a href="?delete= <?php echo $row['id'] ?> ">Delete</a></span> </div> <?php endwhile; echo '</div>'; //Class Manage Div } //end manage_content function delete_content($id) { if(!$id) { return false; }else { $id = mysql_real_escape_string($id); $sql = "DELETE FROM cms_content WHERE id = '$id'"; $res = mysql_query($sql) or die(mysql_error()); echo "Content Deleted Successfully!"; } } } //end delete_content function update_form($id) { $id = mysql_real_escape_string($id); $sql = "SELECT * FROM cms_content WHERE id = '$id'"; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res); ?> <form method="post" action="./post-added.php"> <input type="hidden" name="update" value="true" /> <input type="hidden" name="id" value="<?php $row['id'] ?>" /> <div> <label for="title">Title:</label> <input type="text" name="title" id="title" value="<?php echo $row['title'] ?>" /> </div> <div> <label for="body">Body:</label> <textarea name="body" id="body" rows="8" cols="40" /><?php echo $row['body'] ?></textarea> </div> <input type="submit" name="submit" value="Update Content" /> </form> <?php } //end update_content_form function update_content($p) { $title = mysql_real_escape_string($p['title']); $body = mysql_real_escape_string($p['body']); $id = mysql_real_escape_string($p['id']); if(!$title || !$body): if(!$title): echo "<p>The title is required!</p>"; endif; if(!$body): echo "<p>The body is required!</p>"; endif; echo '<p><a href="update-content.php?id=' . $id . '">Try Again!!!</a></p>'; else: $sql = "UPDATE cms_content SET title = '$title', body = '$body' WHERE id = '$id'"; $res = mysql_query($sql) or die(mysql_error()); echo "Updated Successfully!"; endif; } //end update_content($p) ?> Hello, freaks. I need a little help with the best way to go about this. I have a field in mysql that contains a comma separated string of values. What I need to do is get those values out of the db and list them into editable text fields so the user can update the values in a html form. So far this is my code, I left out all the in betweens - validation, results, etc - for this post...but its there . SELECT servs FROM services WHERE id = $a_id $services = $row['servs']; $srvs = explode(',', $services); Then for the form: <?php foreach ($srvs as $service) { ?> <input type="text" name="servs[]" value="<?php echo $service ?>" /> <?php } ?> This gives me a text field for each value of servs, great! But the problem is, the user can enter up to 15 servs. Some currently have less than that saved in the db. I want to give them the ability to 1. edit any of the current servs value and 2. add more values if they have less than 15. My question is, how do I echo out 15 editable text fields for servs[] no matter the number of values they currently have? And when I go to implode the values, will blank text fields screw everything up? I can't find anything in the forums that relate to this. I believe it probably will involve $i, but I am not too familiar with counting in php yet, so I could really use some help. Thanks! Oh - and I am not stuck on using text fields, but I couldn't figure how to make this work using a select list or checkboxes. Any suggestions either way would help. hi, I would like to know how do i modify this code if i Have more than 1 option in my dropdown list. Can someone help..Thankz <select name="mediaList" id="mediaList"> <option <?php echo ($rows['media_type'] =='Physical Only')?'selected="Selected"':'';?> >Physical Only</option> </select> Hello Freaks, I am currently working on a status report web application. A user inputs what they are planning on accomplishing that week. Afterwords realizes that they made a mistake and need to correct it. The way I want to go about this is sql the database and return * where the username and report date are current. With the results of this query I insert them into the form as the value. This yields a populated form. From here I want the user to be able to change any line and submit the whole form. However, the post array is only populated with one row of data. I thought this might have to do with the names of the inputs all being the same so i tried to index those through the while loop with no luck. Any help would be appreciated! here's the code Code: [Select] <? // renaming sess var $UAID = $_SESSION['UAID']; $WEND = $_SESSION['WEEK_ENDING2']; //have we submitted our changes? if($EDIT == TRUE){ //how many task are there this week $results = mysql_query("Select COUNT(UAID) FROM `WPFTW` where UAID ='$UAID' and Rend = '$WEND'"); $row = mysql_fetch_row($results); //clean $_POST print_r($_POST); unset($_POST['Report']); echo "<br>"; print_r($_POST); } //what do we plan on editing $results = mysql_query("Select * FROM `WPFTW` where UAID ='$UAID' and Rend = '$WEND'"); //while there are results while($row = mysql_fetch_array($results)){ //increment for input name $k = 1; //date formatting list($year,$month,$day) = explode("-",$row['Target']); $row['Target'] = $month."-".$day."-".$year; //empty string to uncheck checkboxes $checked = ""; //populate checkboxes if($row['MS'] == "on"){ $checked = "yes"; } //select the correct drop down menu option if(isset($row['Status'])){ if($row['Status'] == " "){ $selected = "selected"; $selected1 = ""; $selected2 = ""; $selected3 = ""; } elseif($row['Status'] == "P"){ $selected = ""; $selected1 = "selected"; $selected2 = ""; $selected3 = ""; } elseif($row['Status'] == "C"){ $selected = ""; $selected1 = ""; $selected2 = "selected"; $selected3 = ""; } elseif($row['Status'] == "CL"){ $selected = ""; $selected1 = ""; $selected2 = ""; $selected3 = "selected"; } } //select the correct drop down menu option if(isset($row['OT'])){ if($row['OT'] == "Y"){ $selected4 = "selected"; $selected5 = ""; } elseif($row['OT'] == "N"){ $selected4 = ""; $selected5 = "selected"; } } //var to send form to self $cani = htmlentities($_SERVER['PHP_SELF']); //concatenate html & php for form $test = "<form id =\"2bigform\" action=$cani method = \"post\">" . "<tr>" . "<td><input id=\"hidden\" name=\"UAID$k\" type=\"hidden\" value=" . $_SESSION['UAID'] ."></td>". "<td width=\"7%\"> <input id=\"SR\#$k\" name=\"SR#\" type=\"text\" size=\"10%\" maxlength=\"10\" value=" . $row['SRNUM'] . "></td>" . "<td width=\"63%\"> <input id=\"Task$k\" name=\"Task\" type=\"textarea\" size=\"63%\" value=" . $row['Task'] . "></td>" . "<td width=\"7%\"> <select id=\"Status$k\" name=\"Status\">". " <option value=\" \" $selected></option>". " <option value=\"P\" $selected1>P</option>". " <option value=\"C\" $selected2>C</option>". " <option value=\"CL\" $selected3>CL</option>". "</select></td>". "<td width=\"7%\"> <input id=\"MS$k\" name=\"MS\" type=\"checkbox\" size=\"7%\" value=" . $row['MS'] . " checked = $checked></td>". "<td width=\"7%\"> <select id=\"OT$k\" name=\"OT\">". " <option value=\"Y\" $selected4>Y</option>". " <option value=\"N\" $selected5>N</option>". "</select></td>". "<td width=\"9%\"> <input id=\"Target$k\" name=\"Target\" type=\"text\" size=\"9%\" value=" . $row['Target'] . "></td>". "<input id=\"hidden\" name=\"RDate$k\" type=\"hidden\" value=" . $_SESSION['WEEK_ENDING'] ."></td></tr>"; echo $test; $k++; echo $k; } echo "</table>". "<input id=\"Sub\" type= \"Submit\" name=\"Report\" value= \"Submit\"/>". "</form>". "</body>". "</html>"; //<td width="7%"> <input id="SR#" name="SR#" type="text" size="10%" maxlength="10"/></td> //<td width="63%"> <input id="Task" name="Task" type="textarea" size= "63%"/></td> } ?> I have a table called "colors". It has 2 columns, id and color. All I'm trying to do is pull the data into the form, then edit the colors (for example - misspelled, etc.) Then submit it back to the table. Here is the code that pulls the data into a form so I can edit it: Code: [Select] <form action="adminupdatecolors.php" method="post"> <table width="500" border="1" cellpadding="10"> <tr> <td>Color Options:</td> <td> <? $result = mysql_query("SELECT * FROM colors"); while ($row = mysql_fetch_assoc($result)) { echo '<input type="text" name="color[]" value="' . $row['color'] . '"/>' . $row['id'] . '<br />'; } ?> </td> </tr> <tr> <td> </td> <td><input type="Submit" value="Update Colors"></td> </tr> </form> </table> Here is my update script: Code: [Select] <?php include("config.php"); include("db.php"); $id=$_POST['id']; $color=$_POST['color']; $result = mysql_query("SELECT id FROM colors ORDER BY id DESC LIMIT 0,1"); if ($row = mysql_fetch_assoc($result)) { $id = $row['id']; } $sql = "DELETE FROM colors WHERE id='$id'"; mysql_query($sql) or die("Error: ".mysql_error()); foreach ($color as $colorvalue) { $sql2 = "INSERT INTO colors (id,color) VALUES ($id,'$color')"; mysql_query($sql2) or die("Error: ".mysql_error()); } header("Location: " . $config_basedir . "adminhome.php"); ?> Hey, So on my profile page I have a lot of info such as Name, Birthday, City, Country, Status etc... Its set up like this... Name: $loggedInfo[Name]<p/> Birthday: $loggedInfo[Birthday]<p/> City: $loggedInfo[City]<p/> Country: $loggedInfo[Country]<p/> Status: $loggedInfo[Status]<p/> The problem is is that if the user doesnt fill out this info then there is a blank space on their profile. How can I go about having it so if there is no data for say Country, on their profile there will be a link and it will say "Edit this!" and that link can just go to edit profile. Pretty much I dont want to do this for everything... if($loggedInfo[Name] != "") { echo"$loggedInfo[Name]"; }else{ echo"<a href='edit_profile.php'>edit this!</a>"; } Thanks, Sean Am new here - looks like a great foru! I would sincerely appreciate any help anyone can give me. I have been trying to solve my problem for hours and I am not having any luck, so I thought I would post and see if anyone can help. I am very stuck and am not making much progress on this project, and I am certain the answer is very simple. I am constructing a form to collect data for a specialized purpose. The form and program actually work for its intended function, but I am trying to enhance the user experience by preventing customers from having to reenter all of their data should there be a problem with any of the data submitted. I have been able to do that with the contact form portion, but what I am having trouble with is the portion which has as many as 400 possible entries. So, in a nutshell, if the customers contact data is incomplete or in error, the form will ask them to return to the page and correct things. The previous data entered has been saved in the session and the input value will equal the previous entry. i.e. <tr> <td align="right" class="infoBox"><?php echo ENTRY_EMAIL_ADDRESS; ?></td> <td align=left><?php echo "<input type=text name='cemail' value=\"$cemail\" size=35 maxlength=35>" ?></td> </tr> Works perfectly, all well and good there. On the other 400 more or less entries, I am having a difficult time tweaking the string concatenation to work to achieve similar results. There are 4 columns each with $points entries asking for a dimension in either feet or inches. The <input name=> is one of ptaf,ptai,ptbf,ptbi, appended programatically with the corresponding row number or data point. i.e. "ptaf1", "ptai1", etc... This is produced by the example below and works perfectly also. <?php { $points=100; $i=1; while ($i <= $points) {echo ' <tr><td align="center" width="6"><b> ' .$i . '</b></td> <td align="right" NOWRAP>A' .$i . ' (ft) <input type="text" name="ptaf'.$i.'" size=4 maxlength=3> </td> <td align="right" NOWRAP>A' .$i . ' (in) <input type="text" name="ptai'.$i.'" size=4 maxlength=4> </td> <td align="right" NOWRAP>B' .$i . ' (ft) <input type="text" name="ptbf'.$i.'" size=4 maxlength=3> </td> <td align="right" NOWRAP>B' .$i . ' (in) <input type="text" name="ptbi'.$i.'" size=4 maxlength=4> </td> '; $i++; } } ?> I am trying to add <input value=$ptai.$i> for each field but as I mentioned I am not having any luck. It seems as if I have tried every combination imagineable, but still no luck. My head is spinning! The closest I seem to have gotten was with this: <td align="right" NOWRAP>A' .$i . ' (ft) <input type="text" size=6 maxlength=3 name="ptaf'.$i.'" value="' . "$ptaf" . $i . '" ></td> But line 17 for example returns this: <input type="text" value="17" name="ptaf17" maxlength="3" size="6"> To recap, I am trying to have the value set to whatever the customer may have entered previously. Again, I would most appreciate any help anyone can give me. If you need clarification on anything please let me know. Thanks AJ Say there is a complex opt in process where people start to enter their data but certain questions stop them where they close out of the page. They already entered their data and I feel there is a way to grab it and post it to mysql even though they do not click submit.
How would this be done?
A super simple example (proof of concept) or a link to a tutorial would be very useful.
Edited by brentman, 23 September 2014 - 10:42 AM. Hello Friends, i have work with combobox by inserting value from DB dynamically... i just stuck with the situation as m populating combobox as statically , successfully inserting value in DB... but the point is m not sure for how to select perticular value stored in DB for combobox for displaying the data... here is my attempt... Code: [Select] Name: <input type="text" name="txtName" value="<?php print $uName; ?>"/> <br /> User Type: <select name="selType"> <option value="Admin">Admin</option> <option value="User">User</option> </select> i m getting the value of textbox from select query in the loop bt wht abt combobox value? if for 1 record the name will be krazyk n usertype will be admin then how to select the value from DB? please suggest me the way to accomplish it... awaiting for your better response... Thank you...!!! Hi Everyone. I'm using the following code to populate a combobox with salutations. The List is populated and the initial value is 'select a salutation'. When the submit button is clicked, the selection is saved in the database. my issue is that when i open the page based on the id number, the list does not remember my choice. it just lists all the salutations in the combobox. How can i change this code to remember the value selected? thanks. I am saving the value of Salutation_1 from the combobox into records.Salutation_1. <?php $result=mysql_query("select Salutation from salutations"); $options=""; while ($row=mysql_fetch_array($result)) { $categoryname=$row["Salutation"]; $options.="<OPTION VALUE=\"$categoryname\">".$categoryname.'</option>'; } ?> <select name="Salutation_1"> <option >< select salutation > <?php echo $options ?></option> I have a form gathering data from the database. There is one field 'country' which is a combo box. The combo box is populated from the countries table which joins the customers table to provide the country specific to the customer. I'm trying to have the combo box display the country associated with the customer. I think I'm close in my code, but unsure. This is a playground to so I can implement on our other site. <?php require_once('database.php'); $sql2 = "SELECT * From countries "; $countries = $db->query($sql2); if(isset($_GET['customerID'])) { $customerID = filter_input(INPUT_GET, 'customerID', FILTER_SANITIZE_NUMBER_INT); $sql = "SELECT * FROM customers WHERE customerID =$customerID "; //$sql2 = "SELECT * From countries //INNER JOIN customers ON countries.countryCode=customers.countryCode //WHERE customers.customerID = $customerID"; $stmt = $db->query($sql); } if(isset($_GET['customerID'])){ $customerID = filter_input(INPUT_GET, 'customerID', FILTER_SANITIZE_NUMBER_INT); $countryQuery = " {$sql2} INNER JOIN customers ON countries.countryCode = customers.countryCode WHERE customers.customerID = $customerID"; $countriesQuery = $db->prepare($countryQuery); $countriesQuery->execute(['customerID' => $_GET['customerID']]); $selectedCountry = $countriesQuery->fetch(PDO::FETCH_ASSOC); var_dump($selectedCountry); } ?> <!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"> <!-- the head section --> <head> <title>My Guitar Shop</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <!-- the body section --> <body> <div id="page"> <div id="header"> <h1>SportsPro Technical Support</h1> <p>Sports management software for the sports enthusiast.</p></h1> </div> <div id="main"> <h1>View/Update Customer</h1> <form action="update.php" method="get" > <?php ?> <div id="content"> <!-- display a table of products --> <h2>Customers</h2> <form name="customerInfo"> <?php foreach ($stmt as $cust) { ?> <div> <label>First Name</label> <input type="text" name="name" class ="form-control" value ="<?php echo $cust['firstName']; ?>"> </div><br> <div> <label>Last Name</label> <input type="text" name="name" class ="form-control" value ="<?php echo $cust['lastName']; ?>"> </div><br> <div> <label>Address</label> <input type="text" name="address" class ="form-control" value ="<?php echo $cust['address']; ?>"> </div><br> <div> <label>City</label> <input type="text" name="city" class ="form-control" value ="<?php echo $cust['city']; ?>"> </div><br> <div> <label>State</label> <input type="text" name="state" class ="form-control" value ="<?php echo $cust['state']; ?>"> </div><br> <form action="update.php" method="get"> <select name="country"> <option value=""></option> <?php foreach ($countries->fetchAll() as $country): ?> <option value="<?php echo $country['customerID']; ?> <?php echo isset($customerID) == $selectedCountry['customerID'] ? ' selected':''?> "><?php echo $country['countryName']; ?></option> <?php endforeach;?> </select> </form> </div> <br> <div> <label>Country Code</label> <input type="text" name="countryCode" class ="form-control" value ="<?php echo $cust['countryCode']; ?>"> </div><br> <div> <label>Zip Code</label> <input type="text" name="postalCode" class ="form-control" value ="<?php echo $cust['postalCode']; ?>"> </div><br> <div> <label>Email </label> <input type="text" name="email" class ="form-control" value ="<?php echo $cust['email']; ?>"> </div><br> <div> <label>Phone Number </label> <input type="text" name="phone" class ="form-control" value ="<?php echo $cust['phone']; ?>"> </div><br> <div> <label>Password </label> <input type="text" name="password" class ="form-control" value ="<?php echo $cust['password']; ?>"> </div><br> <div> <?php } ?> </div> </div> <form action="UpdateCustomer.php" method="get"> <input type="submit" name="data" value="Update_Data"></input> </form> <div id="footer"> <p> © <?php echo date("Y"); ?> SportsPro, Inc. </p> </div> </div><!-- end page --> </body> </html>
|