PHP - Dynamic Form Save
Hi All, $userClient = "VARIABLE OF WHO IS LOGGED IN"; <form action="actions/assign.php" method="post"> <?php $sql = "SELECT * FROM Engineers where Engineer_Company = '".addslashes($userClient)."' and userType = '5'"; $result = mysqli_query($db, $sql); while($row = mysqli_fetch_assoc($result)) { $userSID = $row["userID"]; echo '<tr> <td>'.$row["userName"].' <input type="hidden" class="form-control" id="usersID[]" name="usersID'.$row["userID"].'" value="'.$row["userID"].'"> <input type="hidden" class="form-control" id="date" name="date" value="'.date('d-m-Y').'"> </td> <td>'; $sql1 = "SELECT * FROM job_orders where companyID = '".addslashes($userClient)."'"; $result1 = mysqli_query($db, $sql1); echo "<select style='width: 250px;' id='job$userSID' name='job$userSID'>"; echo '<option value="">-- Please Select --</option>'; while($row1 = mysqli_fetch_assoc($result1)) { echo '<option value="'.$row1["jobID"].'">'.$row1["jobtitle"].'</option>'; } echo "</select>"; echo '</td> <td>'; $query = $db->query("SELECT * FROM Engineer_Company WHERE Company_ID = '".addslashes($userClient)."'"); $rowCount = $query->num_rows; if($rowCount > 0){ echo ' <select name="company'.$userSID.'" id="company'.$userSID.'" style="width: 250px;"> <option value="">-- Select Company --</option>'; while($row = $query->fetch_assoc()){ echo '<option value="'.$row['Engineer_Company_ID'].'" class="form-control form-control-sm">'.$row['Engineer_Company_Name'].'</option>'; } echo '</select>'; } echo'</td> <td> <div class="form-group"> <select id="site'.$userSID.'" name="site'.$userSID.'" style="width: 250px;"> <option value="">-- Select Site --</option> </select> </div> '; echo'</td> </tr>'; echo ' <script type="text/javascript"> $(document).ready(function(){ $("#company'.$userSID.'").on("change",function(){ var diag_id = $(this).val(); if(diag_id){ $.ajax({ type:"POST", url:"ajax-client-side.php", data:"diag_id="+diag_id, success:function(html){ $("#site'.$userSID.'").html(html); } }); } }); }); </script>'; } ?> </tbody> </table> <input class="btn btn-dark float-right" type="submit" value="Allocate"> </form>
Similar TutorialsI have html form and verify post data via pgp how can I save someone data if some one fill incorrect information Well, folks, thanks to all the help, I've narrowed my problem down to needing a way to allow a variable value to traverse into subsequent calls of a function. I have a simple integer - "companyID", and it's set in "actionfile.php" which is called by two forms. The first time it's called by Form A, it's set. I'd LIKE to put it into $_SESSION, but apparently $_SESSION is zeroed out before I can use it in the second call to "actionfile.php" by Form B. A new form/function call is a new session? I've tried setting it to global and static, to no avail. Anything more elegant than writing the value to SQL for later retrieval? Thanks! Mark Hey guys! I have the following script to create an excel file, the thing is that I dont want to be asked if I want to open or save the file when accessing the php file...I just want the php file directly to save the excel file. Heres the code: $filename = "test.xls"; $contents = "testdata1 \ntestdata2 \ntestdata3 \n"; header('Content-type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename='.$filename); echo $contents; Is there a way instead of using the header function, use something like: fopen, fwrite, fclose ? Thanks in advance! Cheers, I have a form which a user enters information like age, email, address. This information is emiled to the admin. I would like the information to also be saved to a textfile on the server when the same button is pressed Please help Thank you in advance, for your time and effort This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=348155.0 Greetings! I'm new in phpmysql. Am making signup form with three users (Admin, office and student), that when student is selected there will be another form that need to fill up and the data is saved in different table. Below are my codes when the data of admin and office are submitted. Code: [Select] mysql_query("INSERT INTO tbl_user (user_Id,user_Password,user_Fname,user_Lname,user_Sex,user_Level,user_Program) VALUES ('$userid','$password','$fname','$lname','$sex','$level','$program')"); these things here are codes for student when submitted Code: [Select] mysql_query("INSERT tbl_studenroll (user_Id, course_Id, ap_Id, se_Sem, se_Yearlevel) VALUES ('$userid','$course', '$acadyear', '$sem', '$year')") or die(mysql_error()); $seID = mysql_query ("SELECT max(se_Id) AS mxSEid FROM tbl_studenroll")or die (mysql_error()); $seID1 = mysql_fetch_assoc($seID); $seID = $seID1['mxSEid']; $offcourse = mysql_query("SELECT office_Id FROM tbl_offcourse WHERE course_Id = '$course'")or die (mysql_error()); while ($row = mysql_fetch_array($offcourse)) { $off = $row['office_Id']; mysql_query("INSERT tbl_data (se_Id,office_Id,user_Id,course_Id) VALUES ('$seID','$off','$userID','$courseID')") or die(mysql_error()); } sEE that I am saving in three tables at the same time when student is selected. How can I do it? I want to save only what for students and for other users..I tried my codes but when I submit data from office, it saves data to studenroll, but in 0 value. hope I am clear, help me guys! thank you in advace. Hi all, it's been a while since I wrote in PHP but a University project has forced me to touch up on my knowledge of it. I'm trying to re-create an old form making system I made a few years ago from memory. But it's not working. I know it's something very obvious but I just need another eye to take a look for me. I get the following error message: Warning: Invalid argument supplied for foreach() in /home/birdneto/public_html/rebelfrogv2/p_createaccount.php on line 169 So I know it's do with my show_form(); function. Can anyone help? Code: [Select] <div id="page-body-special"> <?php // List page details $page_header = "Create your account"; $page_desc = "Enter your details below to create an account. Creating an account comes with great benefits! You can create a wishlist, sign up for our mailing list and purchase items. Make sure you enter all your information correctly."; // List form details $form_name = "createaccount"; // List all the field names here $field_email_address = "email_address"; $field_email_address_confirm = "confirm_email_address"; $field_password = "password"; $field_password_confirm = "confirm_password"; $field_house_number = "house_number"; $field_street_name = "street_name"; $field_city = "city"; $field_county = "county"; $field_postcode = "postcode"; $field_phone_number = "phone_number"; $field_newsletter = "newsletter"; $field_submit = "submit"; // Define all the field meta data (field name, maxlength, minlength, field type, [field options], [field description]) $fields = array( array($field_email_address, 80, 8, "text", $_POST[$field_email_address]), array($field_email_address_confirm, 80, 8, "text", $_POST[$field_email_address_confirm]), array($field_password, 16, 8, "password", $_POST[$field_password]), array($field_password_confirm, 16, 8, "password", $_POST[$field_password_confirm]), array($field_house_number, 2, 4, "password", $_POST[$field_house_number]), array($field_street_name, 16, 8, "password", $_POST[$field_street_name]), array($field_city, 16, 8, "password", $_POST[$field_city]), array($field_county, 16, 8, "password", $_POST[$field_county]), array($field_postcode, 16, 8, "password", $_POST[$field_postcode]), array($field_phone_number, 16, 8, "password", $_POST[$field_phone_number]), array($field_newsletter, 0, 0, "checkbox", $_POST[$field_newsletter], 0, "Would you like to sign up to our newsletter?"), array($field_submit, 0, 0, "submit", "Create Account") ); // Check if form has been submitted or not. All fields must be declared here with an if statement if($_POST['submit']) { // Set no_errors and show_form to inital 0 $no_errors = 1; function show_errors($field) { if($field == $field_email_address) { if(strlen($_POST[$field_email_address]) < $fields[0][2] and strlen($_POST[$field_email_address]) > $fields[0][1]) { $no_errors = 0; $error = "Your email address must be between " . $fields[0][2] . " and " . $fields[0][1] . " characters"; } } if($field == $field_email_address_confirm) { if($_POST[$field_email_address_confirm] != $_POST[$field_email_address]) { $no_errors = 0; $error = "Your emails do not match each other"; } } if($field == $field_password) { if(strlen($_POST[$field_password]) < $fields[2][2] and strlen($_POST[$field_password]) > $fields[2][1]) { $no_errors = 0; $error = "Your password must be between " . $fields[2][2] . " and " . $fields[2][1] . " characters"; } } if($field == $field_password_confirm) { if($_POST[$field_password_confirm] != $_POST[$field_password_confirm]) { $no_errors = 0; $error = "Your passwords do not match"; } } if($field == $field_house_number) { if(strlen($_POST[$field_house_number]) < $fields[4][2] and strlen($_POST[$field_house_number]) > $fields[4][1]) { $no_errors = 0; $error = "Your house number must be between " . $fields[4][2] . " and " . $fields[4][1] . " numbers"; } } if($field == $field_street_name) { if(strlen($_POST[$field_street_name]) < $fields[5][2] and strlen($_POST[$field_street_name]) > $fields[5][1]) { $no_errors = 0; $error = "Your street name must be between " . $fields[5][2] . " and " . $fields[5][1] . " characters"; } } if($field == $field_city) { if(strlen($_POST[$field_city]) < $fields[6][2] and strlen($_POST[$field_city]) > $fields[6][1]) { $no_errors = 0; $error = "Your city must be between " . $fields[6][2] . " and " . $fields[6][1] . " characters"; } } if($field == $field_county) { if(strlen($_POST[$field_county]) < $fields[7][2] and strlen($_POST[$field_county]) > $fields[7][1]) { $no_errors = 0; $error = "Your county must be between " . $fields[7][2] . " and " . $fields[7][1] . " characters"; } } if($field == $field_postcode) { if(strlen($_POST[$field_postcode]) < $fields[8][2] and strlen($_POST[$field_postcode]) > $fields[8][1]) { $no_errors = 0; $error = "Your postcode must be between " . $fields[8][2] . " and " . $fields[8][1] . " characters"; } } if($field == $field_phone_number) { if(strlen($_POST[$field_phone_number]) < $fields[7][2]) { $no_errors = 0; $error = "Your phone number must be under " . $fields[7][2] . " numbers"; } } return $error; } if($no_errors == 0) { show_form(); } else { echo "<p>Form posted</p>"; echo $br . $br; } } else { show_form(); } function show_form() { // Show the page header echo $br . '<form method="post" action="./?p=' . $page . '" name="' . $form_name . '">'; echo $br . $br; echo '<table id="form-' . $form_name . '">'; echo $br; // List all fields in form format foreach($fields as $meta) { // Explode the array and implode it, changes commas to spaces, then makes all words have capital letters $label_exp = explode("_", $meta[0]); $label_imp = ucwords(implode(" ", $label_exp)); // Is the field type a submission? if($meta[3] == "submit") { echo ' <tr><td colspan="2"><input type="' . $meta[3] . '" name="' . $meta[0] . '" class="' . $meta[0] . '" value="' . $meta[4] . '" /></td></tr>'; echo $br; } // Is the field type a select? elseif($meta[3] == "select") { $options = explode(",", $meta[5]); echo ' <tr><td><label>' . $label_imp . '</label></td><td><select type="' . $meta[3] . '" name="' . $meta[0] . '" class="' . $meta[0] . '">'; echo $br; foreach($options as $option) { function is_selected() { if($option == $_POST[$meta[0]]) { echo 'selected="selected"'; } } echo(' <option ' . is_selected($option) . '>' . $option . '</option>'); echo $br; } echo ' </select></td></tr>'; echo $br; } // Is the field type a checkbox? elseif($meta[3] == "checkbox") { echo ' <tr><td><label>' . $meta[6] . '</label></td><td><input type="' . $meta[3] . '" name="' . $meta[0] . '" class="' . $meta[0] . '" /></td></tr>'; echo $br; } // Is the field type anything else? else { echo ' <tr><td><label>' . $label_imp . '</label></td><td><input type="' . $meta[3] . '" name="' . $meta[0] . '" class="' . $meta[0] . '" maxlength="' . $meta[1] . '" value="' . $meta[4] . '" /></td></tr>'; echo $br; } } // Show the page footer echo '</table>'; echo $br . $br; echo '</form>'; echo $br . $br; } echo $br . "<h1>" . $page_header . "</h1>"; echo $br . $br; echo "<p>" . $page_desc . "</p>"; echo $br . $br; echo '<div class="clear"></div>'; echo $br . $br; ?> </div> Okay, so I have a page with a heap of fields and buttons on it (and want to keep it like that really) inside one form. Layout Box 1 Button 1 Box 2 Button 2 Box 3 Button 3 Box 4 Button 4 etc... Box 1 is called 'amount1$id' Box 2 is called 'amount.$id' where $id is the $id of the data being displayed etc So a sample form may look like Box: "amount22" Button: "Pay22" Box: "amount25" Button: "Pay25" Box: "amount32" Button: "Pay32" Box: "amount39" Button: "Pay39" Box: "amount420" Button: "Pay420" Its working fine up to that point. My problem now is that I can't work out how to get that id number from the form once submitted. If I could get the button name somehow I could do it, although I don't know the button or box names when writing the processing script. I could use a loop and check if button1 to buttonX was posted etc, although if there is a large number of entries in the database, then that starts to become a problem. Thoughts? Hello,
I have made a simple form, which displays an input first, you have to enter a number, then a dynamic form show up with a dynamic part where the number and name of fields vary depending on the number entered first.
In the action page, i have a problem, when i try to display the data in each field, i don't succeed, i get a message
Notice: Array to string conversion
My code is the following :
<h1>Training Reports</h1> <hr /> <form action="" method="post"> Type the number of SEALs : <input type="number" name="nofseals"/> <input type="submit" name="submitn" value="Submit" /> </form> <?php if(isset($_POST['submitn'])){ $numberofseals=$_POST['nofseals']; $numberoffields = 0; echo "<form name=\"report\" action=\"reporta.php\" method=\"post\" style=\"text-align:left;\"> <div style=\"margin-left: 50%;\">Training # <input type=\"number\" name=\"number\"/></div> <br><br> <input type=\"number\" name=\"nos\" value=\"$numberofseals\" style=\"display: none;\"/> <input type=\"number\" name=\"nof\" value=\"$numberoffields\" style=\"display: none;\"/> <h3>Date</h3> <input type=\"date\" name=\"date\" placeholder=\"Date\"/> <h3>Training Type</h3> <textarea name=\"type\" rows=\"2\" placeholder=\"Training Type...\" ></textarea> <h3>Training Duration</h3> <input type=\"time\" name=\"duration\" placeholder=\"Training Duration\"/> <h3>Training Details</h3> <textarea name=\"details\" rows=\"8\" placeholder=\"Training Details...\" ></textarea> <h3>Screenshots</h3> <textarea name=\"ss\" rows=\"1\" placeholder=\"Screenshots links...\" ></textarea> <h2>Participants Marks and Comments</h2>"; while ($numberoffields < $numberofseals) { $numberoffields++; echo "<h3>SEAL $numberoffields : <input type=\"text\" name=\"n[$numberoffields]\" placeholder=\"SEAL Name\"/></h3> <div style=\"margin-left: 20px;\"> Behavior :<input type=\"text\" name=\"b[$numberoffields]\" placeholder=\"Behavior Mark\"/><br> Skills: <input type=\"text\" name=\"m[$numberoffields]\" placeholder=\"Skills Mark\"/><br> Comments: <textarea name=\"c[$numberoffields]\" rows=\"1\" placeholder=\"Comments\"></textarea></div> <br><br>";} echo "<input type=\"submit\" name=\"submit\" value=\"Submit\" />";} ?>Action page : <?php if(isset($_POST['submit'])){ $noofseals=$_POST['nos']; $number=$_POST['number']; $date=$_POST['date']; $type=$_POST['type']; $details=$_POST['details']; $duration=$_POST['duration']; $ss=$_POST['ss']; $numero=0; $c{$numero}=$_POST['c']; $m{$numero}=$_POST['m']; $b{$numero}=$_POST['b']; $n{$numero}=$_POST['n']; echo "[center][color=#2D3C0F][size=20pt][glow=black,2,100][font=georgia]TRAINING REPORT #[/font][/glow][/size][/color][/center] [b][color=navy]Date:[/color][/b]$date [b][color=navy]Type of training:[/color][/b]$type [b][color=navy]How long it lasted:[/color][/b]$duration [b][color=navy]Training details:[/color][/b]$details [b]Screenshots:(optional)[/b]$ss [b][color=navy]SEALs perfomance[/color][/b] [list]"; while($numero < $noofseals) { $numero++; echo "[li][b][color=blue]Seal [$nn]:[/color][/b] [b]Behavior:[/b] [b]Skills:[/b] [b]Comments:[/b] [/li]"; }} echo"[/list]"; ?> Hi, sorry for being a newbie, but I need help setting up a dynamic form. The form will be a reservation type form. I have a single table, which I will post below. What I am looking to do is choose a month from a select box and then have it populate another select box with the available dates. Here is my table info from mysql... Code: [Select] CREATE TABLE `daterange` ( `RID` int(5) NOT NULL auto_increment, `DEND` date NOT NULL, `MONTH` varchar(50) NOT NULL, `DATE` varchar(50) NOT NULL, `SITE` varchar(50) NOT NULL, `PRICE` varchar(10) NOT NULL, `STATUS` varchar(1) NOT NULL default 'A', `FNAME` varchar(50) NOT NULL, `LNAME` varchar(50) NOT NULL, `ADDR1` varchar(50) NOT NULL, `ADDR2` varchar(50) NOT NULL, `CITY` varchar(50) NOT NULL, `STATE` varchar(2) NOT NULL, `ZIP` varchar(5) NOT NULL, `PHONE1` varchar(3) NOT NULL, `PHONE2` varchar(3) NOT NULL, `PHONE3` varchar(4) NOT NULL, `EMAIL` varchar(50) NOT NULL, PRIMARY KEY (`RID`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=83 ; Here is a sample mysql dump... Code: [Select] INSERT INTO `daterange` VALUES(1, '2011-05-15', 'May 2011', '5/15-5/22/11', 'Carterville Pond/Adirondack', '$2625.00', 'N', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); INSERT INTO `daterange` VALUES(2, '2011-05-22', 'May 2011', '5/22-5/29/11', 'Carterville Pond/Adirondack', '$2625.00', 'A', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); INSERT INTO `daterange` VALUES(3, '2011-05-29', 'May 2011', '5/29-6/5/11', 'Carterville Pond/Adirondack', '$2625.00', 'A', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); Finally, here is a php form that I started to develop but it only has a single select box, which works but I wanted another select box that will filter the list down a little... Code: [Select] <? // script to display all the Available Reservations in the daterange table // connection information $hostName = "my_host"; $userName = "my_user"; $password = "my_pass"; $dbName = "my_db"; // make connection to database mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName"); mysql_select_db($dbName) or die("Unable to select database $dbName"); // Select all the fields in all the records of the daterange table $query = "SELECT * FROM daterange WHERE DEND > DATE(NOW()) AND STATUS='A' ORDER BY RID, DATE, SITE"; $result = mysql_query($query); // Determine the number of reservation dates $number = mysql_numrows($result); // Create drop-down menu of reservation dates print "<font size=\"3\" face=\"Arial\"><b>Select Reservation Date:</b> <form action=\"test.php\" method=\"post\"> <select name=\"RID\"> <option value=\"\">Choose One</option>"; for ($i=0; $i<$number; $i++) { $RID = mysql_result($result,$i,"RID"); $DATE = mysql_result($result,$i,"DATE"); $SITE = mysql_result($result,$i, "SITE"); $PRICE = mysql_result($result,$i, "PRICE"); print "<option value=\"$RID\">$DATE, $SITE, $PRICE</option>"; } print "</select><p align=left><label><font size=\"3\" face=\"Arial\">First Name: <input type=\"text\" name=\"FNAME\" size=\"50\" maxlength=\"50\" tabindex=\"1\"<br>"; print "<p align=left><label>Last Name: <input type=\"text\" name=\"LNAME\" size=\"50\" maxlength=\"50\" tabindex=\"2\"<br>"; print "<p align=left><label>Address Line 1: <input type=\"text\" name=\"ADDR1\" size=\"50\" maxlength=\"50\" tabindex=\"3\"<br>"; print "<p align=left><label>Address Line 2: <input type=\"text\" name=\"ADDR2\" size=\"50\" maxlength=\"50\" tabindex=\"4\"<br>"; print "<p align=left><label>City: <input type=\"text\" name=\"CITY\" size=\"50\" maxlength=\"50\" tabindex=\"5\"<br>"; print "<p align=left><label>State (abbrev.): <input type=\"text\" name=\"STATE\" size=\"2\" maxlength=\"2\" tabindex=\"6\"<br>"; print "<p align=left><label>Zip Code: <input type=\"text\" name=\"ZIP\" size=\"5\" maxlength=\"5\" tabindex=\"7\"<br>"; print "<p align=left><label>Contact Phone Number: (<input type=\"text\" name=\"PHONE1\" size=\"3\" maxlength=\"3\" tabindex=\"8\""; print "<label>)<input type=\"text\" name=\"PHONE2\" size=\"3\" maxlength=\"3\" tabindex=\"9\""; print "<label>-<input type=\"text\" name=\"PHONE3\" size=\"4\" maxlength=\"4\" tabindex=\"10\"<br>"; print "<p align=left><label>Email: <input type=\"text\" name=\"EMAIL\" size=\"50\" maxlength=\"50\" tabindex=\"11\"<br>"; print "<p align=left><label>Payment Method: <select name=\"PM\"> <option value=\"\">Choose One</option> <option value=\"Visa\">Visa</option> <option value=\"Mastercard\">Mastercard</option> <option value=\"Discover\">Discover</option>"; print "</select><p align=left><label>Credit Card Number: <input type=\"text\" name=\"C1\" size=\"4\" maxlength=\"4\" tabindex=\"12\""; print "<label> <input type=\"text\" name=\"C2\" size=\"4\" maxlength=\"4\" tabindex=\"13\""; print "<label> <input type=\"text\" name=\"C3\" size=\"4\" maxlength=\"4\" tabindex=\"14\""; print "<label> <input type=\"text\" name=\"C4\" size=\"4\" maxlength=\"4\" tabindex=\"15\"<br>"; print "<p align=left><label>Expiration Month: <select name=\"EXM\"> <option value=\"\">Choose One</option> <option value=\"January\">January</option> <option value=\"February\">February</option> <option value=\"March\">March</option> <option value=\"April\">April</option> <option value=\"May\">May</option> <option value=\"June\">June</option> <option value=\"July\">July</option> <option value=\"August\">August</option> <option value=\"September\">September</option> <option value=\"October\">October</option> <option value=\"November\">November</option> <option value=\"December\">December</option>"; print "</select><p align=left><label> Expiration Year: <select name=\"EXY\"> <option value=\"\">Choose One</option> <option value=\"2011\">2011</option> <option value=\"2012\">2012</option> <option value=\"2013\">2013</option> <option value=\"2014\">2014</option> <option value=\"2015\">2015</option> <option value=\"2016\">2016</option> <option value=\"2017\">2017</option> <option value=\"2018\">2018</option> <option value=\"2019\">2019</option> <option value=\"2020\">2020</option>"; print "</select><p align=left><label>Security Code (3 or 4 digits): <input type=\"text\" name=\"CSC\" size=\"4\" maxlength=\"4\" tabindex=\"16\"<br>"; print "<p align=left><input type=\"submit\" value=\"Book Now!\" name=\"submit\"></form>"; print " <input type=\"reset\" value=\"reset\" name=\"reset\"></form>"; // Close the database connection mysql_close(); ?> Sorry this is so long, any help would be appreciated...... -Bob Hi - I have a form which is populated with values from a DB. This is done by looping through the DB values using a foreach. It works fine. I populate my form with those values. However, I want to be able to amend those values, and then submit the new values back to the DB with 1 single submit button. I don't want a separate submit button for each row of my form. The problem is that because the form is built with a foreach, as the it loops through the variables on each pass of the DB, only the final row of DB are present in the form variables. Question: My 'foreach' approach must be faulty. What is the mechanism or approach I need to use to update the values from the whole form ?? MANY THANKS for all your help !! So I know a little about PHP but I am no expert by any means. But I have a project that I am working on for a fantasy football league and need some help. My users pick players from a list and then their selections are put into a database. So more than one user is likely to pick the same player. Then I need to score the players based off their games for the week. So I have code that gets the Distinct PlayerID and creates a form to update the player score (see code below), but I have no idea how to process the form. It's a little more complicated then the forms I've used before because the MySQL query would need to UPDATE all the rows for each individual PlayerID. Am I making any sense? Anyway, here is the code. If anyone has suggestions on how to process this form or a better way of doing it then please let me know. <? print '<form id="form1" name="form1" method="post" action="update_player.php">'; // Connecting, selecting database $link = mysql_connect('localhost','user','pass'); if (!$link) { die('Could not connect: ' . mysql_error()); } //Query $query=mysql_query("select DISTINCT(PlayerID), PlayerName, Team From fantasy4.temp ORDER BY Team;") or die ('Could not connect: ' . mysql_error()); print' <center> <table align=center border=0 cellpadding=0 cellspacing=2 width=350> <tr align=center> <td width=50 align=center><b>Player ID </b></td> <td width=50 align=center><b>Team</b></td> <td width=200 align=center><b>Player Name</b></td> <td width=50 align=center><b>Score</b></td> <tr><td colspan="10" bgcolor="black" height="1"></td></tr> '; while($row=mysql_fetch_array($query)){ if($color == 1) { print '<tr bgcolor=#dDdDdD> <td align=center> ' . $row['PlayerID'] . ' </td> <td align=center> ' . $row['Team'] . ' </td> <td align=center> ' . $row['PlayerName'] . ' </td> <td align=center> <input name="' . $row['PlayerID'] . '" type="text" id="' . $row['PlayerID'] . '" size="5" maxlength="5" /> </td> </tr>'; $color=0; } else { print '<tr> <td align=center> ' . $row['PlayerID'] . ' </td> <td align=center> ' . $row['Team'] . ' </td> <td align=center> ' . $row['PlayerName'] . ' </td> <td align=center> <input name="' . $row['PlayerID'] . '" type="text" id="' . $row['PlayerID'] . '" size="5" maxlength="5" /> </td> </tr>'; $color=1; } } print '</table>'; print '<input type="submit" name="button" id="button" value="Update Player Scores" /></form>'; ?> This is what I tried that did not work <? // Connecting, selecting database $link = mysql_connect('localhost','user','pass'); if (!$link) { die('Could not connect: ' . mysql_error()); } //Query $query=mysql_query("select DISTINCT(PlayerID) From fantasy4.temp;") or die ('Could not connect: ' . mysql_error()); while($row=mysql_fetch_array($query)){ $PlayerID = $_POST[$row['PlayerID']]; } while($score = array($_POST['$PlayerID'])){ //Insert Query $query2=mysql_query("UPDATE fantasy4.temp set Score='$score' where PlayerID='$PlayerID'") or die ('Yikes could not connect: ' .mysql_error()); $result = @mysql_query($query2); } //Check whether the query was successful or not if($result) { header("location: register-success.php"); exit(); }else { die("Query failed - " .mysql_error()); } ?> First off thank you for opening my issue and taking the time out to try and help. I have created a php page that will display a list of people from a mysql database. What i would like to do is have a button that will update a field in the database when pressed. My question is if i make the fields into a form will it only update that one person? Hi, i am creating a web application, and i would like some help/advise on how to tackle a problem. I need to make an image i have into a contact form, with four fields, which basically posts information into a database. I am not sure how i would go about doing this as i will need to make each of the fields dynamic to post the data. I have attached the image to make my point a bit clearer. thanks I'm praying there's a function somewhere out there that: generates a html form based on the fields of a particular table within a DB (namely mySQL) generates the appropriate form input based on the fields type or notes (ie. for field: avatar_img, it knows to generate a file input) uses the POST method to submit generates and submits SQL insert query to database In addition to that, a similar function that generates a form that allows the editing of records. It doesn't take too long to write these each time myself, but if there's a function that you provide the formname, database driver, table name, whether your form is to insert or edit, that would be quite nifty i think. ie. generateForm(addUser, mySQL, tUsers, insert) Seen any such thing? Many thanks. Hello All, I am building a web based data entry project for my University Recycling Department 1) In the first level the user will enter the number of "rows" that he has to enter it can be any number form 4- 10 . Each row will contain "Vendor Name","Date","Net Recycled Weight" 2) Depending on the number of rows entered by the user I am generating a table structure that has 2.1) A <select> containing vendor names(I am querying for this and then storing the result in an Associative Array and then parsing it for select in every way) 2.2) A text box for the date 2.3) A text box for the Net Recycled Weight ------------------------------------------------ Here is the logic I have implemented so far <html> <head></head> <body> <form name = "form1" method = "post"> <select>HERE THE USER CAN SELECT THE NUMBER OF ROWS HE WANTS TO ENTER</select> <input type = "submit" value = "submit1" name = "submit1"> </form> <body> </html> <?php if(submit1 has been clicked ) { //HERE I AM GENERATING A DYNAMIC FORM BASED ON THE NUMBER OF ROWS COUNT <form name = "form2" method = "post"> echo <table> echo <tr> echo<td>VENDOR</td> echo<td>DATE</td> echo<td>NET RECYCLED WEIGHT</td> echo </tr> for(IT ITERATES TILL I GENERATE THE NUMBER OF ROWS THAT HAS TO BE ENTERED) { I AM GENERATING ROWS HERE } echo <input type = "submit" name = "submit2" value = "submit2"> echo</table> </form> HOW CAN I ACCESS THE POST METHOD OF FORM 2 } ?> MY PROBLEM --------------- I WANT TO KNOW THE FOLLOWING 1) It this the correct way to do it 2) how can I access the data entered in each dynamic row as I have to validate it and then enter the data in MySql 3) I am not sure how I will access the submit button event of the dynamically generated form I hope I can get some help Thanks, Marisha Hi, I have a dynamic form which uses javascript to add rows on the fly. The name of the element on my test page is txtRow1, txtRow2, etc; the number is added when I add a new row. I am trying to figure out how I will extract the data once the form had been POSTED. I have tried Code: [Select] $tags = $_POST['txtRow']; foreach ($tags as $t) { echo "$t<br />"; } but that shows nothing. I would be grateful for any assistance. Thanks Ok so I am writing a CMS to wrap around a company script I wrote a while back. I am having trouble requesting dynamic form names. Heres the code to generate the input fields: $fields = mysql_result($result,$i,"fields"); $exFields = explode(",", $fields); for($i = 0; $i < count($exFields); $i++){ echo "$exFields[$i] : <input type=\"text\" name=\"$exFields[$i]\"> <br>"; } Ok so it generates the fields the way I want. (design crap will be done later) But I am having issues on processing the form, for example: Fields get generated -> Client Fills them in -> Submitted into our already built function. The function takes those form values and creates an XDF file with the correct requested values. But like I said I am having issues requesting the form values because they wont be static they will differ depending on each PDF. Can anyone point me in the direction on how to get the form values? Hi - I'm trying to speed up part of my business. I sell photos taken on site...I dump said photos in a directory and my little app pulls all images from a given directory and displays them on a page. I can get the filename etc displayed on screen, added to the image attributes, whatever. I'd like to have a checkbox next to each image, and the user checks a few and it'll send an email to me so I can fill their order. Looks like this: http://www.limitedwave.com/reflex/ I can use a sendmail like I've tried, but it can take like 10 minutes to actually send from the server which is lame. I'd be cool with just dropping the data in my database, then retrieving selections by user's name, but I don't know how to set up a form/insert page that will insert from a somewhat random set of checkboxes. Thoughts? Thanks. Hi all. I am currently trying to build a site that will allow users to manage a self build house project. This is my first php MySQL project but I am getting to grips with it ok. I am currently building this for my own benefit at the moment as I am about to undertake a self build. I have a few questions to put to you guys. This is where I am at the moment I have a database table named materials which contains a list of materials , quantities, unit of measurement, id. My site has a user control panel that has separate forms for each stage of the build where the user enters the quantities of the materials, and the data is displayed as an array for each stage. So, heres question 1. I want to take the data and use it to generate a form which will be completed by several merchants.... so it will display similar to the array but will be a form with a text box for price where the merchant will insert a price. i.e <?php mysql_connect ("localhost", "test", "test") or die ('I cannot connect to the database becuase: ' . mysql_error()); mysql_select_db ("matquant"); // query $query = mysql_query("SELECT * FROM `quantites` ORDER BY `id` ASC"); // results while ($row = mysql_fetch_array($query)) { echo "<br />" .$row ['id']. " " .$row ['material']. " " .$row['quantity']. " " .$row['unit']. "<br />";} echo mysql_error(); ?> I want to add a text input box form which will allow the merchant to add a price to each item that is added to the array. so there the merchant will be able to give me a price for all the items in my list. Heres where I get stuck.... as I am constantly adding to the list I have no fixed amount of items so the form for the merchants needs to be built dynamically, ie each time I add a new material, I want the merchants form to get a new input. I am not very good at describing my problems but I am hoping that someone can help me out from the information given. Thats the first question. i like to get issues sorted in small bites. the second is the next big bite, I want to send the form above to several merchants, so I intend to have a user database with a user for each merchant, and link the tables so that each merchant can provide a price for each material, ideally the form would highlight the materials that have not had a price yet. I'm looking for advice on the best method of doing this basically but if I can get the first question sorted that would be great.. I have the test site local but can upload it it to the server if it will help you see what im trying to do. Any help that anyone can give will be greatly appreciated. |