PHP - Post Radio As An Array
I have worked on a while loop as a radio and this dispalys well and Now I am trying to post this to the next page. But kind of stuck. This is my while loop for the form
Code: [Select] $intNum = 1; $intnumber = 1; while( $info = mysql_fetch_array( $sqll )){ echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> "; echo " $intNum, {$info['Que_Question']} <br />\n"; $intNum++; for ($i =1; $i < 5; $i++) { echo "<input type=\"Radio\" name=\"choice[{$intnumber}]\" />{$info['Que_Choice'.$i]}<br />\n"; $intnumber++; } } ?> <input type="submit" name="submit" value="submit"/> </form> </body> </html> Now in order for me to post this to the next page, can I do something like Code: [Select] if (isset($_POST['Submit1'])) { $qu=$_POST[Que_ID]; $choi=$_POST[choice]; for($i=1; $1=5; i++) echo $qu. $choi; this is just my guess. I want the que_ID to display four choice for each question ID. so it would be Question ID=2(choice1=selected, choice2=notselected, choice3=not selected, chocie4=not selected) and this would be repeated to the next question ID. So far I can notice that my chociename are added by one(choice1, choice2,choice3,choice4,choice5,choice6,choice7,choice8,choice8......) so my post for loop will not work work as my choices goes up to more then 5. Similar TutorialsHi all, I have a page with 4 textboxes which can be filled out. The thing is I want people to be able to only train 1 type at a time. Underneath I posted the Form page and the exec page does anyone have and idea?? Thnx Ryflex FORM: <?php //authentication & database configuration require_once('auth.php'); require_once('config.php'); //member_ID and city_ID and greyed out empty declaration $member_ID = $_SESSION['SESS_MEMBER_ID']; $city_ID = $_SESSION['SESS_CITY_ID']; $ro = ""; //Database connection $global_dbh = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die("Could not connect to database"); mysql_select_db(DB_DATABASE, $global_dbh) or die("Could not select database"); //get infantry units type = 1 $sql = "SELECT name, resource_1, resource_2, resource_3, timestamp FROM unittype WHERE type = 1"; $result = mysql_query($sql) or die("Could not find units"); //get the 4 unit types in the $n[] array while($data = mysql_fetch_assoc($result)) { $one[] = $data[resource_1]; $two[] = $data[resource_2]; $three[] = $data[resource_3]; $time[] = $data[timestamp]; } //query amount of infantry troops $sql = "SELECT * FROM infantry WHERE member_id = '$member_ID'"; $result = mysql_query($sql) or die("Could not find amount of troops"); //get amount of infantry troops while($data = mysql_fetch_assoc($result)) { $n[] = $data[name]; $training[] = $data[training]; $timestamp[] = $data[timestamp]; $amount[] = $data[amount]; } //check if a training is underway $sql = "SELECT * FROM infantry WHERE member_id = '$member_ID' AND training = 1"; $trcurr = mysql_fetch_array( mysql_query($sql)); if($trcurr['training'] == 1) { $ro = "READONLY STYLE='color:#999999;background:#DEDEDE'"; } ?> <html> <head> <title>Infantry Training</title> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> </head> <body> <p>You can only train 1 type of infantry at a time.</p> <form id="create" name="create" method="POST" action="infantry_exec.php"> <table> <tr> <td><b><?php echo $n[0]; ?></b></td> <td><b><input name="<?php echo $n[0]; ?>" type="text" <?php echo $ro; ?> maxlength="10" id="<?php echo $n[0]; ?>" /></b></td> </tr> <tr> <td><b><?php echo $n[1]; ?></b></td> <td><b><input name="<?php echo $n[1]; ?>" type="text" <?php echo $ro; ?> maxlength="10" id="<?php echo $n[1]; ?>" /></b></td> </tr> <tr> <td><b><?php echo $n[2]; ?></b></td> <td><b><input name="<?php echo $n[2]; ?>" type="text" <?php echo $ro; ?> maxlength="10" id="<?php echo $n[2]; ?>" /></b></td> </tr> <tr> <td><b><?php echo $n[3]; ?></b></td> <td><b><input name="<?php echo $n[3]; ?>" type="text" <?php echo $ro; ?> maxlength="10" id="<?php echo $n[3]; ?>" /></b></td> </tr> <tr> <td colspan="2"><center><input type="submit" name="Submit" value="Train!!!" /></center></td> </tr> </table> </form> </body> </html> EXEC: <?php //authentication & database configuration require_once('auth.php'); require_once('config.php'); //member_ID and city_ID $member_ID = $_SESSION['SESS_MEMBER_ID']; $city_ID = $_SESSION['SESS_CITY_ID']; //Database connection $global_dbh = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die("Could not connect to database"); mysql_select_db(DB_DATABASE, $global_dbh) or die("Could not select database"); //query names of infantry troops $sql = "SELECT * FROM infantry WHERE member_id = '$member_ID'"; $result = mysql_query($sql) or die("Could not find amount of troops"); //get names of infantry troops while($data = mysql_fetch_assoc($result)) { $n[] = $data[name]; } //convert POST to normal variable $amount = array(0 => $_POST[$n[0]], 1 => $_POST[$n[1]], 2 => $_POST[$n[2]], 3 => $_POST[$n[3]]); ?> $post='{"cart_items":[{"configuration":{"price":100,"recharge_number":"9999999999"},"product_id":"999","qty":1}]}';i try this n reslut was :There are no valid items in cart: help me plz Edited by ShivaGupta, 30 November 2014 - 01:11 AM. Why wont my radio array show the value that was selected. If a user select a radio then the value should be printed. But it should print the question id then the choice that was chosen for that question id. Code: [Select] <?php $gender = $_POST["choice"]; $que_ID = $_POST["Que_ID"]; foreach ($gender as $key => $value) { echo $key." - ".$value."";} ?> Code: [Select] $intNum = 1; $intnumber = 1; while( $info = mysql_fetch_array( $sqll )){ echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> "; echo " $intNum, {$info['Que_Question']} <br />\n"; $intNum++; for ($i =1; $i < 5; $i++) { echo "<input type=\"Radio\" name=\"choice[{$info['Que_ID']}][]\" />{$info['Que_Choice'.$i]}<br />\n"; $intnumber++; Hi, I have 2 radio button's within a table and need to pass this array. All other rows within my table can be sent as array's and captured using $_POST['field_name'][$ROW 1 value etc]. However for radio buttons this doesn't work. As an example, a standard textbox I can send an array using the following: echo "<td width='33%'><input type='Textbox' width='100%' id='test' name='test[]' value='" .$row['test']. "'></td>"; I can then capture it using: $test = $_POST['test'][$iLine]; This works, no problem, however for radio buttons, I can't use a static array name, as presumably it dumps all rows into the array, if I do this, only the last row has a checked button, hence I need to use the following (where $checked includes the logic to decide whether the button should be checked or not, this works correctly): echo "<input type='radio' name='".$row['venue_id']."[]' value='1'".$checked."/>P1" echo "<input type='radio' name='".$row['venue_id']."[]' value='0'".$checked2." />P2"; I tried using the following: var_dump($_POST[$row]['game_id'][$iLine]); But this just returns a null value. Any ideas? Well this is my first time using icecast and I am a little lost. I have these two (three in a way) files that are all linked in a way. index.php > cast_info.php > status.xsl so here are the files: index.php Code: [Select] <?php require_once("cast_info.php"); ?> <table> <tr> <th colspan="2">Stats For Icecast Server: <?php echo $radio_info['title']; ?></th> </tr> <?php foreach($radio_info as $title => $data) { switch($title) { case 'now_playing' : ?><tr> <td><b><?php echo $title; ?></b></td> <td><?php echo $data['artist']; ?><br /> <?php echo $data['track']; ?> </td> </tr><?php break; case 'title' : //skip break; default : ?><tr> <td><?php echo $title; ?></td> <td><?php echo $data; ?></td> </tr><?php break; } } ?> </table> cast_info.php Code: [Select] <?php /* * Script Configurations */ $SERVER = 'http://grimradio.com:8000'; //$SERVER = 'http://localhost:8000'; //enter the URL to your Icecast server $STATS_FILE = '/status.xsl'; //enter the path to your status.xsl file (leave blank unless u know its different) //////////////////////////////////// END OF CONFIGURATION ----- DO NOT EDIT BELOW THIS LINE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //get statistics file contents $fp = fopen($SERVER.$STATS_FILE,'r'); if(!$fp) { //error connecting to server! die("Unable to connect to Icecast server."); } $stats_file_contents = ''; while(!feof($fp)) { $stats_file_contents .= fread($fp,1024); } fclose($fp); //create array to store results for later usage $radio_info = array(); $radio_info['server'] = $SERVER; $radio_info['title'] = ''; $radio_info['description'] = ''; $radio_info['content_type'] = ''; $radio_info['mount_start'] = ''; $radio_info['bit_rate'] = ''; $radio_info['listeners'] = ''; $radio_info['most_listeners'] = ''; $radio_info['genre'] = ''; $radio_info['url'] = ''; $radio_info['now_playing'] = array(); $radio_info['now_playing']['artist'] = ''; $radio_info['now_playing']['track'] = ''; $temp = array(); //format results into array $search_for = "<td\s[^>]*class=\"streamdata\">(.*)<\/td>"; $search_td = array('<td class="streamdata">','</td>'); if(preg_match_all("/$search_for/siU",$stats_file_contents,$matches)) { foreach($matches[0] as $match) { $to_push = str_replace($search_td,'',$match); $to_push = trim($to_push); array_push($temp,$to_push); } } //build final array from temp array $radio_info['title'] = $temp[0]; $radio_info['description'] = $temp[1]; $radio_info['content_type'] = $temp[2]; $radio_info['mount_start'] = $temp[3]; $radio_info['bit_rate'] = $temp[4]; $radio_info['listeners'] = $temp[5]; $radio_info['most_listeners'] = $temp[6]; $radio_info['genre'] = $temp[7]; $radio_info['url'] = $temp[8]; //format now playing $now_playing = explode(" - ",$temp[9]); $radio_info['now_playing']['artist'] = $now_playing[0]; $radio_info['now_playing']['track'] = $now_playing[1]; ?> status.xsl Code: [Select] <xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" > <xsl:output omit-xml-declaration="no" method="html" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" indent="yes" encoding="UTF-8" /> <xsl:template match = "/icestats" > <html> <head> <title>Icecast Streaming Media Server</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0"> <h2>Icecast2 Status</h2> <br /> <!--index header menu --> <div class="roundcont"> <div class="roundtop"> <img src="/corner_topleft.jpg" class="corner" style="display: none" /> </div> <table border="0" width="100%" id="table1" cellspacing="0" cellpadding="4"> <tr> <td bgcolor="#656565"> <a class="nav" href="admin/">Administration</a> <a class="nav" href="status.xsl">Server Status</a> <a class="nav" href="server_version.xsl">Version</a></td> </tr> </table> <div class="roundbottom"> <img src="/corner_bottomleft.jpg" class="corner" style="display: none" /> </div> </div> <br /> <br /> <!--end index header menu --> <!--mount point stats--> <xsl:for-each select="source"> <xsl:choose> <xsl:when test="listeners"> <div class="roundcont"> <div class="roundtop"> <img src="/corner_topleft.jpg" class="corner" style="display: none" /> </div> <div class="newscontent"> <div class="streamheader"> <table cellspacing="0" cellpadding="0"> <colgroup align="left" /> <colgroup align="right" width="300" /> <tr> <td><h3>Mount Point <xsl:value-of select="@mount" /></h3></td> <xsl:choose> <xsl:when test="authenticator"> <td align="right"><a class="auth" href="/auth.xsl">Login</a></td> </xsl:when> <xsl:otherwise> <td align="right"> <a href="{@mount}.m3u">M3U</a> <a href="{@mount}.xspf">XSPF</a></td> </xsl:otherwise> </xsl:choose> </tr></table> </div> <table border="0" cellpadding="4"> <xsl:if test="server_name"> <tr><td>Stream Title:</td><td class="streamdata"> <xsl:value-of select="server_name" /></td></tr> </xsl:if> <xsl:if test="server_description"> <tr><td>Stream Description:</td><td class="streamdata"> <xsl:value-of select="server_description" /></td></tr> </xsl:if> <xsl:if test="server_type"> <tr><td>Content Type:</td><td class="streamdata"><xsl:value-of select="server_type" /></td></tr> </xsl:if> <xsl:if test="stream_start"> <tr><td>Mount started:</td><td class="streamdata"><xsl:value-of select="stream_start" /></td></tr> </xsl:if> <xsl:if test="bitrate"> <tr><td>Bitrate:</td><td class="streamdata"> <xsl:value-of select="bitrate" /></td></tr> </xsl:if> <xsl:if test="quality"> <tr><td>Quality:</td><td class="streamdata"> <xsl:value-of select="quality" /></td></tr> </xsl:if> <xsl:if test="video_quality"> <tr><td>Video Quality:</td><td class="streamdata"> <xsl:value-of select="video_quality" /></td></tr> </xsl:if> <xsl:if test="frame_size"> <tr><td>Framesize:</td><td class="streamdata"> <xsl:value-of select="frame_size" /></td></tr> </xsl:if> <xsl:if test="frame_rate"> <tr><td>Framerate:</td><td class="streamdata"> <xsl:value-of select="frame_rate" /></td></tr> </xsl:if> <xsl:if test="listeners"> <tr><td>Current Listeners:</td><td class="streamdata"> <xsl:value-of select="listeners" /></td></tr> </xsl:if> <xsl:if test="listener_peak"> <tr><td>Peak Listeners:</td><td class="streamdata"> <xsl:value-of select="listener_peak" /></td></tr> </xsl:if> <xsl:if test="genre"> <tr><td>Stream Gen </td><td class="streamdata"> <xsl:value-of select="genre" /></td></tr> </xsl:if> <xsl:if test="server_url"> <tr><td>Stream URL:</td><td class="streamdata"> <a target="_blank" href="{server_url}"><xsl:value-of select="server_url" /></a></td></tr> </xsl:if> <tr><td>Current Song:</td><td class="streamdata"> <xsl:if test="artist"><xsl:value-of select="artist" /> - </xsl:if><xsl:value-of select="title" /></td></tr> </table> </div> <div class="roundbottom"> <img src="/corner_bottomleft.jpg" class="corner" style="display: none" /> </div> </div> <br /> <br /> </xsl:when> <xsl:otherwise> <h3><xsl:value-of select="@mount" /> - Not Connected</h3> </xsl:otherwise> </xsl:choose> </xsl:for-each> <xsl:text disable-output-escaping="yes">&</xsl:text>nbsp; <div class="poster">Support icecast development at <a class="nav" target="_blank" href="http://www.icecast.org">www.icecast.org</a></div> </body> </html> </xsl:template> </xsl:stylesheet> now what the problem is, is that it won't display the "now playing" info. not sure exactly where the error might be, but I am sure it has to do with that array. you can view what does display here http://grimradio.com/ I seem to be having a problem with this code. It's supposed to parse the file info.txt and explode comma separated values into an array and then add each value from that file to the end of a URL and POST that url. What I'm getting now is just the first number in the array. Anyway, here's the code: Code: [Select] <?php $FileName = "info.txt"; $FileHandle = fopen($FileName,"r"); $FileContent = fread ($FileHandle,filesize ($FileName)); fclose($FileHandle); // You can replace the \t with whichever delimiting character you are using $SplitContent = explode("\t", $FileContent); foreach($SplitContent as $CurrValue) { header('Location: http://website.com/file.php?value=' . $CurrValue); } ?> I have a dynamic form that I am writing a script for to allow people to modify the fields of the form. I am taking all of the information that they have entered into the post array. Where I am having a problem is that it is not showing all of the fields in the post array. One of the fields is an image field and the name of the image does not show up in the array when I do print_r or anything. One other thing that I would like to know is how to get rid of the submit key and value from the array. I have tried using the unset method but it still shows up in the array. Code: [Select] <?php session_start(); include ('includes/connection.php'); connect(); $table = $_GET['table']; $id = $_GET['id']; $errors = array(); $mod_sql = "SELECT * FROM $table WHERE id = '$id'"; $mod_sql_result = mysql_query($mod_sql); $info = mysql_fetch_assoc($mod_sql_result); $mod_form = "<form name='insert_table' id='insert_table' action='" . $_SERVER['PHP_SELF'] . "?id=$id&table=$table' method='post' enctype='multipart/form-data'> <fieldset> <legend>table information</legend> <input TYPE='hidden' VALUE='" . $table . "' />"; foreach ($info as $key => $val) { $header = str_replace("_", " ", $key); if ($key == 'id') { $mod_form .= "<p>" . $header . ": <input name='" . $key . "' id='" . $key . "' type='text' value='" . $val . "' readonly='readonly' /></p>"; } else if ($key == 'image') { $mod_form .= "<p>Current image: <img style='vertical-align: text-top;' src='../db_images/ad_images/" . $val . "' /><input type='checkbox' name='delete_image' id='delete_image' value='" . $val . "' />Delete this image?</p> <p>" . $header . ": <input name='" . $key . "' id='" . $key . "' type='file' /></p>"; } else { $mod_form .= "<p>" . $header . ": <input name='" . $key . "' id='" . $key . "' type='text' value='" . $val . "' /></p>"; } } $mod_form .= " <p> <input type='submit' name='submit_mod' id='submit_mod' /> </p> </fieldset> </form> "; echo $mod_form; if (isset($_POST['submit_mod'])) { $table = $_POST['table']; $allowed_ext = array('jpg', 'jpeg', 'png', 'gif'); $file_name = $_FILES['image']['name']; $file_ext = (explode(".", $file_name)); $file_ext = strtolower(end($file_ext)); $file_size = $_FILES['image']['size']; $file_tmp = $_FILES['image']['tmp_name']; if (isset($_POST['delete_image'])) { $delete_image_name = $_POST['delete_image']; unlink('../db_images/ad_images/' . $delete_image_name); } if ($file_name != " ") { $new_image = $file_name; move_uploaded_file($file_tmp, '../db_images/ad_images/' . $file_name); } // This is the section of code that I am having trouble with foreach ($_POST as $key => $value) { if ($key == 'image') { $value = $new_image; } $insert_query = "UPDATE $table SET `$key` = '$value' WHERE id = $id"; $insert_action = mysql_query($insert_query); } echo $insert_query; } if (mysql_error()) { $error = "<strong>MySQL error</strong>:<br />" . mysql_errno() . ": " . mysql_error() . "\n<br>When executing:<br>\n$insert_query\n<br>"; $page = $_SERVER["REQUEST_URI"]; $log = "INSERT INTO db_error (`error_id`, `error_page`,`error_text`,`query`) VALUES ('','$page','" . mysql_real_escape_string($error) . "','" . mysql_real_escape_string($mod_sql) . "')"; $insert_log = mysql_query($log); echo $error; if ($insert_log) { echo "<p>Error has been added to the error log</p><p>The error id number is " . mysql_insert_id() . ""; } else { echo "Error adding to error log<br />" . mysql_errno() . ": " . mysql_error(); } } ?> Hi all, Can anyone tell me why the declaration below won't work??? Thnx Ryflex $amount = array(0 => $_POST['$n[0]'], 1 => $_POST['$n[1]'], 2 => $_POST['$n[2]'], 3 => $_POST['$n[3]']); All of my form POST data (from multiple forms) is managed through a file called formdata.php. Formdata.php and check_input() performs trim/stripslashes/htmlspecialchars etc on the posted variables. (it also indirectly calls relevant database functions such as insert or select). What is the correct way to add all of the variables to an array so that I can so that I can pass the array(ofvariables) to a function. ie the checked variables (only a few of them): Code: [Select] $subject = check_input($_POST['subject']); $repphone = check_input($_POST['repphone']); $repfirstname = check_input($_POST['repfirstname']); $replastname = check_input($_POST['replastname']); $streetnum = check_input($_POST['streetnum']); $streetname = check_input($_POST['streetname']); $suburb = check_input($_POST['suburb']); $postcode = check_input($_POST['postcode']); there will be many subjects and many more variables so instead of listing the variables such as: Code: [Select] function post_to_table(){ // variables global $subject;, $streetnum, $streetname, $suburb, $postcode; global $repphone, $repfirstname, $replastname; if ($subject === "specifiedsubject"){ post_to_appropriate_table($streetnum, $streetname, $suburb, $postcode, $repphone, $repfirstname, $replastname); } I would rather use an array instead of passing each variable individually: Code: [Select] function post_to_appropriate_table ($streetnum, $streetname, $suburb, $postcode $repphone, $repfirstname, $replastname) { global $database; $sql = "INSERT INTO incident ("; $sql .= "streetnum, "; $sql .= "streetname, "; $sql .= "suburb, "; $sql .= "postcode, "; $sql .= "repphone, "; $sql .= "repfirstname, "; $sql .= "replastname"; $sql .= ") "; $sql .= "VALUES ("; $sql .= "'{$streetnum}', "; $sql .= "'{$streetname}', "; $sql .= "'{$suburb}', "; $sql .= "'{$postcode}', "; $sql .= "'{$repfirstname}', "; $sql .= "'{$replastname}'"; $sql .= ") "; // echo $sql; //for debugging if required; return $database->query($sql); } how can I ditch the ever growing list of variables and use an array? Thanks. $space = array('3x3', '3x3_6x6', '3x3_6x6', '6x6_10x10', '10x10_20x20', '20x20_40x40', 'above_40x40'); Hi all This is probably the easiest question ever , but I am not familiar with arrays , so hope somebody can help me User post this checkbox form (array): <input type="checkbox" name="type[0][]" value="1" > <input type="checkbox" name="type[0][]" value="2" > <input type="checkbox" name="type[0][]" value="3" > I need to get all checked values and print them ... How can I do this? I tried the code below, but it only returns me one value Code: [Select] $values = array($_POST["type"]); foreach ($values as $item){ echo $item; } Any help??? Thanks!! I have a form that is producing the following : Array ( [formID] => 3154008308 [q1_applicationDate] => Array ( [month] => 11 [day] => 15 [year] => 2010 ) [q4_fullName4] => Array ( [first] => TOM [last] => STONE ) [q5_email] => TSTONE@YAHOO.COM [q6_address6] => Array ( [addr_line1] => 325 E LINCOLN [addr_line2] => [city] => GENESEE [state] => NY [postal] => 33256 [country] => United States ) [q38_selectProvider38] => Sprint [q39_selectPlan] => Individual [website] => [simple_spc] => 3154008308-3154008308 ) HOW do I automatically get each item above into it's own PHP variable? The page that receives this Array is the second page of a 3 or 4 page form. I need to send the above information on through the remainder of the form?? Would appreciate any help! Thanks! Hello! i have a shopping cart set up with mysql with a $_COOKIE['cart_id'] used to call all rows with cart_id... i have a while loop print out all the items in the cart $sql2 = mysql_query("SELECT * FROM cart WHERE cart_id = '$cart_id'") or die(mysql_error()); while($row = mysql_fetch_array($sql2)){ then i have it echo out the name...desc... quantity of each item... but the quantity is set up to be able to change and i have a form set up and i'd like to have each item be able to be changed at once if they wanted....but being multiple rows... there could be multiple $_POST['quantity']... echo "<td><input type='text' name='quantity' value='".$quantity."'/></td>"; there is a unique id for each row in the table that i'd like to set up with an array to post... i'd like to set up an array $array[$uniq_id] => $quantity; and somehow POST this array name='$array[]' and then on the action end... be able to call it by having foreach($quantity as $uniq_id => $qty){ mysql_query("UPDATE cart SET quantity='$qty' WHERE id='$uniq_id' "); } i'm not sure if i'm approaching this the right way... the array part is leaving me stuck...any help is appreciated..thank you! Hi - I have an HTML form which is dynamically produced using CodeIgniter / PHP and presents products a customer has ordered. When the customer has finished changing his quantities they must now submit the form. My problem is that my form will contain many of the same named fields for example, 'Product ID', or 'Product Name' or 'quantity'. So now when it gets processed a typical post array like product id could look like this: Code: [Select] Array ( [0] => 28 [1] => 24 [2] => 101 [3] => 23 [4] => 17 ) Of course I get an error: Quote Severity: Notice Message: Array to string conversion Filename: mysql/mysql_driver.php I really need some advice on how I should pre-process the various POST arrays so I can get them into my DB. A very grateful student of PHP ! Thanks Hi - I am uploading Post variables off a form relating to products and customer orders. If a product has a quantity attached to it then all the POST variables relating to that product need to INSERTED into the DB. If a product has just an empty string in it's quantity variable, then that product does not get INSERTED. So I thought of 2 different approaches: A) I could filter the Quantity Post variable for a positive values then create a new array only containing products with positive quantities. B) I could loop through the product Id (ProdID) POST and using a condition pull out the products with a positive quantity for Insertion. I have been experimenting with B and have failed miserably. However I have succeeded excellently in building some code which INSERTS all the products regardless of their quantities ( see below ) - not ideal as it enters products with empty quantities. I would prefer to adapt what I have rather than throw it away. Can someone kind person give this student a hand with some advice in adapting what I have got ? MANY MANY THANKS ! Code: [Select] <?php function insert_tel_order(){ $lastname = $_POST['lastname']; $orderid = strtoupper(substr($lastname,0,3)).(substr(time(),-4)); //Creates a unique order number $customerid = $_POST['customerid']; $pickupdate = $_POST['pickupdate']; $deliverylocationid = $_POST['deliverylocationid']; $orderdate = $_POST['orderdate']; foreach ($_POST['prodid'] as $arrkey => $prodid){ $quantity = $_POST['quantity'][$arrkey]; $prodid = $_POST['prodid'][$arrkey]; $price = $_POST['price'][$arrkey]; $ordervalue = $quantity * $price; $sql =" INSERT INTO `order` (id, orderid,orderdate,customerid, deliverylocationid,pickupdate,prodid,price, quantity, ordervalue, status) VALUES ('', '$orderid',$orderdate,$customerid,$deliverylocationid,$pickupdate,$prodid,$price,$quantity,$ordervalue,'')"; $this->db->query($sql); } } ?> Hey guys i am currently building a very complex form for one of my clients. The for has ALOT of imputs and can also generate new one automaticly using javascript. My problem is that come of them returns empty arrays while other works. Is there a maximum or some kind that a form can submit at the time? i made a print_r on the $_POST var and this is what i got (I tooke out all the other arrays but theres a lot more then what i am posting) [...] print ('<tr> <td> <input type="text" size="9" name="styleenc[]" value=""> </td> <td> <input type="text" size="9" name="couleurenc[]" value=""> </td> <td> <input type="text" size="2" name="c_y[]" value=""> </td> <td> <input type="text" size="2" name="c_a_s[]" value=""> </td> <td> <input type="text" size="2" name="c_a_l[]" value=""> </td> <td> <input type="text" size="2" name="c_a_o_s[]" value=""> </td> <td> <input type="text" size="9" name="descenc[]" value=""> <input type="hidden" size="9" name="invisible3[]" value="3"> </td> </tr>'); [...] Code: [Select] Array ( [styleenc] => Array ( [0] => [1] => [2] => [3] => [4] => ) [couleurenc] => Array ( [0] => [1] => [2] => [3] => [4] => ) [c_y] => Array ( [0] => [1] => [2] => [3] => [4] => ) [c_a_s] => Array ( [0] => [1] => [2] => [3] => [4] => ) [c_a_l] => Array ( [0] => [1] => [2] => [3] => [4] => ) [c_a_o_s] => Array ( [0] => [1] => [2] => [3] => [4] => ) [descenc] => Array ( [0] => [1] => [2] => [3] => [4] => ) [invisible3] => Array ( [0] => 3 [1] => 3 [2] => 3 [3] => 3 [4] => 3 ) [emplacement] => sdcwedf ) They should all have values i don't get it ... the only one that has values is invisible3 that has been manualy specified with value="3" Hello to everyone,
I have a strange problem and I'm not able to solve it by myself and I need your help!
I have three simple checkboxes that process via POST their value. But with PHP I cannot have an array with the three indexes (if everyone checked) but only an array with the first checkbox checked. The code is very simple:
<?php $scelta = isset($_POST['user_rights']) ? $_POST['user_rights'] : array(); if (isset($_POST["user_rights"])){ print_r($scelta);}else{ ?> <form method="post"><input type="checkbox" name="user_rights[]" value="0"> 0<br><input type="checkbox" name="user_rights[]" value="1"> 1<br><input type="checkbox" name="user_rights[]" value="2"> 2 <input type="submit"></form> <?php} ?>The output if I check all the checkboxes is: Array ( [0] => 0 ) If I try this code on another server it works (it returns the complete array), but if i run it on my web server, it doesn't (it returns only the first item). Do you have any experience with this error? Do you know if there is some configuration to change? Thanks in advance. Rob I have a form which has a variable size, depending on the number of rows in a table. For each row there are about ten fields, and I simply show them all for each row. I've recently started having a trouble in that if I create a form with more than 400 elements, then the $_POST variable is truncated at 400. Is this normal? Do I have to limit the size of the $_POST array? Not by MB, which must be trivial for me, but for the number of array elements? I have a form with lots of fields. How would I run a loop to get each field name and data into an array, so i can then send it off to a function to process each field name / data differently. Instead of typing all the variables in the main function name for each post. Would a foreach statement work? |