PHP - I Need Help Passing Array Variables/ Singling Out User Data
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? Similar TutorialsHello all, I am hoping that someone can help me out with some code that I have. Here is the code: <?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> The code pulls variables, called exercise activities, from a table and allows the user to input the duration and distance that they completed the exercise. The second page looks like this: <?php include "include/dbc.php"; include "include/header.inc"; $exerciseid = $_POST["exerciseid"]; $duration = $_POST["duration"]; $distance = $_POST["distance"]; $metric = $_POST["metric"]; echo'<h1>Added Activities</h1>'; // name of array echo '<h1>Exercise</h1>'; if (is_array($exerciseid)) { foreach ($exerciseid as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Duration</h1>'; if (is_array($duration)) { foreach ($duration as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Distance</h1>'; if (is_array($distance)) { foreach ($distance as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Metric</h1>'; if (is_array($metric)) { foreach ($metric as $key => $value) { echo $key .' : '. $value .'<br />'; } } ?> Here is what the second page of php code returns: [text] Added Activities Exercise 0 : Automobile repair 1 : Carpentry, general 2 : Carrying heavy loads, such as bricks 3 : Construction, outside, remodeling 4 : Electrical work, plumbing 5 : Farming, baling hay, cleaning barn 6 : Farming, milking by hand 7 : Farming, shoveling grain 8 : Marching, rapidly, military 9 : Painting, papering, plastering, scraping Duration Automobile repair : 26 Carpentry, general : Carrying heavy loads, such as bricks : Construction, outside, remodeling : Electrical work, plumbing : Farming, baling hay, cleaning barn : Farming, milking by hand : Farming, shoveling grain : Marching, rapidly, military : Painting, papering, plastering, scraping : Distance Automobile repair : 25 Carpentry, general : Carrying heavy loads, such as bricks : Construction, outside, remodeling : Electrical work, plumbing : Farming, baling hay, cleaning barn : Farming, milking by hand : Farming, shoveling grain : Marching, rapidly, military : Painting, papering, plastering, scraping : Metric 0 : M 1 : mile 2 : mile 3 : mile 4 : mile 5 : mile 6 : mile 7 : mile 8 : mile 9 : mile [/text] Though this works, I want it to be better. I want a way to single out only the data the user inputs and not return everything else. Any ideas/suggestions are welcomed. Thank you! 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. I have a some value that are being generated from a database then thrown into <li><href> to create a list that user can click and fetch data through ajax right now its in a form select/menu and works fine however I need to convert to a list and use and onKeyDown event Code: [Select] <form> <select name="users" size="<?php echo $num_rows;?>" onchange="showUser(this.value)" > <?php do { ?> <option value="<?php echo $row_Recordset1['item_id']?>"><?php echo $row_Recordset1['item_id'].' '. $row_Recordset1['item_name']?></option> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); $rows = mysql_num_rows($Recordset1); if($rows > 0) { mysql_data_seek($Recordset1, 0); $row_Recordset1 = mysql_fetch_assoc($Recordset1); } ?> </select> </form> I need to correct this Code: [Select] <ol> <?php do { ?> <li onKeyDown="showUser(this.value)"><a href="getmenu.php?item_id="<?php echo $row_Recordset1['item_id']?>"> <?php echo $row_Recordset1['item_name']?></a></li> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); $rows = mysql_num_rows($Recordset1); if($rows > 0) { mysql_data_seek($Recordset1, 0); $row_Recordset1 = mysql_fetch_assoc($Recordset1); } ?> </ol> I can add and delete data from my table. Now I need to be able to change one or more fields in an entry. So I want to retrieve a row from the db, display that data on a form where the user can change any field and then pass the changed data to an update.php program. I know how to go from form to php. But how do I pass the data from retrieve.php to a form so it will display? Do I use a URL and Get? Can I put the retrieve and form in the same program? I'm a newbie here and to php and Javascript. So hello all. I am trying to get a portion of a file name passed from one file (first.php) which displays a MySql table. One of the fields is a link that is supposed to open a popup window (second.php) and begin playing a mp3 file with the flash media player. I have everything (almost) working. The table displays as it should, the link is fine. However, I can not get the popup to open with the dimensions I asked for. It opens in a full size new window. And the mp3 will not play. I get the message from the player "we are unable to connect...etc etc". The file name shows up in the status bar and in the URL window. In the file first.php, the table displays, the links appear to be active. when clicked the new window opens, the file names carry over but I can not get the file to play. The player loads (in file second.php) but I get the message from the player "we are unable to connect...etc etc". I suspect it is in the syntax. I have tried so many combinations I can't list them here and so far I have been unable to find anything on google, etc to answer this. After almost three days I have resorted to here. This may not even be the right place for me. Javascript may be my best bet for all I know. Can someone please look over what I have and at least point me in the right direction? Any help is greatly appreciated as this is my first attempt at a website. Thanks first.php Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script language="JavaScript"> <!-- Begin function popUp(URL) { playwindow=window.open(URL, 'name', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=350,height=250'); } // End --> </script> <script language="JavaScript"> <!-- function openPlayer(URL) { player = window.open('player10.php?','width=350,height=275') } // End --> </script> <?php $username="myusername"; $password="mypassword"; $database="mydb"; mysql_connect('mydb',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM mytable"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> </head> <body> <table border="1" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Listen</font></th> <th><font face="Arial, Helvetica, sans-serif">f2</font></th> <th><font face="Arial, Helvetica, sans-serif">f3</font></th> <th><font face="Arial, Helvetica, sans-serif">f4</font></th> <th><font face="Arial, Helvetica, sans-serif">f5</font></th> <th><font face="Arial, Helvetica, sans-serif">f6</font></th> </tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"listen"); $f2=mysql_result($result,$i,"field2"); $f3=mysql_result($result,$i,"field3"); $f4=mysql_result($result,$i,"field4"); $f5=mysql_result($result,$i,"field5"); $f6=mysql_result($result,$i,"field6"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><a href="javascript:openPlayer('player10.php?<?php echo $f1?>')">Listen</a></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f6; ?></font></td> </tr> <?php $i++; } ?> </body> </html> SECOND.PHP Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > <meta http-equiv="X-UA-Compatible" content="IE=8" > <title>My Title </title> <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" > <script language="JavaScript" type="text/javascript"> <!-- // // Make sure there's some data // if (location.search) { // // Extract the name of the graphics file // var mp3_filename = location.search.substring(1) // // Write the <IMG> tag using the name of the graphics // file (you may need to adjust the SRC text) // document.write('<a href="http://mywebsite.com/+mp3_filename">') } // End --> </script> </head> <body> <object width="400" height="300"> <param name="movie" value="http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf"> </param> <param name="flashvars" value="src=http%3A%2F%2Fmywebsite.com%2Faudio%2F+mp3_filename"> </param> <param name="allowFullScreen" value="true"> </param> <param name="allowscriptaccess" value="always"> </param> <embed src="http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="400" height="300" flashvars="src=http%3A%2F%2Fmywebsite.com%2Faudio%2F+mp3_filename"> </embed> </object> </body> </html> I have the following code that outputs a url. It searches my MySQL database for the name of a given item within a theme: $relative = 'http://www.domain.com/wp-content/'; $url1= $relative . 'themes/arjuna-x/itemspec.php?type='; $url2='&item='; <a class="entry-thumbnails-link" href="<?php echo $url1.'Themes'.$url2.$rowThemes['Theme']; ?>"> The output is as follows: http://www.domain.com/wp-content/themes/arjuna-x/itemspec.php?type=Themes&item=(insert variable here) All is good up to this point. My problem however, is that some items (in this case: theme names) have apostrophes in them. For example: April Fool's. This results in breaking my php code. How can I get php to call these variables with apostrophes so that they don't break my php? 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 hai everybody....
1. can any one let me know how to pass a variable from view to controller in CodeIgniter...
2. if possible send me a complete login application...developed by using CodeIgniter....
Thanks & Regards,
Shankaar.
I normally don't work with PHP or rather I'm learning as I go..and this is pretty much my last barrier between completing this project. Anyway here are my two files: http://pastebin.com/aThU3akC - file i want to grab values from and pass to the file below http://pastebin.com/kTYHr99p - file that is suppose to display the values in $transmessage Basically I need the variables defined in the first file to be passed and usable in the second and I'm not sure why I can't 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! The code below is a form the gets information from a database and post it into the appropriate field. I am having a problem with the while loop. All the variables before the while loop work just great and echo out how they should. But everything after the while loop does not work. I know it has something to do with the while loop because when I take the while loop out everything works as it should. Can anyone please help me with this? <? $id = $_POST["id"]; $therapy = $_POST["therapy"]; db_connect(); $query=mysql_query("select * from student where student_id = $id") or die ("invalid query"); $row=mysql_fetch_array($query); print "<table width='330' border=0 align='center'> <form method='POST' action='table.php'> <td>*First Name:</td> <td>*Last Name:</td> <tr>"; ?> <td width="157"><input size="23" name="first_name" value="<?php echo "$row[first_name]"; ?>" /></td> <td width="138"><input type="text" size="23" name="surname" value="<?php echo "$row[surname]"; ?>" /></td> </tr> <tr> <td>Level:</td> <td>Therapy:</td> </tr> <tr> <td> <select name="program_level"> <option <?php if ($row[program_level]=='1') echo "selected=yes"; ?> value="1">O&A</option> <option <?php if ($row[program_level]=='2') echo "selected=yes"; ?> value="2">Student</option> <option <?php if ($row[program_level]=='3') echo "selected=yes"; ?> value="3">Supervisor</option> <option <?php if ($row[program_level]=='4') echo "selected=yes"; ?> value="4">Manager</option> <option <?php if ($row[program_level]=='5') echo "selected=yes"; ?> value="5">Director</option> <option <?php if ($row[program_level]=='6') echo "selected=yes"; ?> value="6">Graduate</option> </select> </td> <td> <!-- Auto drop down for therapist names--> <? $query2=mysql_query("select * from therapy_info;"); ?> <select name='therapy'> <? while ($row=mysql_fetch_assoc($query2)){ ?> <option value="<? echo "$row[therapy_name]"; ?>"> <? echo "$row[therapy_name]"; } ?> </option> </select> <!-- End Auto drop down for therapist names--> </td> </tr> <tr> <td>Active:<?php echo "$row[active]"; ?></td> </tr> <tr> <td><select name='active' value='$row[active]'> <option <?php if ($row[active]=='1') echo "selected=yes"; ?> value='1'>Active</option> <option <?php if ($row[active]=='0') echo "selected=yes"; ?> value='0'>Inactive</option> </select> </td> </tr> <?php print "<tr> <td><input type='submit' value='Change' name='button' /></td> <input type='hidden' name='id' value='$id' />"; ?> <input type='hidden' name='$hardcode_session' /> <? print "</tr> </form> </table>"; 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 I'm creating this URL to pass variables to use from one Page to another:
http://eg10basketbal...Borgman&team=16
My WP site is seeing the first variable but not the second. After some searching I've found this suggestion, but it's not working for me:
function add_query_vars_filter( $vars ) { $vars[] = "nameFull"; $vars[] = "team"; return $vars; } add_filter( 'query_vars', 'add_query_vars_filter' );I tried putting this in the wp-includes/functions.php file of the, but ended up with a fatal error. I have since added it to my theme's functions.php file. There isn't an error, but it doesn't yield recognition of my second variable. Is it possible to use PHP variables in a jQuery file that is including in the header of the file? If so, how? Hi there,
I want to pass a input variable from login_success.php which will be sent to sqlprocess.php as the variable 'SQLinput';
sqlprocess.php
$link = mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $query = $_REQUEST['SQLinput']; //You don't need a ; like you do in SQL $result = mysql_query($query); $numfields = mysql_num_fields($result);login_sucess.php <form action="" method="post" <label> <span>SQL Input :</span> <input type ="text" id="message" name="SQLinput" placeholder="Input SQL"></textarea> </label> <label> <span>SQL Output :</span> <output id="text" id="SQLoutput" ></input> <script type="text/javascript" charset="utf-8"> // handles the click event for link 1, sends the query function getOutput() { getRequest( 'sqlprocess.php', // URL for the PHP file drawOutput, // handle successful request drawError // handle error ); return false; } // handles drawing an error message function drawError () { var container = document.getElementById('output'); container.innerHTML = 'Bummer: there was an error!'; } // handles the response, adds the html function drawOutput(responseText) { var container = document.getElementById('output'); container.innerHTML = responseText; } // helper function for cross-browser request object function getRequest(url, success, error) { var req = false; try{ // most browsers req = new XMLHttpRequest(); } catch (e){ // IE try{ req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { // try an older version try{ req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ return false; } } } if (!req) return false; if (typeof success != 'function') success = function () {}; if (typeof error!= 'function') error = function () {}; req.onreadystatechange = function(){ if(req .readyState == 4){ return req.status === 200 ? success(req.responseText) : error(req.status) ; } } req.open("GET", url, true); req.send(null); return req; } </script> <a href="#" onclick="return getOutput();"><button type="submit" id="search_btn" value="Submit">Submit</button> </a> <div id="output">waiting for action</div>Prior to the JS code - I was able to peform this action - however the JS code enables me to post the query onto the same page. I would like essentially like to query the database through an input box and output the same result on the same page. Thanks! The below works for ?rma=non-returned and &year=$year, however once it's get down to month it doesn't work. Everything seems to be in the proper brackets, but it's still not working. It goes to a blank page when month=$month is added to the URL. The URL looks like this : ?rma=calander&year=2011&month=5 Code: [Select] elseif($_GET['rma']=="calender"){ $sql101010="SELECT DISTINCT rma_year_issued FROM $tbl_name4 WHERE rma_issued='y' ORDER BY rma_year_issued"; $result101010=mysql_query($sql101010); while($row101010=mysql_fetch_array($result101010)){ extract($row101010); $content.='<a href="./acp_admincp.php?rma=calender&year='.$rma_year_issued.'">'.$rma_year_issued.'</a> <br />'; } if(isset($_GET['year'])){ $content=""; $logout.=' | <a href="./acp_admincp.php?rma=calender">Back to RMA Calender</a>'; $rma_year_issued=$_GET['year']; $sql111010="SELECT DISTINCT rma_month_issued FROM $tbl_name4 WHERE rma_year_issued='$rma_year_issued' ORDER BY rma_month_issued"; $result111010=mysql_query($sql111010); while($row111010=mysql_fetch_array($result111010)){ extract($row111010); if($rma_month_issued=="1"){$rma_month_issued2="January";} if($rma_month_issued=="2"){$rma_month_issued2="February";} if($rma_month_issued=="3"){$rma_month_issued2="March";} if($rma_month_issued=="4"){$rma_month_issued2="April";} if($rma_month_issued=="5"){$rma_month_issued2="May";} if($rma_month_issued=="6"){$rma_month_issued2="June";} if($rma_month_issued=="7"){$rma_month_issued2="July";} if($rma_month_issued=="8"){$rma_month_issued2="August";} if($rma_month_issued=="9"){$rma_month_issued2="September";} if($rma_month_issued=="10"){$rma_month_issued2="October";} if($rma_month_issued=="11"){$rma_month_issued2="November";} if($rma_month_issued=="12"){$rma_month_issued2="December";} $content.='<a href="./acp_admincp.php?rma=calander&year='.$rma_year_issued.'&month='.$rma_month_issued.'">'.$rma_month_issued2.'</a> <br />'; } if(isset($_GET['month'])){ $content=""; $logout.=' | <a href="./acp_admincp.php?rma=calender&year='.$rma_year_issued.'">Back to RMA Calender Year</a>'; $rma_month_issued=$_GET['month']; $sql211010="SELECT * FROM $tbl_name4 WHERE rma_year_issued='$rma_year_issued' AND rma_month_issued='$rma_month_issued' ORDER BY rma_date_issued"; $result211010=mysql_query($sql211010); while($row211010=mysql_fetch_array($result211010)){ $content.='<a href="./acp_admincp.php?rma=calander&year='.$rma_year_issued.'&month='.$rma_month_issued.'&id='.$rma_id.'">'.$rma_number.'</a> <br />'; } } } } The issue maybe the AND in the SQL query... however I need to be sure that the data pulled is of that specific month and that specific year. Not one or the other. I have a little problem. I have made a script(function) to connect to the database. this is the script: connect(php) Code: [Select] <?php $server = "localhost"; $username = "username"; $password = "password"; function connectdatabase($type,$database) { if($type == "mysql") { $mysql = mysql_connect($server, $username, $password); mysql_select_db($database, $mysql); } else if($type == "mysqli") { $mysqli = new mysqli($server, $username, $password, $database); } else if($type == "mssql") { $mssql = mssql_connect($server, $username, $password); mssql_select_db($database, $mssql); } function query($query) { if($type == "mysql") { mysql_query($query); } else if($type == "mysqli") { $mysqli->query($query); } else if($type == "mssql") { mssql_query($query); } } } ?> and aanmelden(php) Code: [Select] <?php include("config.php"); connectdatabase("mysql", "[ledensysteem]"); //example if(!empty($_POST)) { if(!preg_match('/^[A-Za-z1-9-]{'.$Minimale_Gebruikersnaam_Karakters.',}$/', $_POST['gebruikersnaam'])) { if(!isset($error)){ $error=1;}else{$error=$error+1;} echo "Je gebruikersnaam moet minimaal {$Minimale_Gebruikersnaam_Karakters} tekens bevaten en mag geen komma of andere onbedoelde tekens zijn<br>Toegestaan is <br>A t/m Z <br>a t/m z <br>1 t/m 9 <br>en -"; } else { echo "geldige gebruikersnaam(goedgekeurd)"; } if(preg_match('/^[A-Za-z1-9-]{'.$Minimale_Wachtwoord_Karakters.',}$/', $_POST['wachtwoord']) && preg_match('/^[A-Za-z1-9-]{'.$Minimale_Wachtwoord_Karakters.',}$/', $_POST['herhaalwachtwoord'])) { if($_POST['wachtwoord'] != $_POST['herhaalwachtwoord']) { if(!isset($error)){ $error=1;}else{$error=$error+1;} echo "niet hetzelfde wachtwoord"; } /*else { echo "hetzelfde wachtwoord (goedgekeurd)"; }*/ } else { if(!isset($error)){ $error=1;}else{$error=$error+1;} echo "wachtwoord moet minimaal {$Minimale_Wachtwoord_Karakters} tekens bevatten!"; } if(!preg_match("/^[A-Za-z1-9_.-]{1,}@[A-Za-z1-9-]{1,}\.[A-Za-z1-9]{2,3}$/", $_POST['email'])) { if(!isset($error)){ $error=1;}else{$error=$error+1;} echo "onjuiste email"; } else { echo "goedgekeurd!"; } if(!isset($error)) // this problem is fixed yesterday on phpfreaks.com forum! { echo "goedgedaan geen errors!"; query("SELECT username FROM phpfreaks WHERE password = private"); // example } } else { ?> <HTML> <HEAD> <TITLE>New Document</TITLE> </HEAD> <BODY> <form method="post"> <input type="text" name="gebruikersnaam" value="gebruikersnaam" maxlength="20" size="20"> <input type="password" name="wachtwoord" value="wachtwoord" maxlength="20" size="20"> <input type="password" name="herhaalwachtwoord" value="herhaalwachtwoord" maxlength="20" size="20"> <input type="text" name="email" value="voorbeeld@domeinnaam.extensie" maxlength="50" size="20"> <input type="submit" name="login" value="inloggen"> </form> </BODY> </HTML> <?php } ?> the problem is, is that i want to pass a variable between functions like $type (the database type) between connectdatabase(); and query(); in the 'aanmelden.php' file is an example of how i use the function (on line 3 and 45 the ones with //example comment) thanks for reading. please help. ps. config.php contains include("connect.php"); Ok, well basically i'm not sure if this can be done or not. Basically I have a IM type bar for my website similar to facebook. It's from CometChat.com. Anyway the place to edit the links to all the modules for the bar are done in the config.php file. What I'm trying to do is put a link for users to click to go directly to their profile on the site. To do this i get the user's ID, and reference it to the mysql database, get the nickname, pass it to a varaiable and plug the variable into the url in the config file. The problem I'm having is when I run ANY mysql commands in the config file it kills the CometChat script from showing at all on the site. I'm not sure why since the whole config file is in php... so i don't see how mysql statements would keep the script from showing. Another Idea I thought about was running the mysql statements in another php file and somehow get that variable from a php code in the config.php file.. but i'm not really sure what code will run the mysql file and return the variable i need. Any help is greatly appreciated. |