PHP - Single Input Name And Multiple Values
I have the form:
Similar Tutorials
Table Issue - Multiple Location Values For User Pushes Values Out Of Row Instead Of Wrapping In Cell
Hey all, I am building a simple cms. I have a posts table and I have an images table. A post has many images and images has a foreign key to the posts table. So when a user edits, updates, creates, and deletes a post, they affect the images related to the post. Sometimes a post can have more than one image, like three images. Hence I rendered this in the view (note that I am using a datamapper that converts tables to objects and fields to key/value pairs): Code: [Select] foreach($records as $post){ echo form_open_multipart("homes/update/$post->id"); //File uploads require a multipart form. Default form handling uses the application/x-www-form-urlencoded content type. Multipart forms use the multipart/form-data encoding. //this is critical to pass the id as part of the action attribute of the form, so we can use our params hash to target the id to update the specific record echo label('Update Title'); echo form_input('title',$post->title); echo label('Update Body'); echo form_textarea('body',$post->body); $images = $post->images->include_join_fields()->get(); if(!is_null($images->image_file_name)){ echo label('Update Images'); foreach($images as $image){ echo form_upload('image_file_name',$image->image_file_name); } } } echo form_submit('submit','Update'); The above line of code will render a few input file types. The problem occurs during posting to my update method. It is looking for one parameter from the input file field and so if I upload three different images, it will only look for one and write only one to database: Code: [Select] $field_name = 'image_file_name'; if ( ! $this->upload->do_upload($field_name)){ $error = array('error' => $this->upload->display_errors()); echo $error['error']; // redirect('homes/edit'); } else { $data = array('upload_data' => $this->upload->data()); $image_file_name = $data['upload_data']['file_name']; Is it possible to do wht I am trying to do? Should I only have on input file type per form submission or is that I need to fix the code to accomodate for multiple submissions by creating an array of sorts? Thanks for response. I have a textarea feild in my form where the user can type in several keywords such as Textarea Box Below Cars Trains Buses I have a database with the meanings of the words entered and want to be able to get the three definitions from the database on for submission. In a normal input box where i only type one word i can grab no problem like so $word = $_POST['word']; $sql = "SELECT meaning FROM table WHERE word='$word'"; Though i am trying to get multiple values from the same textarea box So if a user types in 3 words the query would query the database on thoses three words, the problem is i dont know how to get the diffrent words from the form for example $first = $_POST['word']; which would be the first word $sec = $_POST['word']; which would be the second word etc. Any help here would be great thanks. PHP script return 20 UL LIST values like, < ul >
A < /ul > How to display UL LIST into row wise 5 columns like
A B C D Dear All Members here is my table data.. (4 Columns/1row in mysql table)
id order_no order_date miles How to split(miles) single column into (state, miles) two columns and output like following 5 columns /4rows in mysql using php code.
(5 Columns in mysql table) id order_no order_date state miles 310 001 02-15-2020 MI 108.53 310 001 02-15-2020 Oh 194.57 310 001 02-15-2020 PA 182.22
310 001 02-15-2020 WA 238.57 ------------------my php code -----------
<?php
if(isset($_POST["add"]))
$miles = explode("\r\n", $_POST["miles"]);
$query = $dbh->prepare($sql);
$lastInsertId = $dbh->lastInsertId(); if($query->execute()) {
$sql = "update tis_invoice set flag='1' where order_no=:order_no"; $query->execute();
} ----------------- my form code ------------------
<?php -- Can any one help how to correct my code..present nothing inserted on table
Thank You Edited February 8, 2020 by karthicbabuHi, My company has 240+ locations and as such some users (general managers) cover multiple sites. When I run a query to pull user information, when the user has multiple sites to his or her name, its adds the second / third sites to the next columns, rather than wrapping it inside the same table cell. It also works the opposite way, if a piece of data is missing in the database and is blank, its pull the following columns in. Both cases mess up the table and formatting. I'm extremely new to any kind of programming and maybe this isn't the forum for this question but figured I'd give it a chance since I'm stuck. The HTML/PHP code is below: <table id="datatables-column-search-select-inputs" class="table table-striped" style="width:100%"> <thead> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> <th>Actions</th> </tr> </thead> <tbody> <?php //QUERY TO SELECT ALL USERS FROM DATABASE $query = "SELECT * FROM users"; $select_users = mysqli_query($connection,$query);
// SET VARIABLE TO ARRAY FROM QUERY while($row = mysqli_fetch_assoc($select_users)) { $user_id = $row['user_id']; $user_firstname = $row['user_firstname']; $user_lastname = $row['user_lastname']; $username = $row['username']; $user_phone = $row['user_phone']; $user_image = $row['user_image']; $user_title_id = $row['user_title_id']; $user_role_id = $row['user_role_id'];
// POPULATES DATA INTO THE TABLE echo "<tr>"; echo "<td>{$user_id}</td>"; echo "<td>{$user_firstname}</td>"; echo "<td>{$user_lastname}</td>"; echo "<td>{$username}</td>"; echo "<td>{$user_phone}</td>";
//PULL SITE STATUS BASED ON SITE STATUS ID $query = "SELECT * FROM sites WHERE site_manager_id = {$user_id} "; $select_site = mysqli_query($connection, $query); while($row = mysqli_fetch_assoc($select_site)) { $site_name = $row['site_name']; echo "<td>{$site_name}</td>"; } echo "<td>{$user_title_id}</td>"; echo "<td>{$user_role_id}</td>"; echo "<td class='table-action'> <a href='#'><i class='align-middle' data-feather='edit-2'></i></a> <a href='#'><i class='align-middle' data-feather='trash'></i></a> </td>"; //echo "<td><a href='users.php?source=edit_user&p_id={$user_id}'>Edit</a></td>"; echo "</tr>"; } ?>
<tr> <td>ID</td> <td>FirstName</td> <td>LastName</td> <td>Username</td> <td>Phone #</td> <td>Location</td> <td>Title</td> <td>Role</td> <td class="table-action"> <a href="#"><i class="align-middle" data-feather="edit-2"></i></a> <a href="#"><i class="align-middle" data-feather="trash"></i></a> </td> </tr> </tbody> <tfoot> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> </tr> </tfoot> </table>
Hey, If i have a string which contains numbers and symbols... such as 1:2:4 (its not always : for the symbol it changes) Is there a function that can convert the numbers that are 9 or less to have a 0 infront of them such as: 01:02:04 (also this is not timestamp format - just normal strings) 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 can use the first while loop, but there is no data in the second while loop. Is there a better way as I have never done this before... Code: [Select] <?php $featured_results = mysql_query("SELECT * FROM products LEFT JOIN product_images ON products.product_id=product_images.product_id WHERE products.product_featured='1' AND products.product_active='1' AND thumb='1'"); $fa=0; while($featured_row = mysql_fetch_assoc($featured_results)) { $fthumb_result = mysql_query("SELECT image_name FROM product_images WHERE product_id='".$featured_row['product_id']."' AND thumb='1'"); $fthumb = mysql_fetch_row($fthumb_result); if ($fa==0) { echo "\n<img id=\"home-slider-photo-".$fa."\" class=\"home-slider-photo preload\" src=\"/includes/getimage.php?img=".$fthumb[0]."&w=370&h=370\" alt=\"\" />"; } else { echo "\n<img id=\"home-slider-photo-".$fa."\" class=\"home-slider-photo preload home-slider-photo-unsel\" src=\"/includes/getimage.php?img=".$fthumb[0]."&w=370&h=370\" alt=\"\" />"; } $fa++; } echo "<div id=\"home-slider-photo-price\">"; $fb=0; while($featured_row2 = mysql_fetch_assoc($featured_results)) { if ($fb==0) { echo "\n<div id=\"home-slider-photo-price-".$fb."\" class=\"home-slider-photo-price\">\n<span>only</span>$".$featured_row2['product_price']."\n</div>"; } else { echo "\n<div id=\"home-slider-photo-price-".$fb."\" class=\"home-slider-photo-price home-slider-photo-price-unsel\">\n<span>only</span>$".$featured_row2['product_price']."\n</div>"; } $fb++; } echo "</div>"; ?> Hi.
I have a product database w/ tables each for product series, model, sub-model and optionals. One item in each of these makes up one product. So Series K, Model 7, sub-model 2, optional 3 will be a product called K 7/2-3 .The permutations and combinations of these are all possible products.
In the same db, I have a quotations table. Each quotation has a unique id / record. A quotation can include any number of products : it can have K 7/2-3, KA 561/1-2 , FPN 311/2-1 or it can only have KA 561/1-2 etc.
Now I am stuck. Don't know how to
a. structure the quotations table
b. create a MySQL select so that one statement can make multiple selections . I thought of using a checkbox but that doesn't work either since the series/model/sub model/optionals must chosen sequentially.
Any ideas I can follow thru ?
Many thanks
Swati
Hey guys, I'll be the first to say that I'm a real php n00b, and only understand the basics. I have a website already in place that someone else coded and I just need to add something to. There's a form that posts to another page and then back to a sql database. What I want to do is have the form also email me the contents of the form when it is submitted. Is there a way to have a form do multiple actions? I'm not sure the best way to go about this, so if someone has some pointers, I'd really appreciate it. Thanks! Hi there im trying to set a single variable multiple rows of data that are echoed using a single variable. The trouble is i just cant seem to make it work by trying to add a while or do loop.. The variable is $alderaanfleetalt and consists of: Code: [Select] $fleetname = "FleetName"; $shipname = "Ship Name"; Which is just text stored in two other variables. The select query row of data is added the $alderaanfleetalt variable. Code: [Select] $alderaanfleetalt = $fleetname." ".$row_Alderaanfleet['FleetName']."</br>".$shipname." ".$row_Alderaanfleet['ShipName']; At the moment only a single row appears. ive tried to add a while/do loop so that multiple rows are outputted but its not working. Code: [Select] do{ $alderaanfleetalt = $fleetname." ".$row_Alderaanfleet['FleetName']."</br>".$shipname." ".$row_Alderaanfleet['ShipName']; } while ($row_Alderaanfleet = mysql_fetch_assoc($Alderaanfleet)); Im a bit lost here and not even sure it can be done this way... Any help would be ace. Thank you Hi all, slightly confusing title! What I am trying to do is make a simple stores system whereby I can add and remove stores. It is purely php and no mySQL. My idea was to create a text file with the individual number and then include the file on the table on the page. I have worked out how to increment one value by one, but the others I am struggling with. Example I wish to have two links one which I click to increase and another to decrease the value by one. It's the multiple issue that is confusing me, I create a txt file and a php file using a variable from a submitted form (part number). The php file holds info and the text file holds the number which is default at '0' (Zero). My idea was to write some php to the file, perhaps when I click the plus it will open and write to the file + 1 .. Any guidance or points in the right direction would be greatly appreciated. Thanks. Shugs Hi, I believe this is my first post on here. First off let me say thank you for silently helping out in the past while I keep on learning PHP. I have decided to build an image gallery, and I am having problems with the page numbering links and the breadcrumbs. Reson I decided to build my own is that I wanted a challange to learn more. I could not find anything that would intregrate with the site as I wanted it to (pulled as a function so offers some customising with options). The problem that I am having is that the <a href= tag is starting to give multipul "/"s when I only need one, so that the url at the top is coming up as http://localhost/mmv4/gallery/pics///Ax/Ax_Jo/ when I am wanting http://localhost/mmv4/gallery/pics/Ax/Ax_Jo/IMG_4244.JPG. I have used str_replace to catch //s and more, but this then adds odd slashes on the end so the page numbeing is getting odd results. some dirs have the / on the end and some do not, so the links are sometimes "visited" and others not. I beleve that the problem is generated in Code: [Select] <?php if(isset($_GET['album'])) { //load the available dirs into an array so that the sneeky users cannot get further back. $files = scandir($gal); $dirs = array(); foreach($files as $file){ if($file != '.' && $file != '..' && $file != 'thumbs') { if(is_dir($gal."/".$file)) { $dirs[] = $file; //echo $file ."<br />\n"; } } } //if(in_array($_GET['album'],$dirs)) { $album = "/".$_GET['album']."/"; $album = str_replace("..", "", $album); //} //else { // $output .= "<p>There is no album called \"$_GET[album]\", please select an album from below.</p>"; //} } or the breadcrumbs bit Code: [Select] <?php if($crumbs == 1) { //bread crums $path = $gal.$album; $path = explode("/", $path); $crumbs = array(); foreach($path as $key => $value) { if($value != ""){ $crumbs[] = $value; } } // create Breadcrumbs div $output .= "<div id=\"breadcrumbs\">"; $number = count($crumbs); $real = ""; foreach($crumbs as $num => $link) { if ($link == $gal) { $link = "Gallery Home"; } if ($num == $number -1) { $output .= $link; } else{ if ($num >= 1){ $real =""; for($x=1; $x<=$num; $x++) { $real .= "/".$crumbs[$x]; } $output .= "<a href=\"?album=".str_replace("/", "",$real)."\">".$link."</a>"." <- "; } else{ $output .= "<a href=\"?album=".str_replace("/", "",$real)."\">".$link."</a>"." <- "; } } $num +1; } //close breadcrumbs div $output .= "</div>"; } Can any one please help me shed some light on this one, I am confused. I can send / attach the full source if needed. MOD EDIT: tags fixed for syntax highlighting . . . Hey Im always trying to remove code and cut corners to reduce work in the long run, soIim wondering how I could link my menu bar from say a template to ALL my php pages for my site so I don't have to write/change links on every page when I need to. Thanks Hi is it possible to update multiple records of the same table using a single hidden field with a while loop??? For example: Code: [Select] <?php if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE ships SET HealthA=%s WHERE ShipID=%s", GetSQLValueString($_POST['healtha'], "int"), GetSQLValueString($_POST['shipid'], "text")); ?> <input name="healtha" type="hidden" id="healtha" value="<?php echo $row_Ships['HealthA'] + 1; ?>" /> <input name="shipid" type="hidden" id="shipid" value="<?php while($row = mysql_fetch_assoc($Ships)){ echo $row_Ships['ShipID']; }?>" /> If its not possible what else could i do to achieve this please? Thank you I have stored supplier information in a table and same form user will select multiple products for that supplier and that will be stored in a seperate table against that supplier id. Now when i would like to display all supplier information with muliple products in a single line. Now all the information will be displayed as many time as the products are. How to display all the products in a same line.
Now my display is like this
if(isset($_POST['submit']) && ($_POST['vendor']!='') && ($_POST['item']!='')) { $sql="SELECT supplier.id AS sid, supplier.name AS SNAME, supplier.category, supplier.website, supplier.email, supplier.phone, supplier.vat, supplier.pan, supplier_location.id, supplier_location.supplier_id, supplier_location.location, supplier_products.id, supplier_products.supplier_id, supplier_products.product_id, location.loc_id, location.name AS locname, products.product_id, products.name AS pname FROM supplier INNER JOIN supplier_location ON supplier.id = supplier_location.supplier_id INNER JOIN supplier_products ON supplier.id=supplier_products.supplier_id INNER JOIN location ON supplier_location.location = location.loc_id INNER JOIN products ON supplier_products.product_id=products.product_id WHERE supplier.id=".$sup." AND supplier_products.product_id=".$product; $sql1 = mysql_query($sql) or die(mysql_error()); <table> <thead><tr> <th>Vendor ID</th> <th>Vendor</th> <th>Category</th> <th>Website</th> <th>Email</th> <th>Phone</th> <th>Products</th> <th>Locations</th> <th>VAT</th> <th>PAN</th> </tr> </thead> <tbody> <tr> <?php while($row = mysql_fetch_array($sql1)) { ?> <td><?php echo $row['sid'] ?></td> <td><?php echo $row['SNAME'] ?></td> <td><?php echo $row['category'] ?></td> <td><?php echo $row['website'] ?></td> <td><?php echo $row['email'] ?></td> <td><?php echo $row['phone'] ?></td> <td><?php echo $row['iname']; ?></td> <td><?php echo $row['locname']; ?></td> <td><?php echo $row['vat'] ?></td> <td><?php echo $row['pan'] ?></td> </tr> <?php } ?> </tbody></table> }
Hi, I have a table of content in my page. For each row it has a check box. How do i achieve the function of when i click on submit button, those rows which are checked will be downloaded as a single pdf file. For example, for each checked row is a PDF file here. Suppose if i checked for 5 rows , 5 PDFs will be downloaded. Hello, Please excuse me if this sounds like a bit of a newb question. If I have a link to a users profile and use GET to pull information about that user from various tables using something like this: Code: [Select] <?php { $id = $_GET['id']; $user = mysql_query("SELECT * FROM users,tbl1,tbl2,tbl3,tbl4,tbl5 WHERE $id=tbl1.user_id AND tbl1.user_id=tbl2.user_id AND tbl2.user_id=tbl3.user_id ANDtbl3.user_id=tbl4.user_id AND tbl4.user_id=tbl5.user_id"); $user=mysql_fetch_assoc($user); } ?> <h3>Table 1</H3> <?php echo "<b>".$user['tbl1_title']."<br>"; ?><br /> <h3>Table 2</H3> <?php echo "<b>".$user['tbl2_title']."<br>"; ?><br /> <h3>Table 3</H3> <?php echo "<b>".$user['tbl3_title']."<br>"; ?><br /> <h3>Table 4</H3> <?php echo "<b>".$user['tbl4_title']."<br>"; ?><br /> <h3>Table 5</H3> <?php echo "<b>".$user['tbl5_title']."<br>"; ?><br /> Why does it only show the 1st record for that user from each table? And mostly, how do I change it to show all or a certain number of records from each table? Any help would be greatly appreciated. Thanks in advance I know it needs a for loop, but i don't know where in the code i should be putting it? Code: [Select] function check_input($value) { // Stripslashes if (get_magic_quotes_gpc()) { $value = stripslashes($value); } // Quote if not a number if (!is_numeric($value)) { $value = "'" . mysql_real_escape_string($value) . "'"; } return $value; } $_POST = array_map('check_input', $_POST); $sql="INSERT INTO testimonials (CustomerName, Town, Testimonial, SortOrder, Images) VALUES ({$_POST['customername']}, {$_POST['town']}, {$_POST['testimonial']}, {$_POST['sort_order']}, '$imgname' )"; } if (!mysql_query($sql,$con)) { die("<br>Query: $sql<br>Error: " . mysql_error() . '<br>'); } echo "<p align=center><b>1 testimonial added</b></p>"; mysql_close($con); Thanks in Advance, Steve Hi All
I have not really played around with PHP in ages so I am having a hard time trying to figure out the best way to proceed. Anyhow... what I need to get done is to take a singleton pattern core database class that has a extended driver based class (ie; the type of database server the connection is connecting to), and build a new class that dynamically handles as many driver based connections that are called using a single instance. As a side note, I tried PDO but it only supports a single driver per class instance, and then each of those connections cannot not have their on set of properties that relate to each connection. Anyway, I was thinking that the best way to handle all the driver specific connections, is to hand out a 'unique hash reference' that points to an array of connection objects and the object properties. then when the client runs any sql function they pass the 'unique hash reference' which the class then returns the object and it properties that will be used by the class to call up the driver specific sql function that was requested by the client. So what do you all thing about that....
TIA stephanieT
PS...
I reason i need this is because I need to update up 25 different databases based on data stored on all the databases and not all of the database servers are of the same type, (ie; MSSQL, Oracle, MySQL, MariaDB, berkeley DB, postgres, sqlite2,3, etc, etc)! Edited January 16, 2019 by StephanieT |