PHP - Storing Multiple Form Fields In An Array
I have a Form that has 10 questions.
When the User completes the Form, each Response needs to be a separate record. (My database has a many-to-many relationship with a "member" and "question" table joined by a "answer" table in the middle. And each Form field will go into its own unique record to make the many-to-many work.) At the top of my Form I have... if ($_SERVER['REQUEST_METHOD']=='POST'){ // Form was Submitted (Post). // Initialize Errors Array. $errors = array(); // Trim all form data. $trimmed = array_map('trim', $_POST); // ************************ // Validate Form Data. * // ************************ // Validate Answer1. if (strlen($trimmed['answer01']) >= 2 && strlen($trimmed['answer01']) <= 1024){ // Valid Answer1. $answerArray[0] = $trimmed['answer01']; }else{ // Invalid Answer1. $errors['question01'] = 'Answer must be 2-1024 characters.'; }//End of VALIDATE ANSWER1 // Validate Answer2. // : // : // Validate Answer10. And down farther in my code, I have each Field in my Form set up like this... Code: [Select] <!-- Question 1 --> <label for="question01">1.) Why did you decide to start your own business?</label> <textarea id="question1" name="answer01" cols="60" rows="8"><?php if (isset($answerArray[0])){echo htmlentities($answerArray[0], ENT_QUOTES);} ?></textarea> <?php if (!empty($errors['question01'])){ echo '<span class="error">' . $errors['question01'] . '</span>'; } ?> So if my Form works like I am thinking, all 10 Form Fields would end up here... Code: [Select] $answerArray[0] $answerArray[1] $answerArray[2] $answerArray[3] $answerArray[4] $answerArray[5] $answerArray[6] $answerArray[7] $answerArray[8] $answerArray[9] First of all, does that sound correct? If that part is correct, then how do I take the $answerArray[] and INSERT each value into a different record in my "answer" table?? Hope that makes sense?! Thanks, Debbie Similar TutorialsI have html form that looks like: <form method="post" action="?a=up"> ...some mysql query... while ($i = mysql_fetch_array($result)) { <input name="name[]" type="text" value="<?=$i['name'];?>" /> <input name="years[]" type="text" value="<?=abs($age);?>"/> <input name="to[]" type="checkbox" value="<?=$i['id'];?>" /> } <input name="" type="submit" value="go" /> </form> The problem I have is that I can not get the values of the form fields such as "name" and "years". I can only get a list of the ids (value of "to" checkbox). The php code looks like: $cnt = 0; for($p = 0; $p <= (sizeof($to)-1); $p++) { echo $to[$p].$name[$p].$years[$p]"<br>"; $cnt++; } $tm = array($cnt); What I'm doing wrong? Hi i would like to submit the following code to my database as a mutiple selection box. when i submit i just get the last selected value for example if i hold ctrl and press 1 2 3 4 i am only receiving 4 on my database. any ideas? thanks in advance for any help! Code: [Select] Hours Of Availability:<br> <select name="availability" multiple="multiple" size="9"> <option value="Monday - Period 1">Monday - Period 1</option> <option value="Monday - Period 2">Monday - Period 2</option> <option value="Monday - Period 3">Monday - Period 3</option> <option value="Monday - Period 4">Monday - Period 4</option> <option value="Monday - Period 5">Monday - Period 5</option> <option value="Monday - Period 6">Monday - Period 6</option> <option value="Monday - Period 7">Monday - Period 7</option> <option value="Monday - Period 8">Monday - Period 8</option> <option value="Monday - Period 9">Monday - Period 9</option> </select> <select name="availability" multiple="multiple" size="9"> <option value="Tuesday - Period 1">Tuesday - Period 1</option> <option value="Tuesday - Period 2">Tuesday - Period 2</option> <option value="Tuesday - Period 3">Tuesday - Period 3</option> <option value="Tuesday - Period 4">Tuesday - Period 4</option> <option value="Tuesday - Period 5">Tuesday - Period 5</option> <option value="Tuesday - Period 6">Tuesday - Period 6</option> <option value="Tuesday - Period 7">Tuesday - Period 7</option> <option value="Tuesday - Period 8">Tuesday - Period 8</option> <option value="Tuesday - Period 9">Tuesday - Period 9</option> </select> <select name="availability" multiple="multiple" size="9"> <option value="Wednesday - Period 1">Wednesday - Period 1</option> <option value="Wednesday - Period 2">Wednesday - Period 2</option> <option value="Wednesday - Period 3">Wednesday - Period 3</option> <option value="Wednesday - Period 4">Wednesday - Period 4</option> <option value="Wednesday - Period 5">Wednesday - Period 5</option> <option value="Wednesday - Period 6">Wednesday - Period 6</option> <option value="Wednesday - Period 7">Wednesday - Period 7</option> <option value="Wednesday - Period 8">Wednesday - Period 8</option> <option value="Wednesday - Period 9">Wednesday - Period 9</option> </select> <select name="availability" multiple="multiple" size="9"> <option value="Thursday - Period 1">Thursday - Period 1</option> <option value="Thursday - Period 2">Thursday - Period 2</option> <option value="Thursday - Period 3">Thursday - Period 3</option> <option value="Thursday - Period 4">Thursday - Period 4</option> <option value="Thursday - Period 5">Thursday - Period 5</option> <option value="Thursday - Period 6">Thursday - Period 6</option> <option value="Thursday - Period 7">Thursday - Period 7</option> <option value="Thursday - Period 8">Thursday - Period 8</option> <option value="Thursday - Period 9">Thursday - Period 9</option> </select> <select name="availability" multiple="multiple" size="9"> <option value="Friday - Period 1">Friday - Period 1</option> <option value="Friday - Period 2">Friday - Period 2</option> <option value="Friday - Period 3">Friday - Period 3</option> <option value="Friday - Period 4">Friday - Period 4</option> <option value="Friday - Period 5">Friday - Period 5</option> <option value="Friday - Period 6">Friday - Period 6</option> <option value="Friday - Period 7">Friday - Period 7</option> <option value="Friday - Period 8">Friday - Period 8</option> <option value="Friday - Period 9">Friday - Period 9</option> </select> <select name="availability" multiple="multiple" size="9"> <option value="Saturday - Period 1">Saturday - Period 1</option> <option value="Saturday - Period 2">Saturday - Period 2</option> <option value="Saturday - Period 3">Saturday - Period 3</option> <option value="Saturday - Period 4">Saturday - Period 4</option> <option value="Saturday - Period 5">Saturday - Period 5</option> <option value="Saturday - Period 6">Saturday - Period 6</option> <option value="Saturday - Period 7">Saturday - Period 7</option> <option value="Saturday - Period 8">Saturday - Period 8</option> <option value="Saturday - Period 9">Saturday - Period 9</option> </select> <br>Press + Hold Ctrl For Multiple</p> This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=320940.0 HTML code: Code: [Select] <form method="post" action="viewpage.php?page_id=5"> Email: <input name="email" type="text"><br> Full Name: <input name="name" type="text"><br> Age: <input name="age" type="text"><br> Summoner Name: <input name="summon" type="text"><br> Do you have vent? <input name="vent" type="text"><br> Do you have a mic? <input name="mic" type="text"><br> How often can you be on? <input name="online" type="text"><br> What level are you? <input name="level" type="text"><br> Who do you like to play as? <input name="champs" type="text"> </form><br> Can you help donate to the clan for vent and the site?<br> <textarea name="name" rows="7" cols="25"></textarea><br> Before you say anything about the PHP not scripted to do all fields, I already know this I'm trying to figure out how to send multiple ones in one message: PHP Code: Code: [Select] <?php if (isset($_POST['submit'])) { $to = "hidden for privacy"; $subject = "LoL Recruitment"; $email = $_REQUEST['email'] ; $message = ($_REQUEST['name'], $_REQUEST['age']) ; $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"; } } ?> I'm willing to bet my Code: [Select] $message = ($_REQUEST['name'], $_REQUEST['age']) ;if FAR wrong Hi Guys, I am attempting to create a program for a local auction house. I arrived at a stand still on a certain issue which is creating a sticky form. On the "enter auction details page" the user will be entering data as the auction is in session. 1. item Description 2. Item Price 3. Bidders Id 4. Qty Of course it would be repetitive to require the user to keep entering the same data for every bidder, so I want to stick the obvious fields which are "item description" & "Item Price" as these don't change until a new item comes up for sale. As of know I am processing the input on a separate page which records all input to the database with a redirect back to the "enter auction details page". I have tried many times to get the item description and item price fields to stick. These would need to change as the user moves onto the next item in which the description and price would change as well. Here is my current code for this part: Code: [Select] <?php session_start(); $field_itemDescription = ""; //iyem description, default as blank if (isset($_SESSION['itemDescription'])) $itemDescription = $_SESSION['itemDescription']; ?> <form action="record_trans.php" method="post"> <font face= "calibri" size= "4"> <table> <tr> <td><b>Item Description:</b></td> <td><input type= "text" name= "itemDescription" size= "30" value="<?php echo $itemDescription;?>"></td> </tr> <tr> <td><b>Item Price:</b></td> <td><input type= "text" name= "itemPrice" size= "5" value="<?php echo $itemPrice;?>"> </td> </tr> </tr> <td><b>Winning Bidders:</b></td> <td><input type="text" name= "bidderId" size= "5" /> </td> </tr> <tr> <td><b>How many deals?:</b></td> <td><input type="text" name= "itemQty" size= "3" value= "1" /></td> </tr> </table> <center><input type="submit" name="submit" value= "Save & Cont." " /></center> </form></font> Hello everyone I need your assitance a great deal, so I have a form which i submitted to a php file throug ajax and jquery. It is working A ok but I want to be able to submit it with javascript instead, so i don't load any lib. And it is now a problem. The method I use to get the form field names and values in jquery is so simple and dynamic hence if changes are made on the html form i don't have to edit my jquery file to effect the change ie in respect to changing the name of the fields or adding more fields. But I don't know to archieve this using javascript. So i want to post my jquery script, for you all my mighty programmers to assist me get a javascript Clone for me, thank you very much for Helping Jquery file $("form.ajax").on("submit", function(){ var that= $(this); that.find('[name]').each(function(index,value){ var that = $(this), name =that.attr('name'), value =that.val(); data[name]=value; }); return false;}); Now the above code is just my major focus of the script. What it does is that select the form with an ajax class attribute and run a function after the user submits the form. The var that get reference to the above form throug the (this) reference. Next i use find fuction to look through out the open and close of our form.ajax form for any element that has the name attribute and set it into array using the .each(function (index,value){}) this is my main focus how to ilterate through the form looking for name attribute and set my finding into array using javascript. The next that var reference to the find statement and then we steal the name attribute and value from our findings and set an array called data with the stolen name variable as its index n value attribute as its value. Thank you once more my aim again is with the find and array setting statement. i have my form with 5 fields that are not required to be filled out. Code: [Select] <input class="inputbg" type="text" name="MAC[]" /> <input class="inputbg" type="text" name="MAC[]" /> <input class="inputbg" type="text" name="MAC[]" /> <input class="inputbg" type="text" name="MAC[]" /> <input class="inputbg" type="text" name="MAC[]" /> On my process page I want to remove all of the empty index's that did not have data entered. I am new to sending array data via POST do I need to do anything else other then what is below? Code: [Select] foreach($MAC as $key => $value) { if($value == "") { unset($MAC[$key]); } } $mac_addresses = array_values($MAC); if(empty($mac_addresses)){ $error = "You did not enter any MAC adresses."; $valid = "false"; } In brief, I'm attempting to capture the form data from a dynamic form to a mysql database. From he
To He
The post data looks like this from the form - Array(
... ) PHP CODE:
... As a non-php or mysql developer, I'm learning on the fly. This is a section of the php file that I was using to post the form data to mySQL. This worked great up to the point I added the dynamic form widget. <?php // This function will run within each post array including multi-dimensional arrays function ExtendedAddslash(&$params) { foreach ($params as &$var) { // check if $var is an array. If yes, it will start another ExtendedAddslash() function to loop to each key inside. is_array($var) ? ExtendedAddslash($var) : $var=addslashes($var); unset($var); } } // Initialize ExtendedAddslash() function for every $_POST variable ExtendedAddslash($_POST); $submission_id = $_POST['submission_id']; $formID =$_POST['formID']; $ip =$_POST['ip']; $fname =$_POST['fname']; $lname =$_POST['lname']; $spousename =$_POST['spousename']; $address =$_POST['address'][0]." ".$_POST['address'][1]." ".$_POST['address'][2]." ".$_POST['address'][3]." ".$_POST['address'][4]." ".$_POST['address'][5]; ... $db_host = 'localhost'; $db_username = 'xxxxx'; $db_password = 'xxxxx'; $db_name = 'xxxxx'; mysql_connect( $db_host, $db_username, $db_password) or die(mysql_error()); mysql_select_db($db_name); // search submission ID $query = "SELECT * FROM `tableName` WHERE `submission_id` = '$submission_id'"; $sqlsearch = mysql_query($query); $resultcount = mysql_numrows($sqlsearch); if ($resultcount > 0) { mysql_query("UPDATE `tableName` SET `fname` = '$fname', `lname` = '$lname', `spousename` = '$spousename', `address` = '$address', WHERE `submission_id` = '$submission_id'") or die(mysql_error()); } else { mysql_query("INSERT INTO `tableName` (submission_id, formID, IP, fname, lname, spousename, address) VALUES ('$submission_id', '$formID', '$ip', '$fname', '$lname', '$spousename', '$address') ") or die(mysql_error()); } ?> It has been suggested that I explore using the PHP Explode() function. It's possible that may work, but can't get my head around how to apply the function to the PETLIST Array. Looking for suggestions or direction to find a solution for this challenge. Looking forward to any replies. First, Happy X-Mas to all! I want to do a form for entering dog-show results. On first site of form the user is able to enter how many dogs for each class (there are youth and open class for example) he want to insert. So on second site there will be formfields for every dog in every class, created with php. User should be able to take dogname from jquery autocomplete - this works for multiple fields. But i need the according id to the dogname - and actual only one id is given - the first one is changing by choosing from autocomplete in next fields... Data came from a json array like 0: {dogidindatabase: "9892", value: "Excalibur Khali des Gardiens de la Cour ",…} dogidindatabase: "9892" label: "<img src='../main/img/female.png' height='20'>Excalibur Khali des Gardiens de la Cour " value: "Excalibur Khali des Gardiens de la Cour " 1: {dogidindatabase: "15942", value: "Excalibur from Bandit's World Kalli",…} dogidindatabase: "15942" label: "<img src='../main/img/male.png' height='20'>Excalibur from Bandit's World Kalli" value: "Excalibur from Bandit's World Kalli"all i need is inside ... the script in form is <script type='text/javascript'> //<![CDATA[ $(function() { $(".dog").autocomplete({ source: "xxx.php", minLength: 3, select: function(event, ui) { $('#dogidindatabase').val(ui.item.dogidindatabase); } }); $["ui"]["autocomplete"].prototype["_renderItem"] = function( ul, item) { return $( "<li></li>" ) .data( "item.autocomplete", item ) .append( $( "<a></a>" ).html( item.label ) ) .appendTo( ul ); }; }); //]]> </script>and the form looked like <input type='text' name='dog' class='dog' value='".strip_tags(${'dogname' .($countbabymale+1)})."' size='35' data-required='true' /><br> <input class='readonly' readonly='readonly' type='text' id='dogidindatabase' name='dogidindatabase' size='5' />I changed in script and form id='dogidindatabase' to class, but it doesn´t work. Testsite is under http://www.wolfdog-d...how.php?lang=de (only german at first) - Insert a number (higher than 1) under baby 3-6 (first box, the others are not working for testing); submit to get to page 2; you see all post-variables (for testing). Try to insert a dogname in first input-field (choose "exc") and insert first one - the id is under dogname. In second dogname inputfield you can choose second dog - the id for the first one changes to id of seond one .... How can i get both for every dog? I need some advice, I'm not sure if this is the right section to post this or not but I'll give it a try. I am creating a website for a small group of people to be able to message back and forth. I ran into a problem when doing the whole reply to a message option. I dont want to have each individual message as a new entry in my database, and then look for each message in that conversation when loading the conversation, I thought about inserting something like +=+=+=+=+=+= in between messages in the conversation so that when i pull up that conversation i could just separate the messages into an array by looking for that +=+=+=+=+=+= in the string of text and separating all the messages out. I want to know if anyone knows a better way of doing this or if this is a good way to go. thanks for any suggestions. Okay I'm a newbie at PHP but was trying to write a counter for my website to count the amount of times a specific button is clicked. My desired outcome is as follows: If the form submit button "like" or "dislike" is clicked, get user's ip and check to see if it already exists in the database. If it exists, don't increment the count (of either button), otherwise log the ip and increment the count (of whichever button is clicked) by 1. Currently I've got the increment working (testing only the like button at the moment) and I've got the ip being stored into the database, but cannot get the comparison to work. Each time the button is clicked it adds the ip address into the database instead of disallowing it. Note: there are two different tables--one storing the ip (counter) and one storing the like clicks (Designs) (dunno if there's a better way?) Excuse my newbieness. The problem area: (like button only): if(isset($_POST['like'])) { $ip_address = $_SERVER['REMOTE_ADDR']; $query = mysql_query("SELECT ip FROM counter WHERE ip = '$ip_address'"); $num_rows = mysql_num_rows($query); if ($num_rows > 0) { die ("You've already clicked the button!"); } else { mysql_query("INSERT INTO counter VALUES ($ip_address)"); mysql_query("UPDATE Designs SET up = up + 1 WHERE ref = 'cataclysm'"); } } $select = mysql_query("SELECT up FROM Designs"); while($row = mysql_fetch_array($select)) { echo $row['up']; } Hello,
I have a table with these columns (database)
table.JPG 34.95KB
0 downloads
and i have a static form through which user define the installments. Static 24 input boxes are there like this
<form name="installment" method="post" action="" enctype="multipart/form-data" onsubmit="return validate()"> <table id="dt_hScroll" class="table table-striped"> <thead> <tr> <th>SL No.</th> <th>Amount</th> <th>Due Date</th> </tr> <tr> <td> 1. </td> <td> <input type="text" name="installment1" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date1" class="tcal span4" value="<?php //echo date("Y-m-d"); ?>" /> </td> </tr> <tr> <td> 2. </td> <td> <input type="text" name="installment2" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date2" class="tcal span4" /> </td> </tr> <tr> <td> 3. </td> <td> <input type="text" name="installment3" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date3" class="tcal span4" /> </td></tr> <tr> <td> 4. </td> <td> <input type="text" name="installment4" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date4" class="tcal span4" /> </td></tr> <tr> <td> 5. </td> <td> <input type="text" name="installment5" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date5" class="tcal span4" /> </td></tr> <tr> <td> 6. </td> <td> <input type="text" name="installment6" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date6" class="tcal span4" /> </td></tr> <tr> <td> 7. </td> <td> <input type="text" name="installment7" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date7" class="tcal span4" /> </td></tr> <tr> <td> 8. </td> <td> <input type="text" name="installment8" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date8" class="tcal span4" /> </td></tr> <tr> <td> 9. </td> <td> <input type="text" name="installment9" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date9" class="tcal span4" /> </td></tr> <tr> <td> 10. </td> <td> <input type="text" name="installment10" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date10" class="tcal span4" /> </td></tr> <tr> <td> 11. </td> <td> <input type="text" name="installment11" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date11" class="tcal span4" /> </td></tr> <tr> <td> 12. </td> <td> <input type="text" name="installment12" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date12" class="tcal span4" /> </td></tr> <tr> <td> 13. </td> <td> <input type="text" name="installment13" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date13" class="tcal span4" /> </td></tr> <tr> <td> 14. </td> <td> <input type="text" name="installment14" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date14" class="tcal span4" /> </td></tr> <tr> <td> 15. </td> <td> <input type="text" name="installment15" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date15" class="tcal span4" /> </td></tr> <tr> <td> 16. </td> <td> <input type="text" name="installment16" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date16" class="tcal span4" /> </td></tr> <tr> <td> 17. </td> <td> <input type="text" name="installment17" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date17" class="tcal span4" /> </td></tr> <tr> <td> 18. </td> <td> <input type="text" name="installment18" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date18" class="tcal span4" /> </td></tr> <tr> <td> 19. </td> <td> <input type="text" name="installment19" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date19" class="tcal span4" /> </td></tr> <tr> <td> 20. </td> <td> <input type="text" name="installment20" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date20" class="tcal span4" /> </td></tr> <tr> <td> 21. </td> <td> <input type="text" name="installment21" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date21" class="tcal span4" /> </td></tr> <tr> <td> 22. </td> <td> <input type="text" name="installment22" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date22" class="tcal span4" /> </td></tr> <tr> <td>23. </td> <td> <input type="text" name="installment23" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date23" class="tcal span4" /> </td></tr> <tr> <td> 24. </td> <td> <input type="text" name="installment24" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date24" class="tcal span4" /> </td></tr> <tr><td></td><td> <input type="submit" name="save" id="save" value="Save" class="btn btn-info span3" /> <input type="hidden" readonly="readonly" name="roll_no" value="<?php echo $roll_no; ?>" class="span5" /> </td><td></td></tr> </thead> </table> </form>Here i am not getting how to store it in that table. Actually all the 24 inputs are not mandatory. If user fills only 2 then also it should store it in the database table. I tried to do like this if(isset($_POST['save'])) { $roll_no = $_POST['roll_no']; $ins_amt1 = $_POST['installment1']; $due_date1 = $_POST['due_date1']; $ins_amt2 = $_POST['installment2']; $due_date2 = $_POST['due_date2']; $ins_amt3 = $_POST['installment3']; $due_date3 = $_POST['due_date3']; $ins_amt4 = $_POST['installment4']; $due_date4 = $_POST['due_date4']; $ins_amt5 = $_POST['installment5']; $due_date5 = $_POST['due_date5']; $ins_amt6 = $_POST['installment6']; $due_date6 = $_POST['due_date6']; $ins_amt7 = $_POST['installment7']; $due_date7 = $_POST['due_date7']; $ins_amt8 = $_POST['installment8']; $due_date8 = $_POST['due_date8']; $ins_amt9 = $_POST['installment9']; $due_date9 = $_POST['due_date9']; $ins_amt10 = $_POST['installment10']; $due_date10 = $_POST['due_date10']; $ins_amt11 = $_POST['installment11']; $due_date11 = $_POST['due_date11']; $ins_amt12 = $_POST['installment12']; $due_date12 = $_POST['due_date12']; $ins_amt13 = $_POST['installment13']; $due_date13 = $_POST['due_date13']; $ins_amt14 = $_POST['installment14']; $due_date14 = $_POST['due_date14']; $ins_amt15 = $_POST['installment15']; $due_date15 = $_POST['due_date15']; $ins_amt16 = $_POST['installment16']; $due_date16 = $_POST['due_date16']; $ins_amt17 = $_POST['installment17']; $due_date17 = $_POST['due_date17']; $ins_amt18 = $_POST['installment18']; $due_date18 = $_POST['due_date18']; $ins_amt19 = $_POST['installment19']; $due_date19 = $_POST['due_date19']; $ins_amt20 = $_POST['installment20']; $due_date20 = $_POST['due_date20']; $ins_amt21 = $_POST['installment21']; $due_date21 = $_POST['due_date21']; $ins_amt22 = $_POST['installment22']; $due_date22 = $_POST['due_date22']; $ins_amt23 = $_POST['installment23']; $due_date23 = $_POST['due_date23']; $ins_amt24 = $_POST['installment24']; $due_date24 = $_POST['due_date24']; $items = array(); $installment[] =array($ins_amt1, $ins_amt2, $ins_amt3, $ins_amt4, $ins_amt5, $ins_amt6, $ins_amt7, $ins_amt8, $ins_amt9, $ins_amt10, $ins_amt11, $ins_amt12, $ins_amt13, $ins_amt14, $ins_amt15, $ins_amt16, $ins_amt17, $ins_amt18, $ins_amt19, $ins_amt20, $ins_amt21, $ins_amt22, $ins_amt23, $ins_amt24); //$in_values= serialize($installment); $due_date[] = array($due_date1, $due_date2, $due_date3, $due_date4, $due_date5, $due_date6, $due_date7, $due_date8, $due_date9, $due_date10, $due_date11, $due_date12, $due_date13, $due_date14, $due_date15, $due_date16, $due_date17, $due_date18, $due_date19, $due_date20, $due_date21, $due_date22, $due_date23, $due_date24); //$in_dates= serialize($due_date); //$s1 = "insert into installment(id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) values ('', ".$fee_id.", '".$roll_no."', ".$in_values.", '".$in_dates."', '', 'unpaid', ''"; foreach($installment as $row_key => $value) { $item = $value; $uom = $due_date[$row_key]; $items[] = sprintf("(%d, %d, '%s', %d, '%s', '%s', '%s', '%s')", '', $fee_id, mysql_real_escape_string($roll_no), intval($item), $uom, '', '', '' ); } $msql = 'INSERT INTO installment (id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) VALUES '.implode(', ', $items);But it is taking only one data. Can somebody please suggest. The data has to be saved like this saveddata.JPG 70.92KB 0 downloads Somebody please help. Thank you Hello all, I'm currently working on a project and it is the first time I have had to store/retrieve an array with PHP and MySQL. Basically its a website that has a list of discounts/coupons on it. People can register and submit their discounts and such. I am storing an array for who is eligible for the discount, as well as which categories the discount falls under. I did some googling and there seems to be tons of thoughts on the best way to do this. Some say to use implode/explode, some say to serialize/unserialize, I was just wondering if there is a common, concrete way to do this? I will need to be able to search the array for its contents. So if children are eligible for the discount, I need to be able to store that in a database, retrieve it later, and search it for only "Children" so I can display the discounts available only to children. If someone could please advise the best way to do this and post some examples, it would be greatly appreciated. I learn best with examples that are explained properly. Script:
<?php // For example, the entries in the table. $entry1 = "text1"; $entry2 = "text2"; $entry3 = "text3"; // For example, the ID numbers in the table. $value1 = "140"; $value2 = "141"; $value3 = "142"; echo "<form method='POST' action='" . $_SERVER['PHP_SELF'] . "'>"; echo "<input type='checkbox' name='hashtag_modify_checkbox[]' value='" . $value1 . "' />"; echo "Modify"; echo "<input type='text' name='hashtag_name[]' value='" . $entry1 . "' />"; echo "<input type='checkbox' name='hashtag_modify_checkbox[]' value='" . $value2 . "' />"; echo "Modify"; echo "<input type='text' name='hashtag_name[]' value='" . $entry2 . "' />"; echo "<input type='checkbox' name='hashtag_modify_checkbox[]' value='" . $value3 . "' />"; echo "Modify"; echo "<input type='text' name='hashtag_name[]' value='" . $entry3 . "' />"; echo "<input type='submit' name='submit' />"; echo "</form>"; // Here, only store those hashtag names where the "modify" checkbox is checked. ?>This is used for the admin panel. It is a form where the input fields hold the text ("hashtags") already inside of them. Basically, one would have to check the "modify checkbox" to modify a hashtag, then only the modified hashtags should get stored into an array. How to have those hashtags stored in the array with the checked checkbox as the factor? The suggestions are much appreciated. Edited by glassfish, 23 October 2014 - 10:06 AM. I've got an array like this: $firstquarter = array('January', 'February', 'March'); Then I'm adding it to a MySQL DB as follows: $insert = "INSERT INTO sometable (months) VALUES ('$firstquarter') "; $insertresult = mysql_query($insert) or die ('Error in Insert query: ' . mysql_error()); When I use PHPMyAdmin I see a this value stored in the DB: 'Array' Can I retrieve the values, by index, from this database field?? Hello again, guys! I have a couple of questions that I hope anyone can answer. I am making a form that is storing the information in a database, and in this form I also want images to be uploaded. I want to make a function that allows the user to upload as many images as they would like to have in their ad on my website, and I also need something that can handle the upload process, and see how many images the user is trying to upload. Any easy solutions for this? I also have another question: As you can see on the example image underneath this text, I have a form with multiple inputs where the user is suppose to choose how many inputs they want to fill in themself. How should I store this information in the database, and how can I make a script that detects how many of the forms the user actually filled? I hope you guys understood what I was trying to say, and I thank you all anyways. Underneath you can see an image of my forms. Example image: Cheers, Marius Hi all I have a question about how to store parsed data into a multidimensional arrays -- I can store items into an array, but multidimensional arrays mystify me a bit. Any help would be greatly appreciated. I'm storing the images in a table, grouped according to their table and their descriptions, so that later when I call the images, I can display them accordingly. I'm using the Simple HTML DOM Parser. So say I have two tables, one with three images, and another with one. I'd like the resulting to array to look like: Code: [Select] Array ( [0] => Array ( [0] => image1.jpg [1] => 1st Variation Description ) [1] => Array ( [0] => image2.jpg [1] => image3.jpg [2] => image4.jpg [3] => 2nd Variation Description ) ) This is what I have so far: Code: [Select] $html = str_get_html($vartables); $varinfo = array(); foreach($html->find('table') as $table){ $varinfo[] = $table->innertext; } print_r($varinfo); Which yields: Code: [Select] Array ( [0] => <tr> <td width=150> Description1 </td> <td><a href="image1.jpg"> <img src="image1" height=100 border=1></a> </td> </tr> [1] => <tr> <td width=150> Description2 </td> <td><a href="image2.jpg"> <img src="image2.jpg" height=200 border=1></a> </td> <td><a href="image3.jpg"> <img src="image3.jpg" height=200 border=1></a> </td> <td><a href="image4.jpg"> <img src="image4.jpg" height=200 border=1></a> </td> </tr> ) I'd like to strip out the html and keep the .jpg's and descriptions together in a multidimensional array...unfortunately my newbness is getting the better of me there, I'm researching but running into a roadblock. Thanks in advance for any help. i want to store some data that i have gained from a request at the planetfile of openstreetmap: so i have set up a database on my opensuse 13.1 i have created a db called test on the mysql-server on my opensuse: CREATE TABLE `pois` ( `id` bigint(20) unsigned NOT NULL, `lat` float(10,7) NOT NULL, `lon` float(10,7) NOT NULL, PRIMARY KEY (`id`) ) CREATE TABLE `pois_tag` ( `poisid` int(11) NOT NULL DEFAULT '0', `tagname` varchar(45) NOT NULL DEFAULT '', `tagvalue` varchar(255) DEFAULT NULL, PRIMARY KEY (`poisid`,`tagname`) ) Where each tagname/value pair is stored as a row in a separate table with the pois id Processing would be like this <?php $db = new mysqli(localhost,root,rimbaud,'test'); // use your credentials $xmlstr = <<<XML <data> <node id="2064639440" lat="49.4873181" lon="8.4710548"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="turkish"/> <tag k="email" v="info@lynso.de"/> <tag k="name" v="Kilim - Café und Bar Restaurant"/> <tag k="opening_hours" v="Su-Th 17:00-1:00; Fr, Sa 17:00-3:00"/> <tag k="operator" v="Cengiz Kaya"/> <tag k="phone" v="06 21 - 43 755 371"/> <tag k="website" v="http://www.kilim-mannheim.de/"/> </node> <node id="2126473801" lat="49.4851170" lon="8.4756295"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="italian"/> <tag k="email" v="mannheim1@vapiano.de"/> <tag k="fax" v="+49 621 1259 779"/> <tag k="name" v="Vapiano"/> <tag k="opening_hours" v="Su-Th 10:00-24:00; Fr-Sa 10:00-01:00"/> <tag k="operator" v="Vapiano"/> <tag k="phone" v="+49 621 1259 777"/> <tag k="website" v="http://www.vapiano.de/newsroom/?store=29"/> <tag k="wheelchair" v="yes"/> </node> <node id="667927886" lat="49.4909673" lon="8.4764904"> <tag k="addr:city" v="Mannheim"/> <tag k="addr:country" v="DE"/> <tag k="addr:housenumber" v="5"/> <tag k="addr:postcode" v="68161"/> <tag k="addr:street" v="Collinistraße"/> <tag k="amenity" v="restaurant"/> <tag k="name" v="Churrascaria Brasil Tropical"/> <tag k="phone" v="+496211225596"/> <tag k="wheelchair" v="limited"/> </node> <node id="689928440" lat="49.4798794" lon="8.4853418"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="greek"/> <tag k="email" v="epirus70@hotmail.de"/> <tag k="fax" v="0621/4407 762"/> <tag k="name" v="Epirus"/> <tag k="opening_hours" v="Mo-Sa 12:00-15:00,18:00-24:00"/> <tag k="phone" v="0621/4407 761"/> <tag k="smoking" v="separated"/> <tag k="website" v="http://epirus-ma.blogspot.com/"/> <tag k="wheelchair" v="no"/> </node> <node id="689928445" lat="49.4799409" lon="8.4851357"> <tag k="amenity" v="restaurant"/> <tag k="cuisine" v="italian"/> <tag k="email" v="gianlucascurti@ristorante-augusta.de"/> <tag k="name" v="Ristorante Augusta"/> <tag k="opening_hours" v="Mo-Fr 12:00-14:00,18:00-23:00;Su 12:00-14:00,18:00-23:00"/> <tag k="phone" v="0621 449872"/> <tag k="website" v="ristorante-augusta.com/"/> <tag k="wheelchair" v="no"/> </node> </data> XML; $fields = array('id','name','lat','lon'); $xml = simplexml_load_string($xmlstr); // // PROCESS XML RECORDS // $poisdata = array(); $tagdata = array(); foreach ($xml->node as $node) { $nodedata = array_fill_keys($fields,''); $nodedata['id'] = intval($node['id']); $nodedata['lat'] = isset($node['lat']) ? floatval($node['lat']) : 0; $nodedata['lon'] = isset($node['lon']) ? floatval($node['lon']) : 0; $poisdata[] = vsprintf("(%d, %10.7f, %10.7f)", $nodedata); foreach ($node->tag as $tag) { $k = (string)$tag['k']; $v = (string)$tag['v']; $tagdata[] = sprintf("(%d, '%s', '%s')" , $nodedata['id'] , $db->real_escape_string($k) , $db->real_escape_string($v)); } } // // STORE THE DATA // $sql = "REPLACE INTO pois ('id','lat','lon') VALUES\n" . join(",\n", $poisdata); $db->query($sql); $sql = "REPLACE INTO pois_tag (poisid, tagname, tagvalue) VALUES\n" . join(",\n", $tagdata); $db->query($sql); // // DISPLAY THE DATA // $currentTags = array(); $sql = "SELECT DISTINCT tagname FROM pois_tag ORDER BY tagname = 'name' DESC, tagname"; $res = $db->query($sql); while (list($tn) = $res->fetch_row()) { $currentTags[] = $tn; } $thead = "<tr><th>id</th><th>lat</th><th>lon</th><th>" . join('</th><th>', $currentTags) . "</th></tr>\n"; $currid = $currlat = $currlon = 0; $sql = "SELECT p.id, lat, lon, tagname, tagvalue FROM pois p LEFT JOIN pois_tag t ON t.poisid = p.id ORDER BY p.id"; $res = $db->query($sql); $tdata = ''; while (list($id, $lat, $lon, $t, $v) = $res->fetch_row()) { if ($currid != $id) { if ($currid) { $tdata .= "<tr><td>$currid</td><td>$currlat</td><td>$currlon</td><td>" . join('</td><td>', $poisrow) . "</td></tr>\n"; } $currid = $id; $currlat = $lat; $currlon = $lon; $poisrow = array_fill_keys($currentTags,''); } $poisrow[$t] = $v; } $tdata .= "<tr><td>$currid</td><td>$currlat</td><td>$currlon</td><td>" . join('</td><td>', $poisrow) . "</td></tr>\n"; ?> <html> <head> <meta name="generator" content="PhpED 12.0 (Build 12010, 64bit)"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Tags</title> <meta name="author" content="Barand"> <meta name="creation-date" content="06/04/2014"> <style type="text/css"> body, td, th { font-family: arial, sans-serif; font-size: 10pt; } table { border-collapse: collapse; } th { background-color: #369; color: white; padding: 5px 2px; } td { background-color: #EEE; padding: 2px; } </style> </head> <body> <table border='1'> <?php echo $thead, $tdata; ?> </table> </body> </html> leeeds to the following errors.... PHP Fatal error: Call to a member function fetch_row() on a non-object in /home/martin/php/osm_200.php on line 121 martin@linux-70ce:~/php> php osm_200.php PHP Notice: Use of undefined constant localhost - assumed 'localhost' in /home/martin/php/osm_200.php on line 3 PHP Notice: Use of undefined constant root - assumed 'root' in /home/martin/php/osm_200.php on line 3 PHP Notice: Use of undefined constant rimbaud - assumed 'rimbaud' in /home/martin/php/osm_200.php on line 3 PHP Fatal error: Call to a member function fetch_row() on a non-object in /home/martin/php/osm_200.php on line 121 martin@linux-70ce:~/php> so what goes wrong here...? Hi, just a very simple question: I have an array as follows: $langList = array('English', 'French', 'German', 'Dutch'); What's the easiest way to store this array in an external file, so that multiple php scripts can access its contents? And what is then the php line I need to retrieve the array from the external file? Thanks! Hey there - how are you? I'm trying to add up multiple fields from a table and it's mostly working but I have one curious error. It always seems to miss the field upgrade6_fee. I'm totally baffled. I thought it was my syntax but I'm not seeing anything wrong with it. Any ideas? Otherwise it all seems to be working. <?php $query = "SELECT fee1, upgrade3_fee, upgrade4_fee, upgrade5_fee, upgrade6_fee, upgrade7_fee, SUM(fee1 + upgrade3_fee + upgrade4_fee + upgrade5_fee + upgrade6_fee + upgrade7_fee) AS ttotal FROM Register"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo number_format(($row['ttotal']), 2); } ?> |