PHP - Multiple Array Problems Passing
Similar TutorialsPlease forgive my limited knowledge of php. I am trying to pass a variable from 1 page to the next. I have SCRIPT A (I didn't write it) that parses an rss feed and then calls SCRIPT B to insert it into a database. Everything works great.. and all I'm trying to do is add a new piece of information. In my db, I added a column called 'city'. There are currently 25 different SCRIPT A's (25 different city names). I could create 25 SCRIPT Bs and call them individually, but I'm trying to use 1 SCRIPT B and just send the city name. I've read about POST and GET but still not sure on this? Can't I just hard code my city name into each SCRIPT A like this: Code: [Select] $city = "miami"; And then put this at the top of SCRIPT B? Code: [Select] $city = $_GET['city']; Well.. apparently, I can't because that doesn't work. Again.. sorry for the dumb question. It's my first time attempting anything with php. Thanks. hello this is my first time posting so i'm sorry if i word this wrong or it is a stupid question. i have a simple database made up with a product table with five fields; id, url, name, description, and price. also a categories table with five fields; id, parent_id, siteurl, name, and description. i have everything up and running,but i can't figure out how to pass the product id as a parameter. right now i have "example.php" but i need "example.php?id=1" here is what my code looks like indextest.php Code: [Select] <?php error_reporting(0); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Car Dealer</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <?php $usr = "root"; $pwd = ""; $db = "mymarket"; $host = "localhost"; //connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } $category = ""; // setup SQL statement $SQL = " SELECT * FROM categories "; $SQL = $SQL . " WHERE parent_id = '0' "; // execute SQL statement $retid = mysql_db_query($db, $SQL, $cid); // check for errors if (!$retid) { echo( mysql_error()); } else { ?> <div id="layout"> <div id="titlebg"> <div class="title">CAR</div> <div class="title1">DEALER</div> <div class="title2">WE HAVE</div> <div class="title3">THE BEST CARS</div> <div class="title4" align="center"> Links: <a target="_blank" href="http://jigsaw.w3.org/css-validator/" class="title4">CSS VALIDATOR</a></div> </div> <hr id="hrline" /> <div id="gradientbg"> <div id="links"> <h2> <?php // display results echo ("<p><dt><b>$category</b><br>\n"); while ($row = mysql_fetch_array($retid)) { $siteurl = $row["siteurl"]; $name = $row["name"]; echo ("<dd><a href='$siteurl'>$name</a></dd>\n<br>"); } echo ("</dt></p>"); } ?> <h2/> </div> <div id="header"></div> </div> <div id="bodypart"> <div id="catalogue"> <div class="cat">CATALOGUE</div> <div id="cat1"></div> <div id="car1"></div> <div id="cat2"></div> <div id="car2"></div> </div> <div id="line"></div> <div id="ourservices"> <div class="our">OUR SERVICES</div> <div id="pic1"></div> <div class="lorem">Lorem ipsum</div> <div class="txt">At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam Consetetur sadi pscing </div> </div> <div id="line1"></div> <div id="aboutus"> <div class="abt">ABOUT US</div> <div id="pic2"></div> <div class="lorem1">Lorem ipsum</div> <div class="txt1">At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam Consetetur sadi pscing </div> </div> </div> <hr id="hrline1" /> <div class="foottxt">Copyright © Cars. Design by <a href="http://www.dotcominfoway.com/" class="foottxt">DOT COM INFOWAY</a>.</div> </div> </body> </html> and i would like to link that to this next file att.php Code: [Select] <?php error_reporting(0); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Smartphone Dealer</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <?php $usr = "root"; $pwd = ""; $db = "mymarket"; $host = "localhost"; //connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } $category = ""; // setup SQL statement $SQL = " SELECT * FROM categories "; $SQL = $SQL . " WHERE id ='4' OR id = '5' OR id = '6' "; ?> <div id="layout"> <div id="titlebg"> <div class="title">SMARTPHONE</div><br> <div class="title1">DEALER</div> <div class="title2">WE HAVE</div> <div class="title3">NO CONTRACT SMARTPHONES</div> <div class="title4" align="center"> Links: <a target="_blank" href="http://jigsaw.w3.org/css-validator/" class="title4">CSS VALIDATOR</a></div> </div> <hr id="hrline" /> <div id="gradientbg"> <h3> <?php // execute SQL statement $retid = mysql_db_query($db, $SQL, $cid); // check for errors if (!$retid) { echo( mysql_error()); } else { // display results echo ("<p><dt><b>$category</b><br>\n"); while ($row = mysql_fetch_array($retid)) { $siteurl = $row["siteurl"]; $description = $row["description"]; echo ("<dd><a href='$siteurl'>$description</a></dd>\n<br>"); } echo ("</dt></p>"); } ?> </div> <h3> </div> <hr id="hrline1" /> <div class="foottxt">Copyright © Nathan Hein. Template by <a href="http://www.dotcominfoway.com/" class="foottxt">DOT COM INFOWAY</a>. <br> DISCLAIMER: This website was designed for a school project and is not intended for commercial use of any kind.</div> </div> </body> </html> i know i probably have a lot of problems with this code, but the one i can't figure out is passing the parameter and i have been looking at forums, websites, w3schools, everywhere. i;m just not grasping the concept of how to make it work with this. thank you so much for any input So i got the following problem: i got some pages : index.php , comment.php, viewArticle.php When i try to submit something from comment.php appear a error "Undefined variable:result" The var result is defined in index.php When i click on one article from the list the function viewArticle() is requiring viewArticle.php and the function addcomment() is requiring comment.php The addcomment function() is in viewArticle function() I can't figure out what's wrong but I guess have something to do whit the form action="index.php?action=viewArticle&articleid=<?php echo $result['article']->id?>" index.php code Code: [Select] <?php include('config.php'); $action = isset($_GET['action'])?$_GET['action']:""; switch($action) { case 'viewArticle':viewArticle();break; default:homepage(); } function homepage() { $result = array(); $data = Article::getlist(1); $result['article']=$data['result']; $result['total']=$data['totalrows']; require('homepage.php'); } function viewArticle() { if( !isset($_GET['articleid']) )homepage(); $result = array(); $result['article'] = Article::getbyid((int)$_GET['articleid']); $result['name'] = $result['article']->name; addcomment(); require('viewArticle.php'); } function addcomment() { if(isset ($_POST['submit'] )) { $comment = new Comment; $set = array(); $set['usern']="HJhj"; $set['com']="aca wqeq"; $set['page']=7; $comment->storeFormValues($set); $comment->insertc(); } else require('comment.php'); } ?> viewArticle.php code Code: [Select] <center> <h1> <?php echo $result['article']->text ?> </h1> comment.php code: Code: [Select] <form method='post' action="index.php?action=viewArticle&articleid=<?php echo $result['article']->id?>" > <input type="hidden" name="id" value="56"/> <ul> <li> <input type="text" name="usern" id="usern" /> </li> <li> <textarea name="com" id="com" COLS=40 ROWS=6></textarea> </li> <input type="hidden" name="page" value="56" /> <input type="submit" name="submit" value="submit" /> </form> Given the following array $documentlist, displayed from print_r Array ( [MerchantDocumentInfo] => Array ( => Array ( [documentID] => 2760322451 [generatedDateTime] => 2010-08-03T16:02:45-07:00 ) [1] => Array ( [documentID] => 2761837402 [generatedDateTime] => 2010-08-03T23:01:15-07:00 ) ) ) I'm trying to figure out the syntax to use the documentID as a dynamic variable When I 'hard code' the variable, I get the document I want eg $order = $t->GetDocument('2760322451'); -- returns requested document info into $order array where $order is an array and $t are my connection credentials. I've made numerous attempts, but get errors in anything I try. Can someone tell me the correct syntax to use to pass a dynamic value for documentID from the $documentlist array at the top? I've tried $order = $t->GetDocument($documentlist['MerchantDocumentInfo' ]['documentID']) ; and get ===> syntax error, unexpected '[', expecting ']' $order = $t->GetDocument($documentlist->MerchantDocumentInfo[0]['documentID']) ; get nothing $order = $t->GetDocument($documentlist->MerchantDocumentInfo[1]['documentID']) ; get nothing $order = $t->GetDocument($documentlist->MerchantDocumentInfo[1][documentID]) ; get nothing Thanks in advance for any ideas, I've been trying to figure this out for days. Hi everybody. So I tried to do some research on this and the answers I found were pretty complicated and hard for me (as a newbie) to understand. What I am trying to do is send the results of an HTML form (radio buttons) to more than one php script (currently name_BB1.php but I would also like to send it to name_2.php). Is there a simple way to do this? Is it even possible?
All I need to pass from the script is the name of the department chosen (Music Books or Video) and the first script uses that information to access related databases. However the second script also needs to know the name of the department originally chosen and I don't know how to get that variable over there without asking the user a second time.
HTML:
<form action="name_BB1.php" method="POST"> </p>Which database would you like to select?<br \><br \> <input type="radio" name="choice" value="Music" />I want music!<br \> <input type="radio" name="choice" value="Books" />Give me books!<br \> <input type="radio" name="choice" value="Video" />I want to see videos!<br \><br \> <input type="submit" value="submit"> </p> </form> Thanks! I have some function or method. Is there a better design patter to implement this?
function myFunction($a=null,$b=null,$c=null,$d=null,$e=null,$f=null,$g=null,$h=null) { //Do a bunch of stuff }Maybe the second function? function myNewFunction($data=array()) { $data=array_merge(array('a'=>null,'b'=>null,'c'=>null,'d'=>null,'e'=>null,'f'=>null,'g'=>null,'h'=>null),$array); //Do a bunch of stuff }Please provide decision making factors why you would use one approach over the other. Hi all, new to php and struggling passing an array via url. first page: Code: [Select] $str = serialize($cartinfo); $strenc = urlencode($str); <A href="/test/getcart.php?cartinfo=<?PHP echo $strenc; ?>">test</A> Which does add a long string to the URL so I guess to here it's fine. Second Page: Code: [Select] <?PHP $cartinfo = unserialize($_GET["cartinfo"]); var_dump($cartinfo); ?> However all I get is: bool(false) Any advice would be great, I also tried adding $cartinfo to the session, but this didn't work either. Surely passing variables should be straight forward??? Thanks. $seat_s is a $var that can have multiple values depending on a form in a previous page. this code works fine as is, but i need to pass the array into a 3rd page. i have no idea how to do this from the code below. ive tried passing the array straight into a _post then _get on the next page but that only holds the 1st value and not all of them. suggestions please.... thanks <?php $seat_s = $_POST['seats']; foreach($_POST['seats'] AS $seat) { $rowId = substr($seat, 0, 1); $columnId = substr($seat, 1); echo $rowId . $columnId . ", "; } ?> This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=359130.0 I recently posted a simple query about ISSET and finally got that simple problem solved thanks to you guys. But I've hit a new snag. I've create a simple sort of cart, or record counter. While I can add/remove/clear items and display their affilated arrays, I don't know how to cycle through a multidimensional array that is dynamically set.
Something like $_SESSION['Primary'][$items][$attributes] - Where $items is a dynamic set, and $attributes is a fixed set of keys with values.
I can target individual $Items, or display all the items in there. But I can't display all the Items and their subsequent $attributes aswell. Do I have to write 1 set of Ajax code for just displaying the $items, and another for each individual set of $attributes? Or is their a way to cycle through each $item, and then all of it's(or specific) $attributes and values? I've tried using loops which logically work, but I can't pass it through json_encode.
Is there any documentation I could read in relation to this? I feel this is the key component to manuvering through a database of sorts. I'm just not entirely sure how to go about accessing multidimensional Array's without a ton of code that becomes redudent. And even then, it wouldnt work well with a dynamic setup.
Edited by 7blake, 07 November 2014 - 01:39 PM. Hello Everyone! I have created a javascript array which now i want to pass to php, so php can store those values to mysql. So please anyone can suggest me how do i pass it to php? Any help will highly be appreciated! I have the registration form blues! form 1 collects the classes chosen, and passes an array of classes chosen(on a previous page), in a hidden field: <input type="hidden" value="<?= $c_row['workshop_id'] ?>" name="wid[]" /> form 2 makes it a variable $wid = $_POST['wid']; I'm trying to pass it to form 3, using the hidden input again, this time as a variable: $wid = $_POST['wid']; <input type="hidden" value="<?= $wid ?>" name="wid[]" /> The next page is a printable page. But I can't do anything with the classes, because it's some how made an array of an array??? I wrote: $wid = $_POST['wid']; print_r($wid); This produces--- Array ( => Array ) I want it to give me the original array? Is there a different way to do this? So I'm trying to create an Array from a comma separated string containing array{s}. How can I take a string full of comma separated hex values such as : <?php $myStr = ( "00ffff", "00cccc", "009999", "007777", "004444", "001111", "01ffff", "01cccc", "019999" ); ?> & turn it into 3 separated arrays like : <?php $myNewArrs = [ Array1 ( 3 ), Array2 ( 3 ), Array3 ( 3 ), ]; ?> which REALLY looks like : <?php $myNewArrs = [ Array ( "00ffff", "00cccc", "009999" ), Array ( "007777", "004444", "001111" ), Array ( "01ffff", "01cccc", "019999" ), ]; ?>
? Thank you & have a great afternoon!
Edited May 27 by AquariaXI I am passing an array to an option list but if a value has two words, the second word doesnt get sent via POST. So if the value should be THE ONE, the word ONE doesnt get sent via POST. Kinda wierd, wondered if there is an easy explanation for this? Code: [Select] <?php echo '<SELECT name=carrier>'; foreach ($allcar as $key => $value) { echo '<OPTION value=' . $value . '> ' . $value . ''; } echo '</select>'; ?> Hi guys, Is there an html code that allows you to array a form input? and once you passed the form, how do you extract the data then insert it to the database? Thanks Okay heres the problem. I have a form which displays items that sit within a packet. (In this case its called Wireless Package 1). Each item has its own specific value, which can be any string, hench why there is an 'input type= text' in the value column in the table. Each of these values is stored in a table, with the primary key 'piid', (show as a hidden field within 3rd column). The problem is when im posting the array 'values[]' I cant distinguish between what value needs to be referenced againist a piid, how do i obtain these individual ID's and Values in a loop so they can turned into a MySql Strings????? I tried using an explode function but got no where, any help is very much apprieciated! This is the code for the form displayed. <table border="1" cellpadding="5" cellspacing="5"> <tr> <th>Item ID</th> <th>Item</th> <th>Value</th> <th>Remove</th> </tr> <form action="edit_packet.php" method="post"> <?php foreach($packages as $packet):?> <tr> <td> <?php echo $packet['piid'] ;?> </td> <td> <?php echo $packet['desc'] ;?> </td> <td> <input type="hidden" name="values[]" value="<?php echo $packet['piid'];?>,," /> <input type="text" name="values[]" value="<?php echo $packet['value']; ?>" /> <input type="hidden" name="values[]" value="///" /> </td> <td> <form action="delete.php" method="post"> <input type="hidden" name="pid" value="<?php echo $packet['piid'];?>"/> <input type="submit" value="Delete Packet"> </td> </tr> <?php endforeach; ?> </table> <input type="submit" value="Submit" /> </form> I have an issue with a form where people choose from several classes, and how many people they're enrolling. If they choose the first class, select the number of students and hit submit, it is supposed to carry the number of students to the 2nd page where a variable is created for it: $qty = $_POST['participantqty']; It works if they pick the first class and choose a number of students. It works if they pick the first class and another, plus the number of students for each. But if they choose any one class except the first one (and only that class), choose their number of students and submit... This is when it doesn't carry the number forward... It also glitches when they select two classes that don't include the first class. It carries the number of students for one, but not the other. qty_insert and qty_total on page two are where the data dissappears. I'm assuming it has something to do with the array, but I'm in a little over my head. On the second page, I added in print_r($myarray); and it shows the variable is passing to the second page. page one: Code: [Select] <form method="post" action="register2.php"> <? //output each row while ($c_row = mysql_fetch_array($result_all_events)){ $display = date("F j", strtotime($c_row['workshop_date'])) ; $i++; //date('d m y', strtotime($mysql_date)); ?> <input type="checkbox" name="workshop_id[]" value="<?= $c_row['workshop_id'] ?>" /> <?= $c_row['workshop_title'] ?> </td><td><?= $c_row['workshop_date'] ?></td><td><select name="participantqty[]" id="" class=""> <option value="">select</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="10">9</option> <option value="10">10</option> </select> $ <?= $c_row['workshop_price'] ?></td></tr><tr><td colspan=3><hr></td></tr> <? } //end while ?> <input type="submit" value="Submit" class="buttontype"> and on page two where it totals things up: Code: [Select] <form method="post" action="register3.php"> <?php // connect to database include("dbconnectionfile.php"); $fname = mysql_escape_string($_POST['fname']); $lname = mysql_escape_string($_POST['lname']); $address = mysql_escape_string($_POST['address1']); $address2 = mysql_escape_string($_POST['address2']); $city = mysql_escape_string($_POST['city']); $state = mysql_escape_string($_POST['state']); $zip = mysql_escape_string($_POST['zip']); $phone = mysql_escape_string($_POST['phone']); $fax = mysql_escape_string($_POST['fax']); $email = mysql_escape_string($_POST['email']); $hear = mysql_escape_string($_POST['hear']); $how1 = mysql_escape_string($_POST['how1']); $how2 = mysql_escape_string($_POST['how2']); $how3 = mysql_escape_string($_POST['how3']); $how4 = mysql_escape_string($_POST['how4']); $res = mysql_escape_string($_POST['resident']); if( $res == NULL ) { $res="No"; } $how = $how1 . $how2 . $how3 . $how4; $query_insertItem = "INSERT INTO tbl_registration (reg_fname, reg_lname, reg_address, reg_address2, reg_city, reg_state, reg_zip, reg_phone, reg_fax, reg_email, reg_how, reg_how_detail, reg_dc) VALUES ('$fname', '$lname', '$address', '$address2', '$city', '$state', '$zip', '$phone', '$fax', '$email', '$hear', '$how', '$res')"; $dberror = ""; $ret = mysql_query($query_insertItem); $reg_id = mysql_insert_id(); $id_reg = $reg_id; // store all posted intemnos and descriptions in local arrays $ids = $_POST['workshop_id']; $qty = $_POST['participantqty']; echo $qty; if(sizeof($_POST['workshop_id'])) { // loop through array $number = count($ids); for ($i=0; $i<=$number; $i++) { // store a single item number and description in local variables $itno = $ids[$i]; $qty_insert = $qty[$i]; $query_insertItemWorkshop = "INSERT INTO tbl_registration_workshop (registration_id, workshop_id, regworkshop_qty) VALUES ('$reg_id', '$itno', '$qty_insert')"; $dberror = ""; $ret = mysql_query($query_insertItemWorkshop); $query_selectAllItems_events = 'SELECT * FROM tbl_workshops where workshop_id = '.$itno; @$result_all_events = mysql_query($query_selectAllItems_events); @$numRows_all_events = mysql_num_rows($result_all_events); @$num=mysql_num_rows($result_all_events); @$z_row = mysql_fetch_array($result_all_events); $qty_total=$qty_insert*$z_row['workshop_price']; $total = $total + $qty_total; // the qty_insert and the qty_total below are what appear blank. if ($ids[$i] <> '') { echo "Description:</b> ". $z_row['workshop_title'] ." " . $qty_insert . " at ". $z_row['workshop_price'] ." each: </td><td valign=top> $". $qty_total ."<br>"; } } } ?> <input type="hidden" name="reg_id" value="<?= $id_reg ?>" /> <input type="hidden" name="total" value="<?= $total ?>" /> <input type="submit" value="Checkout now!" /></form> i created an array like this while{ $ir = 0; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['id_sub']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['seminar_topic']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['seminar_mark']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['attendance']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['internal_mark']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['external_mark']; $ir++; } echo "<input type='hidden' name='ar_std' id='ar_std' value='$stud' /> </table>" ; and it is able to print in the same page using foreach ($stud as $v1) { echo "$v1\n<br>"; foreach ($v1 as $v2) { echo "$v2\n<br>"; } } and in the next page $ar_stud[]=$_POST["ar_std"]; I'm getting an error PHP Warning: Invalid argument supplied for foreach() in save.php on line 25 PHP Stack trace: Hello all, I'm hoping someone can help me out. Here is the code I have for a page that contains a user form: <?php include "include/dbc.php"; include "include/header.inc"; ?> <style type="text/css"> .mydate{ color:#00F; text-decoration:underline; cursor:pointer; } </style> <script type="text/javascript"> function displayDate(d){ var date=new Date(); var D=date.getDate(); date.setDate(D+d); var YYYY=date.getFullYear(); var MM=date.getMonth()+1; MM<10?MM='0'+MM:null; var DD=date.getDate(); DD<10?DD='0'+DD:null; var span=document.getElementById('date'); span.innerHTML= 'Entries for '+MM+'/'+DD+'/'+YYYY; } onload=function(){displayDate(0)}; </script> <h1>Food Diary</h1> <div class="full"> <center><div><span class="mydate" onclick="displayDate(-1)"><img src="images/left_arrow.png" border="0">Yesterday</span> <span id="date" style="font-size:2em;"></span> <span class="mydate" onclick="displayDate(1)">Tomorrow<img src="images/right_arrow.png" border="0"></span></div><br /> <a href="#" onclick="displayDate(0);return false;">Today</a> </center> <div class="full"> <form name="exercise" id="exercise" method="GET" action=""> <center><table> <tr> <td><h3>Add an Activity</h3></td> </tr> <tr> <td><input name="NewSearchString" style="width: 100px" type="text"/> <input type="submit" value="Search" /> </td> </tr> <tr> <td> <select name="activity"> <option value="_">Activity Browse...</option> <option value="all">All Activities</option> <option value="biking">Biking</option> <option value="condition">Conditioning</option> <option value="dancing">Dancing</option> <option value="fish">Fishing & Hunting</option> <option value="Home">Home Activities</option> <option value="misc">Miscellaneous</option> <option value="music">Music Playing</option> <option value="occupation">Occupation</option> <option value="running">Running</option> <option value="sports">Sports</option> <option value="walking">Walking</option> <option value="water">Water Activities</option> <option value="winter">Winter Activities</option> </select> <input type="submit" value="Submit" /></td></tr></table></center></form> </td> </tr> </table> </center> <table width="100%"> <tr bgcolor="#66CC33"> <td><div>Activity</div></td> <td><div>Specific Activity</div></td> <td><div>Time (hh:mm)</div></td> <td><div>Distance</div></td> <td><div>Units</div></td> </tr> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr> <?php if(isset($_GET[activity])) { $category=$_GET[activity]; $result = mysql_query("SELECT * FROM exercise WHERE type='$category'"); ?> <form action="add_activity.php" method="POST"> <?php while($row = mysql_fetch_array($result)) { echo '<tr><td><div>'.$row[Type].'</div></td>'; echo '<td><div>'.$row[Name].'<input type="hidden" name="exerciseid" value="'.$row[Name].'"></div></td>'; echo '<td><div><input type="text" name="duration['.$row['Name'].']"></div></td>'; echo '<td><div><input type="text" name="distance['.$row['Name'].']"></div></td>'; echo '<td><div><select name="metric[]"> <option value="mile" name="mile">mile</option> <option value="Km" name="Km">km</option> <option value="M" name="M">m</option> <option value="Yard" name="yard">yrd</option> <option value="Feet" name="feet">ft</option> </select></div></td></tr>'; } mysql_close(); ?> <tr><td colspan="6" align="center"><input type="submit" name="submit" value="Add Activities" onClick="return confirm( 'Are you sure you want to submit the activities?');"></td></tr> </form> <?php } ?> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr></table> And here is the page that the user information is supposed to be passed to: <?php include "include/dbc.php"; include "include/header.inc"; $duration = $_POST["duration['.$row['Name'].']"]; echo '<h1>Added Activities</h1>'; echo $duration; ?> Well, this isn't working for me. The second page code returns this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING When I execute print_r, the values are returned to me. So I have two questions: 1) What do I need to do to change the code on the 2nd page to echo and POST the array? 2)The database contains multiple exercises under the same name. So, when the variables are passed to the 2nd page. All the values are returned regardless of whether they have been filled out or not. What can be done to only returned the user input and not the blank variables? |