PHP - Passing Parameters In Url Not Passing
Code: [Select]
<?php $parentesco .=' <ul><li><a href="children.php?category_id='.$idc.'&name= '. $name2 . '">'. $name. ' </a></li></ul>'; ?> in the url string $idc is passing but $name2 is not. $name2 is pickup from a query, I echo that value everywhere in the code and it echo its value but is not passing so how. Help Similar TutorialsI 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. I am calling CURL and trying to do a POST request with parameters: Code: [Select] $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Accept: application/json", "Content-Type: application/json")); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl, CURLOPT_USERAGENT, "curl 7.23.1 (x86_64-unknown-linux-gnu)"); curl_setopt($curl, CURLOPT_USERPWD, "username:password"); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_URL, "https://www.mydomain.com/route"); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, "key1=blah1&key2=blah2"); return curl_exec(curl); The problem, inside the request at http://www.mydomain.com/route I am not seeing any POST parameters passed. I.E. Code: [Select] print_r($_POST); Code: [Select] Array ( ) Should have key1=blah1 and key2=blah2. Any ideas? Hello again, Though this question is somewhat related to my prior note, I thought it was probably different enough to justify a separate topic... So, I have a link at site1.com/dir/admin/?param1=value¶m2=value, etc, which I want to redirect to site2.com with all the rest being the same. Thanks to your help, it's working with two specified parameters However, there is a relatively short list of potential parameters (maybe 5?) but not all of them are passed in all calls to the link. In other words, sometimes the link is called with param1 and param2, sometimes with 1 and 3, sometimes with 1,2, and 4, etc. What is the best way to do the redirect which would ensure that all the parameters which are sent to the initial link are then included in the redirect? Is there a way to search the incoming link and grab all parameters in it? Or do I put together the list of possible parameters and then grab the values with $_GET for all of them and then pass all of them even if the values are null (not sure whether the app will accept that or not...) I hope I'm stating the question clearly enough! Thanks in advance for your help! I work with a large codebase and I have this situation come up fairly often:
the legacy class has large objects such as:
$design->motor->dimensions->a; $design->motor->dimensions->bd; $design->specifications->weight; $design->data->height; //etcWhen I create a new class, that class sometimes operates on the specific data, so say: class MyClass { public function compute($weight, $height, $a) { //stuff } } //and I call this for example as such: (new MyClass())->compute($design->specifications->weight, $design->data->height, $design->motor->dimensions->a);CONS: Potential issue: if design specs change and I need to change things parameters in "compute" function, I need to "re-key" the variables I pass to the function, and adjust things accordinly in MyClass as wel. PROS: only the exact data is being passed, and this data can come from anywhere it is viable, so in effect the function is fairly well separated, I think. Alternative option for me is to pass the entire design object, i.e class MyClass { public function compute(&$design) //can also be done via DI through a setter or constructor. { print $design->specifications->weight; print ($design->data->height + $design->motor->dimensions->a); //stuff } } (new MyClass())->compute($design);PROS: In this case when things change internally in which variables are needed and how things are computed, I only need to change the code in compute function of the class itself. CONS: MyClass now needs to be aware of how $design object is constructed. When it comes to this parameter passing, and Dependency Injection like this in general, does Computer Science advocate a preference on this issue? Do I pass the entire object, or do I pass only the bits and pieces I need? Ok quick run down... I need to pass a variable from one page[form] to another while skipping a page that is in the middle. The middle page is paypal... after they pay, they are being redirected to a thank you for registering with a email also being sent. But I need their email from the first page[form]. so what i need to figure out or help is: 1. First page is a form, they enter name, last name, address, email and so on 2. They are redirected to paypal to pay for a service. 3. Are directed back to my site for a email to be sent to them, but I need their email from the first page. Hi, I'm trying to pass a variable into a URL and apparently I'm doing it wrong this code is OK Code: [Select] $id = $3; echo '<a href="newPage.php?id=3"></a> If I use Code: [Select] $id = $_GET['id']; echo $id; on the newPage.php, I echo 3 whereas, if I do Code: [Select] $id = $3; echo '<a href="newPage.php?id="'.$id.'"></a> when echo out on the newPage.php it prints out nothing also, in current url look like this: Code: [Select] www.site.com/newPage.php?id= What am I doing wrong? Many thanks Can anyone explain to me why this system isnt working? I have no clue why it shouldnt be. The pin number is passed from a form to this script, which then determines if a users pin is correct and if so, forwards them onto the relevant page. Otherwise, it returns them to the login. <?php session_start(); $pin=$_POST['pin']; if ($pin='7221') { $_SESSION['pin']='7221'; $_SESSION['name']='Keith D Whelpton'; header('Location: phonesystem.php'); } elseif ($pin='3585') { $_SESSION['pin']='3585'; $_SESSION['name']='Luke S Barnes'; header('Location: phonesystem.php'); } else { header('Location: phonelogin.php'); } ?> here is my code: Code: [Select] $query2 = "SELECT * FROM members_copy WHERE RSUSER = ".$_SESSION["rsUser"].""; $result2 = mysql_query($query2); $UserID = $result2['USERID']; echo $UserID; When I echo out UserID it doesn't show a number?! Please help?! $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 . ", "; } ?> <?php $opid = $_GET['opid']; $sql="Select * from `ships` WHERE `enabled` = 'Yes'"; $result = mysql_query($sql) or die (mysql_error()); echo "<form action=main.php?id=joinop.php&opid=".$opid." method=post> Ship Type: <select name = ship>"; while ($row = mysql_fetch_array($result)) { echo "<option Value=".rawurlencode($row['shiptype']).">".$row['shiptype']."</option>"; } echo "</select> <input name=submit type=submit value=Join> </form>"; if (isset($_POST['submit'])) { $stype = rawurldecode($_Post['ship']); $stime = date("G:i:s",time()); $sql="Select * from `ships` WHERE `shiptype` = '$stype'"; $result = mysql_query($sql) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { $weight = $row['weight']; } echo $stype; mysql_query ("INSERT INTO `ccccomma_eve`.`userops` (`id` ,`starttime` ,`endtime` ,`shiptype` ,`weight` ,`payout` ,`active`) VALUES ('$opid', '$stime', '', '$stype', '$weight', '', 'Yes')") or die (mysql_error()); Echo "Op Joined"; } ?> The variable is empty when I echo it out, any ideas on how to make to stick? Here is just the form that is giving me trouble echo "<form action=main.php?id=joinop.php&opid=".$opid." method=post> Ship Type: <select name = ship>"; while ($row = mysql_fetch_array($result)) { echo "<option Value=".rawurlencode($row['shiptype']).">".$row['shiptype']."</option>"; } echo "</select> <input name=submit type=submit value=Join> </form>"; Hello all, So I've picked up a PHP book in an attempt to learn it. The issue I'm having is preventing me from getting any further. They have me creating a simple order form, but the data is not passing from the HTML page to the PHP Processing file. I know there are other ways of doing this that I'm unaware of, but this code is verbatam to what we are isntructed to type within the book itself. Here is the code orderform.html: Code: [Select] <html> <body> <form action="processorder.php" method="post"> <table border="0"> <tr bgcolor="#cccccc"> <td width="150">Item</td> <td width="15">Quantity</td> </tr> <tr> <td>Tires</td> <td align="center"><input type="text" name="tireqty" size="3" maxlength="3"></td> </tr> <tr> <td>Oil</td> <td align="center"><input type="text" name="oilqty" size="3" maxlength="3"></td> </tr> <tr> <td>Spark Plugs</td> <td align="center"><input type="text" name="sparkqty" size="3" maxlength="3"></td> </tr> <tr> <td>How did you find Bob's?</td> <td><select name="find"> <option value = "a">I'm a regular customer</option> <option value = "b">TV advertising</option> <option value = "c">Phone directory</option> <option value = "d">Word of mouth</option> </select> </td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Submit Order"></td> </tr> </table> </form> </body> </html> processorder.php: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Bobs Auto Parts - Order Results</title> </head> <body> <h1>Bobs Auto Parts</h1> <h2>Order Results</h2> <?php $tireqty = $_post['tireqty']; $oilqty = $_post['oilqty']; $sparkqty = $_post['sparkqty']; echo "<p>Order Processed at "; echo date('H:i, jS F Y'); echo "</p>"; echo '<p>Your order is as follows: </p>'; echo $tireqty.' tires<br />'; echo $oilqty.' bottles of oil<br />'; echo $sparkqty.' spark plugs<br />'; $totalqty = 0; $totalamount = 0.00; define('TIREPRICE', 100); define('OILPRICE', 10); define('SPARKPRICE', 4); ?> </body> </html> For some reason the values on the processing form dont show up. The only text thats displayed is : Bobs Auto Parts Order Results Order Processed at 17:07, 9th January 2011 Your order is as follows: tires <---- Should be showing the total quantity ordered bottles of oil <---- Should be showing the total quantity ordered spark plugs <---- Should be showing the total quantity ordered Is anyone able to let me know where the error is in this code? The writers website isnt any help.... Regards, sapper6fd I cannot figure this out and I know I'm just looking past the obvious... I am creating a simple "you are now leaving this website" page, Everything is setup, and all urls pointing to http://mysite.com?exit=http://externalsite.com, It should redirect to my exit.php which will redirect to the external site after 5 seconds. The problem is, the "http://" of the external site is causing a 403 forbidden, and even without it, anything with multiple &s isn't passing through. I cannot figure out how to get it to pass the full url to the exit.php... This is driving me MAD! The Variable gets passed through the URL but when I try and echo the result I gte NOTHING. First Page. Code: [Select] <?php include'config.php'; $result = mysql_query("SELECT * FROM carbontrust"); while($entry = mysql_fetch_array($result)) Print "$entry[contact] - $entry[company] :: <a href='edit.php?id=$entry[id]'>Edit</a><br>"; exit; ?> Second Page. (Where I want the Variable passed to) Code: [Select] <?php include'config.php'; $id = $_GET['id']; echo "ID: $id"; } ?> Its probably just a stupid error but iv looked through a load of tutorials and this should be correct. :/ I am storing thousands of titles in mysql and many of these have a title with an ampersand. An example is how AT&T is getting stored in the database: at-amp-t Easy enough, I thought.. I'll just run str_replace on it before I save it to the database. $title = str_replace("-amp-", "&", $title); That works great.. except when I click the new hyperlink created from this url. It looks correct... showing the exact url of what is stored in mysql: (http://www.domain.com/this-is-the-at&t-title) ...but no url with this ampersand works. All other $title urls works great. If I don't run str_replace on it, it works fine.. but then I get a url stored as at-amp-t... which I'm trying to avoid. Thoughts? hi all. i am so lost here guys,i need your help. basically, i have 3 pages here. _add_tsubject, _query_subject, and _do_addtsubject. _add_tsubject here contains a livesearch javascript that searches for subjects which i query in _query_subject. the result of that is displayed in _add_tsubject. i am using get method for that and for the url. now, my problem is how to pass or should i say combine the url from _add_tsubject with the url inside the <a href> in _query_subject?or is it possible??i'm sorry if it sounds confusing. but if it's confusing you please have a look at the code.. _add_tsubject <?php include("dbconnection_wmsuipil.php"); $id = $_GET['item']; $t_id = $_GET['t_id']; $lname = $_GET['lname']; $fname = $_GET['fname']; $result= mysql_query("SELECT * FROM tblSetSY")or die(mysql_error()); while($row = mysql_fetch_array($result)) { $setYear=$row['SchoolYear']; $setSem=$row['Sem']; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Adding subject to teacher..</title> <link rel="stylesheet" href="style.css"/> <link rel="stylesheet" href="validator_style/screen.css"/> </head> <body> <div style="margin-right:30px; padding:10px;" align="right"><a href="#" onclick="window.location.reload()">Reload</a> | <a href="#" onclick="window.close()">Close</a></div> <form name="form" id="cmxform_sched" class="cmxform" method="post" action="_do_addtsubject.php"> <fieldset> <p> <label for="t_id">Teacher ID: </label> <input type="hidden" name="school_year1" value="<?php echo $setYear;?>"/> <input type="hidden" name="sem1" value="<?php echo $setSem;?>"/> <input type="hidden" name="id" value="<?php echo $id;?>" size="15"/> <input type="text" name="t_id" value="<?php echo $t_id;?>" size="15"/> </p> <p> <label for="name">Name: </label> <input type="text" name="name" value="<?php echo $fname.' '.$lname;?>" size="25"/> </p> <p><i>*Add subjects to be handled...</i></p> <p><label for="keyword">Enter Subject ID: </label> <input type="text" name="sid" id="sid" size="15" onkeyup="showResult(this.value)" /> </p> <div id="livesearch" align="center"><b>->Subject info will be listed here<-</b></div> </table> </fieldset> </form> <script type="text/javascript"> function showResult(str) { if (str.length==0) { document.getElementById("livesearch").innerHTML=""; document.getElementById("livesearch").style.border="0px"; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("livesearch").innerHTML=xmlhttp.responseText; document.getElementById("livesearch").style.border="1px solid #A5ACB2"; } } xmlhttp.open("GET","_query_subject.php?q="+str,true); xmlhttp.send(); } </script> </body> </html> _query_subject (i get an error on the _POST here..) <?php include("dbconnection_wmsuipil.php"); $t_id=$_POST['t_id']; $name=$_POST['name']; $sy=$_POST['school_year1']; $sem=$_POST['sem1']; $q=$_GET['q']; $sql="SELECT * FROM admin_subject WHERE subj_id like '%".$q."%'"; echo "<table border='1'> <tr> <th>#ID</th> <th>Subject ID</th> <th>Subject Code</th> <th>Description</th> <th>Lect</th> <th>Lab</th> <th>Units</th> </tr>"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { $OutLine = array('id'=>'','subj_id'=>'','subj_code'=>'','subj_desc'=>'','lecture'=>'','laboratory'=>'','units'=>''); $OutLine['id'] = $row['id']; $OutLine['subj_id'] = $row['subj_id']; $OutLine['subj_code'] = $row['subj_code']; $OutLine['subj_desc'] = $row['subj_desc']; $OutLine['lecture'] = $row['lecture']; $OutLine['laboratory'] = $row['laboratory']; $OutLine['units'] = $row['units']; $countTsubj=0; if($row>$countTsubj) { echo "<tr>"; echo "<td>".implode('<td/>',$OutLine); echo '<td><a href="_do_addtsubject.php?id='.$row['id'].'&subj_id='.$row['subj_id'].'&code='.$row['subj_code'].'&desc='.$row['subj_desc'].'&lect='.$row['lecture'].'&lab='.$row['laboratory'].'&units='.$row['units'].'">[Add]</a></td>'; echo "</tr>"; } } echo "</table>"; ?> _do_addtsubject <?php include("dbconnection_wmsuipil.php"); $t_id=$_POST['t_id']; $name=$_POST['name']; $sy=$_POST['school_year1']; $sem=$_POST['sem1']; $id=$_GET['id']; $subj_id=$_GET['subj_id']; $code=$_GET['code']; $desc=$_GET['desc']; $lect=$_GET['lect']; $lab=$_GET['lab']; $units=$_GET['units']; echo $t_id; echo $name; echo $sy; echo $sem; echo $id; echo $subj_id; echo $code; echo $desc; echo $lect; echo $lab; echo $units; ?> there guys..i hope you can help me..the last page is where plan to echo the url once it's combined..please please help.. hey guys i am stuck at one part. i am coding a site where on the index page there are 5 categories. Now on click of these it takes me to a page where i can search within a particular category. i can do it by statically giving <href="localhost/xampp/abc.php">and a fixed page path. but i want the name of the category passed when i click and the search page to open when i open search. thanks hello all, I'm new here and I'm learning mysql/php. Currently I have a dynamic table on one of my webpages, and the loop code looks like this:while ($i < $numRows) { $fname = mysql_result($result, $i, "fname"); $fcode = mysql_result($result, $i, "fcode"); $ftype = mysql_result($result, $i, "ftype"); $fdesc = mysql_result($result, $i, "fdesc"); ?> <tr> <td><a href="showfunction.php?fname=<?php echo "$fname"; ?>" target="_self"> <?php echo "$fname"; ?></a></td> <td> <?php echo "$fdesc"; ?> </td> <td><div align="center"> <?php echo "$ftype"; ?> </div></td> </tr> <?php $i++; } ?> what I would like to do is pass the ''fname'' variable to the "showfunction" page so it can printed from the database. Here is the relevant portion of the page:<body><div class="codeblock"> <div class="title">Code:<br /> </div><code><pre> <?php echo $fcode; ?> </pre></code></div> <br /><pre><hr /> </pre> I know that doesn't work, and I didn't expect it to because there is no way to 'get' the 'fname' variable from the preceeding script. I do not want to use the GET method with this because from what I understand, you can only use it with Forms. I really don't want to put controls in all of my table fields just to be able to pass the function name to the next page. Does that make sense? If I could get a jumpstart on this one last hurdle, I would appreciate it. thank you so much! Cheers. Hi First post here. Long time reader! I'm looking to gauge the general practices of dealing with variables between pages. I'd always pass my variables through the POST. Im normally always doing a post back and processing the data at the top of the page. I never liked the query string as it open to manipulation, but can see its use for a search results page and saving the url. I came from a ASP background and we would only use session variables for holding user login information as the windows server had a habit of restarting the pool and loosing the session. We didn't want this happening, for example, when doing an e-commerce transaction. We always felt the post was the most robust method. Now Im using php and all the great features it has. I was looking to see what the more experience php developers used and am I right sticking to the post method, or is utilising session a more modern way of doing things. I've a few years experience doing web dev, just thought I touch base on a few issues to make sure I'm still heading in the right direction. Thanks for any advice guys! Hi, I am trying to pass a variable when posting a form. This is my form with the select: Code: [Select] <form id="form1" name="form1" method="post" action="products_2.php?id_subcategoria= WHAT SOULD I PUT HERE?"> <select name="subcats" class="subcatsSelectMenu" id="subcats" onchange="this.form.submit()"> <option value="">Ver placas por tipos</option> <?php do { ?> <option value="<?php echo $row_subcats_RS['id_subcategoria']?>"><?php echo $row_subcats_RS['subcategoria_esp']?></option> <?php } while ($row_subcats_RS = mysql_fetch_assoc($subcats_RS));$rows = mysql_num_rows($subcats_RS); if($rows > 0) { mysql_data_seek($subcats_RS, 0); $row_subcats_RS = mysql_fetch_assoc($subcats_RS); } ?> </select> </form>How can I pass the variable in the URL? Thanks 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. |