PHP - $_request Passed To Variable Not Working
i've been programming in PHP for years, and have done a substantial amount of work on applications of this nature. this problem has me stumped, not because i can't fix it (i did), but because i have no idea what the problem is. there are hundreds of lines of code involved here, so i'll break it down into a post-friendly format.
take this for example, and forgive any typos. it's late, and i've been beating my head against this for over two hours... =\ this is from my form: Code: [Select] /* ... numerous form fields being passed as $_REQUEST arrays */ <input type="hidden" name="option_id[]" value="<?php print $query_result->option_id; ?>" /> /* a couple hundred more lines */ here's the DB update handler: Code: [Select] if (!empty($_REQUEST['option_name'])) { foreach ($_REQUEST['option_name'] as $k => $v) { if ($v != '') { $option_id = $_REQUEST['option_id'][$k]; $option_name = $_REQUEST['option_name'][$k]; $option_price = $_REQUEST['option_price'][$k]; $option_desc = htmlentities($_REQUEST['option_desc'][$k], ENT_QUOTES); if (!$option_id = '') { $sql_options = "UPDATE table SET" . " option_name = '" . $option_name . "', option_price = '" . $option_price . "', option_desc = '" . $option_desc . "' WHERE option_id = '" . $option_id "'"; if (!$query_function($sql_options)) { $error = true; } } else { $sql_options = "INSERT INTO table (option_name, option_price, option_desc)" . " VALUES ('" . $option_name . "', '" . $option_price . "', '" . $option_desc . "')"; if (!$query_function($sql_options)) { $error = true; } } } } } the above code doesn't post to the database because the $option_id variable returns a null value. however, if i replace the $option_id variable where i build the query string with $_REQUEST['option_id'], it works just fine. Code: [Select] /* in relevant part */ $sql_options = "UPDATE table SET" . " option_name = '" . $option_name . "', option_price = '" . $option_price . "', option_desc = '" . $option_desc . "' WHERE option_id = '" . $_REQUEST['option_id'] . "'"; needless to say i was infuriated by having spent a couple of hours to come to this conclusion. i only used the variables in the first place because i need to expand the function that this lives inside and i don't want to have to type $_REQUESTs over and over. the only thing i can think is that it might be a type issue. the data is coming out of the mysql table from an INT field and being placed into the value for the hidden field straight from the row collection. would forcing a variant data type by not strongly typing my variable have caused this problem? i haven't tested the theory because i'm still too ticked off to open my code editor. i'm bouncing this off the community and posting my experience in the hope that it might help someone who comes after. Similar TutorialsHi How to get value of all $_Request variable so that we can validate for cross scripting. see below http://srijanlinux.com/consentRequestNew.php?requestId=24753 print count($_GET); // return ---------- 1 print_r($_GET); // return ----------- Array ( [requestId] => 24753 ) Now I want to validate value of requestId. I know I can validate by getting using $_GET['requestId']. But there are changes that I don't know variable name then How validate unknown variable which might be put by hacker. Thanks akash Hi: Can anyone tell me why the following is not working: Code: [Select] a_Photo_Delete.php <?php $photo_id = $_REQUEST['photo_id']; mysql_query("DELETE FROM gallery_photos WHERE photo_id = $photo_id"); header("Location: a_Photo_Edit.php"); ?> <!DOCTYPE HTML> <html> <head> <meta charset="ISO-8859-1" /> <title></title> </head> <body> </body> </html> ------------------------------ a_Photo_Edit.php <p> <?php if ($_REQUEST['URL'] == 'a_Photo_Delete.php') { echo "<span class=\"textError\">Photo successfully deleted!</span>"; } ?> </p> The photo gets deleted OK, and the HEADER goes to the "a_Photo_Edit.php" page properly, but the "Photo successfully deleted!" message does not show up .. Confused why .. ??
Hi All, I've been trying to access xml data from an API feed, but it needs a Variable to be passed to an include file without a form. the include is at the header of the page. in the code below, i'm trying to retrieve the variable $project_add from the $xml_2 feed. $proj_add_ID comes from another feed and is being passed ok. foreach ($projects_1 as $proj_1) { $job_no =$proj_1['job_no']; $job_name =$proj_1['job_name']; $job_status =$proj_1['job_status']; $job_staff =$proj_1['job_staff']; $job_due =$proj_1['job_due']; $clr_1 = $colors_1[$job_status]; if ($err_2) { echo "cURL Error #:" . $err_2; } else { $_POST['job_id']= $job_no; $xml_2=simplexml_load_string($response_2) or die("Error: Cannot create object"); $proj_add = $xml_2->xpath("CustomFields/CustomField[ID ='$proj_add_ID']"); foreach($proj_add as $item_2) { $project_add = "$item_2->Text"; } echo "<div class='row no-gutters'>"; echo "<div class='col-sm bg-white border rounded'><a href='managejob.php?job_id=$job_no' class='text-left ml-1'><strong>$job_no</strong></a></div>"; echo "<div class='col-sm-2 bg-white border rounded'><p class='text-left ml-1'>$job_name</p></div>"; echo "<div class='col-sm-2 bg-white border rounded'><p class='text-left ml-1'></p>$project_add</div>"; echo "<div class='col-sm-2 bg-white border rounded'>" . state_dropdown_1($job_no, $job_status, $clr_1) . "</div>"; echo "<div class='col-sm-2 bg-white border rounded'><p class='text-left ml-1'>$job_staff</p></div>"; echo "<div class='col-sm-2 bg-white border rounded'><form action='CALL_API_PUTTaskDate.php' method='POST'>" . "<input type='hidden' name='task_ID' value ='". $jdata['task_ID'] ."'>" . "<input type='hidden' name='est_min' value ='". $jdata['est_min'] ."'>" . "<input class ='form-control bg-white text-dark font-weight-bold' type='date' name='start_date' value='" . date('Y-m-d', strtotime( $jdata['display_date_1'] )) . "' onchange='this.form.submit()'>" . "</form></div>"; echo "<div class='col-sm bg-white border rounded'><p class='text-left ml-1 mt-1'><strong>" . date('d/m/Y', strtotime( $jdata['display_date'])) . "</strong></p></div></div>"; } The include file is like this / collect Custom Felds if ($_SERVER["REQUEST_METHOD"] == "POST") { // collect value of status input field $job_no = $_REQUEST['job_id']; } if (isset($_POST['job_id'])) { $job_no = $_POST['job_id']; } if (isset($_GET['job_id'])) { $job_no = $_GET['job_id']; } $curl_2 = curl_init(); curl_setopt_array($curl_2, array( CURLOPT_URL => "https://api.xxx.com/job.api/get/$job_no/customfield?apiKey=xxx&accountKey=xxx", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "Accept: */*", "Accept-Encoding: gzip, deflate", "Cache-Control: no-cache", "Connection: keep-alive", "Host: api.xxx.com", "Postman-Token: xxx", "User-Agent: PostmanRuntime/7.17.1", "cache-control: no-cache" ), )); $response_2 = curl_exec($curl_2); $err_2 = curl_error($curl_2); curl_close($curl_2); The problem is the variable $job_no isn't getting passed to CURLOPT_URL so it's not retrieving the data required. i need to be able to retrieve this data without submitting a form as it's in a foreach loop and the Id is specific to each iteration. is there a way to do this? I have been able to achieve this by putting the include within the div tags that it will be displayed but it just slows down everything too much and hangs. Any help will be much appreciated. Kind regards, Michael Bennington. I am trying to pass a php variable to javascript but it's not working. This is the "sketch" of my code. <?php $url="asset/go/"; ?>
<!DOCTYPE html> <html> <head> <title>Page Title</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> </head> <body> <script> var user="mayor"; var url ='<?php echo json_encode($url); ?>'; if(user=="mayor"){ alert(url); } </script> </body> </html> As it is now, it comes with the output below: <?php echo json_encode($url); ?> If I remove the quotation around the php in d jQuery, it throws an error in syntax. Also both codes are located in the same file named test.php Thanks in advance. Edited April 18 by Abel1416<?php global $places; $comm = $GLOBALS["location"]; $comm=trim($comm); while(list($one,$two) = each($places)) { echo "<option value=\"$two\""; if ( $two == $comm)echo "selected "; echo ">$two</option>\n" ; } ?> Variable passed to each() is not an array or objectHi, my code works fine but it is giving the error message Please can anyone help? Thanks I actually asked a question here yesterday and decided to try a different route with it. What I am doing is passing an email variable entered from my home page on to www.dollapal.com/offerlist.php. I'm wanting this page to be a complete list of all of my entries in my surveys table. The email variable needs to be appended to the end of every link. I got that to work, but what I want to do now is display that information for every record in my 'surveys' table. Right now I am using the random function, which I'm sure is wrong, but I'm not sure what function to be looking for. Is it possible to use a foreach function here to echo each record? If so, I'm not sure how exactly to call the foreach() function in this case. I believe my two problems lie in the random and foreach functions, but I'm not sure how to correct them. I've attached a little chunk of code that I'm working with. I'm not sure if I'm completely off base here, or if I'm close to achieving my desired result. Please let me know if you require more information. This forum has been amazing to me so far. Thank you all for your help! hello, please i need ur help!!!! when i enter this url in my browser:http://localhost:10080/ntop/dumpData.html?language=php&proto i get: $ntopHash = array( 'ff02::1:2' => array( 'index' => '0', 'hostNumIpAddress' => 'ff02::1:2', 'hostResolvedName' => 'ff02::1:2', 'firstSeen' => '1337008485', 'lastSeen' => '1337009340', 'minTTL' => '0', 'maxTTL' => '0', 'pktSent' => '0', 'pktRcvd' => '15', 'ipBytesSent' => '0', 'ipBytesRcvd' => '0', etc...... so i'm writing a script to extract these informations and put them in a new web interface in a table. my script is: Code: [Select] <HTML> <HEAD> <LINK REL=stylesheet HREF=http://localhost:3000/style.css type="text/css"> </HEAD> <BODY BGCOLOR=red> <?php $host="localhost"; $port=10080; $url="http://localhost:10080/ntop/dumpData.html?language=php&proto"; $fp = fsockopen ($host, $port); if (!$fp) { echo "$errstr ($errno)<br>\n"; } else { $outStr = ""; fputs($fp, "GET $url HTTP/1.1\r\nHost: $host\r\n\r\n"); while (!feof($fp)) { $out = fgets($fp,128); if($out == "\n") $begin = 1; else if($begin = 1) $outStr = $out; } fclose ($fp); #echo "<pre>$outStr</pre>"; eval($outStr); } echo "<center>\n<table border>\n"; echo "<tr><th BGCOLOR=white>Sessions</th><th BGCOLOR=white>Values</th></tr>\n"; while (list ($key, $val) = each($ntopHash)) { echo "<tr><th align=center BGCOLOR=white>$key</th>\n"; echo "<td><table border>\n"; while (list ($key_1, $val_1) = each ($val)) if(gettype($val_1) == "array") { echo "<tr><th align=left>$key_1</th><td><table border>\n"; while (list ($key_2, $val_2) = each ($val_1)) { echo "<tr><th align=left>$key_2</th><td align=right> $val_2</td></tr>\n"; } echo "</table></td></tr>\n"; } else if($val_1 != "0") { if($key_1 == "sessionState") { if($val_1 == 0) $val2 = "SYN"; else if($val_1 == 1) $val2 = "SYN_ACK"; else if($val_1 == 2) $val2 = "ACTIVE"; else if($val_1 == 3) $val2 = "FIN1_ACK0"; else if($val_1 == 4) $val2 = "FIN1_ACK1"; else if($val_1 == 5) $val2 = "FIN2_ACK0"; else if($val_1 == 6) $val2 = "FIN2_ACK1"; else if($val_1 == 7) $val2 = "FIN2_ACK2"; else if($val_1 == $val2 = "TIMEOUT"; else if($val_1 == 9) $val2 = "END"; echo "<tr><th align=left>$key_1</th><td align=right> $val2</td></tr>\n"; } else echo "<tr><th align=left>$key_1</th><td align=right> $val_1</td></tr>\n"; } echo "</table></td></tr>\n"; } echo "</table>\n"; // echo "<pre>$outStr<pre>"; ?> </center> </body> </html> and i'm having this error: Sessions Values Warning: Variable passed to each() is not an array or object in C:\xampp\htdocs\projet\sessions.php on line 33 please i need your helpppp i get this error Warning: current() [function.current]: Passed variable is not an array or object.. for this Code: [Select] $lastblock = current( ${"s".$row} ); print_r($lastblock); when i change to this it works.. Code: [Select] $lastblock = current( $s0 ); print_r($lastblock); The problem is i won't know the $row seeing as it is in a while loop. Solution? Hi I am trying to send a company name to a form for users to report errors. Code: [Select] echo "<a href=\"http://www.example.com/suppliers.php?companyName=$compName\">$compName</a>"; In the form, I have the usual code which I use to fill in the value of a field... $companyName = $_REQUEST['companyName']; This works fine - except if there is an ampersand in the name. A & B Products...., becomes just A I have tried htmlentitles to convert to & but the problem still exists. Any thoughts on how I could correct this? Thanks Any ideas on how to make this code usable without using the $_REQUEST superglobal? Here is my code: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> <?php if($_GET['submit'] == "Change Background Color") { $bgcolor = strval($_POST['thecolor']); } else { $bgcolor = "red"; } ?> <body bgcolor="<?= $bgcolor; ?>"> <form name="color" method="get" action="<?= $_SERVER['PHP_SELF']; ?>"> Enter a color: <input type="text" name="thecolor" value=""> <input type ="submit" value="Change Background Color"> </form> Hello everyone, I can get Test 2 to successfully operate the if statement using a variable variable. But when I try the same method using a session variable (Test 1) the if statement is not executed. Please could you tell me why the if statement in Test 1 is not being executed? Code: [Select] <?php # TEST 1 $_SESSION[test_variable] = "abcd"; $session_variable_name = "_SESSION[test_variable]"; if ($$session_variable_name == "abcd") { echo "<br>line 373, abcd<br>"; } # TEST 2 $test_variable = "efgh"; $test_variable_name = "test_variable"; if ($$test_variable_name == "efgh") { echo "<br>line 379, efgh<br>"; } ?> Many thanks, Stu I have a script that adds points together based upon the placing. This is the actual script: Code: [Select] <? $points = 0; if($place === '1st') {$points = $points + 50;} elseif($place === '2nd') {$points = $points + 45;} elseif($place === '3rd') {$points = $points + 40;} elseif($place === '4th') {$points = $points + 35;} elseif($place === '5th') {$points = $points + 30;} elseif($place === '6th') {$points = $points + 25;} elseif($place === '7th') {$points = $points + 20;} elseif($place === '8th') {$points = $points + 10;} elseif($place === '9th') {$points = $points + 10;} elseif($place === '10th') {$points = $points + 10;} elseif($place === 'CH') {$points = $points + 50;} elseif($place === 'RCH') {$points = $points + 40;} elseif($place === 'TT') {$points = $points + 30;} elseif($place === 'T5') {$points = $points + 30;} elseif($place === 'Champion') {$points = $points + 50;} elseif($place === 'Reserve Champion') {$points = $points + 40;} echo "Total HF Points: $points"; ?>What it *should* do (my friend's script works the same way and it works) it starts at points = 0, than if there is a first place, it adds 50, and so forth until it reaches the end. It is included into a file, in this area: Code: [Select] <div class="tabbertab"> <h2>Records</h2> <? $query92 = "SELECT * FROM THISTABLE WHERE VARIABLE='$id' OR VARIABLE = '$name' ORDER BY ABS(VARIABLE), VARIABLE"; $result92 = mysql_query($query92) or die (mysql_error()); echo "<table class='record'> <tr><th>Show</th> <th>Class</th> <th>Place</th></tr> "; while($row92 = mysql_fetch_array($result92)) { $class = $row92['class']; $place = $row92['place']; $entries = $row92['entries']; $race = $row92['show']; $purse = number_format($row92['purse'],2); echo "<tr><td>$race</td> <td>$class</td> <td>$place</td></tr>"; } ?> <tr><td colspan='3'><div align='right'><? include('includes/points.php'); ?></div></td></tr> </table> </div> This is the code that is relevant. When ended here, it echoes the last place that appears in the results (such as a 5th place echoing 30 points). When I move it to be included in the while loop, it shows Total Points: 50 Total Points: 25 Total Points: 10 (depending on the results displayed on that page). What am I doing wrong? I like to use $_REQUEST to get something from either $_POST or $_GET. Annoying though, it also includes values from cookie, like the PHP session id, FCK editor cookies and the google tracking code. Is there anyway to remove cookie values from request, besides looping through cookie and unsetting the values I don't want? So I have an existing picklist that i am trying to tweak - I am making it into a multiselect and trying to return multiple values
I have been able to accomplish the first part by adding select 'multiple' but when i submit it only returns results for the last value selected.
Here is the code for the form (Left out the picklists that do not need to be multiple select)
<td align="center" valign="top"> <? // base64_encode(base64_encode( 'test1'))?> <br /> <br /> <form id='report_form' action="driverreport_sd.php" method="post" name="report_form"> <!--<div class="criteria_div">--> <table align="center" class="table_border" cellpadding="5" cellspacing="0" width="80%"> <tr> <td align="right" class="first_td"> Status: </td> <td align="left"> <select multiple name='Status' id='Status'> <? $statuslist=$ObjReport->ObjStatus->get_Status_List(); while($status=mysql_fetch_object($statuslist)) { if($status->Status=="Please Select") { ?> <option value="<?=$status->Status?>" <?=($status->Status==$_REQUEST['Status']?"selected=selected":"")?>> <?=$status->Status?></option> <? } else { ?> <option value="<?=$status->Status?>" <?=($status->Status==$_REQUEST['Status']?"selected=selected":"")?>> <?=$status->Status?></option> <? } } ?> </select> </td> </tr> <td align="center" colspan="2"> <input type="hidden" id='sort_by' name='sort_by' value="<?=$_REQUEST['sort_by']?>" /> <input type="hidden" name='search_val' id='search_val' value="<?=$_REQUEST['search_val']?>" /> <input type="hidden" name='search_by' id='search_by' value="<?=$_REQUEST['search_by']?>" /> <input type="hidden" name="report_submited" value='report_submited' /> <button type="submit" id="report_submited" name="" value='submit'>Submit</button> </td> and here is the return request <? if($_REQUEST['report_submited']) { $ReportData=$ObjReport->generate_report($_REQUEST['Status'],$_REQUEST['School'],$_REQUEST['Campaign'],$_REQUEST['State'],$_REQUEST['Stdtype'],$_REQUEST['Primbad'],$_REQUEST['Rep'],$_REQUEST['From_Date'],$_REQUEST['To_Date'],$_REQUEST['sort_by'],$_REQUEST['search_by'],$_REQUEST['search_val']); $currentTotalRow=mysql_num_rows($ReportData); if($currentTotalRow>0) { ?> Any suggestions would be appreciated Thanks! Hi guys, I have a problem with the code on below. When I input the value into $name and $email method, the page come into blank page. <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $name = clean($_GET['name']); $email = clean($_GET['email']); $comments = clean($_GET['comments']); $type = clean($_GET['type']); if($name == '') { $errmsg_arr[] = 'name or member ID missing'; $errflag = true; } if($email == '') { $errmsg_arr[] = 'email address ID missing'; $errflag = true; } else { } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $insert = array(); if(isset($_GET['name'])) { $insert[] = 'name = \'' . clean($_GET['name']) .'\''; // echo "tested"; } if(isset($_GET['email'])) { $insert[] = 'email = \'' . clean($_GET['email']) . '\''; } if(isset($_GET['type'])) { $insert[] = 'type = \'' . clean($_GET['type']) . '\''; } if(isset($_GET['comments'])) { $insert[] = 'comments = \'' . clean($_GET['comments']) . '\''; } if (count($insert)>0) { $names = implode(',',$insert); if(isset($name)) { $name = $_GET['name']; $headers = "From: "-f .$name."@myemail.com"; $to = "myname@mymail.com"; $subject = $type; $message = $comments . '; $header .= "MIME-Version: 1.0\l\n"; $add = "-f". $name ."@myemail.com"; mail($to, $subject, $message, $header, $add); echo "Thank you for sent us your feedback"; } else { if(isset($email)) { $email = $_GET['email']; $headers = "From: "$email"; $to = "myname@mymail.com"; $subject = $type; $message = $comments . '; $header .= "MIME-Version: 1.0\l\n"; $add = "-f". $email ."; mail($to, $subject, $message, $headers, $add); } echo "Thank you for sent us your email"; } } } ?> There must be the problem coming from this: if(isset($name)) { $name = $_GET['name']; $headers = "From: "-f .$name."@myemail.com"; $to = "myname@mymail.com"; $subject = $type; $message = $comments . '; $header .= "MIME-Version: 1.0\l\n"; $add = "-f". $name ."@myemail.com"; mail($to, $subject, $message, $header, $add); echo "Thank you for sent us your feedback"; } else { if(isset($email)) { $email = $_GET['email']; $headers = "From: "$email"; $to = "myname@mymail.com"; $subject = $type; $message = $comments . '; $header .= "MIME-Version: 1.0\l\n"; $add = "-f". $email ."; mail($to, $subject, $message, $headers, $add); } I am not sure where the problem is, so please could you help me?? Hi, I have a variable named $siteName stored in the server.php file in the data directory data/server.php Now in the header.php page I want to retrieve the $siteName variable so it can be used in the header information. This is what I have but it isnt working. server.php Code: [Select] <?php $siteName = 'My+Test+Site'; ?><?php $adminEmail = 'pwithers2009@hotmail.co.uk'; ?><?php $sendmailLoc = '/usr/sbin/sendmail'; ?><?php $imgdir = 'http://www.tropicsbay.co.uk/images/'; ?><?php $imgdirbase = '/home/tropicsb/public_html/images/'; ?> header.php Code: [Select] <?php include("data/server.php"); $siteName = $_GET['siteName']; echo ' <!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=iso-8859-1" /> <title>$siteName Admin Panel</title> <link rel="stylesheet" href="admin.css" type="text/css" /> </head> <div id="pagehead"> <div id="navigation"> <img alt="" src="images/leftNav.gif" height="32" width="4" id="leftNav" /> <img alt="" src="images/rightNav.gif" height="32" width="4" id="rightNav" /> <div id="globalLink"> <a href="admin.php?cmd=manage&username=admin&password=$adminpw" id="gl1" class="glink" onmouseover="ehandler(event,menuitem1);">Users</a><a href="admin.php?cmd=editTemplate&username=admin&password=$adminpw" id="gl2" class="glink" onmouseover="ehandler(event,menuitem2);">Templates</a><a href="admin.php?cmd=mysqlBackup&username=admin&password=$adminpw" id="gl3" class="glink" onmouseover="ehandler(event,menuitem3);">Database</a><a href="admin.php?cmd=paymentLog&username=admin&password=$adminpw" id="gl4" class="glink" onmouseover="ehandler(event,menuitem4);">Payment</a><a href="admin.php?cmd=profileFields&username=admin&password=$adminpw" id="gl5" class="glink" onmouseover="ehandler(event,menuitem5);">Setup</a><a href="admin.php?cmd=changeAdminpw&username=admin&password=$adminpw" id="gl6" class="glink" onmouseover="ehandler(event,menuitem6);">Preferences</a><a href="admin.php?cmd=logout&username=admin&password=$adminpw" id="gl7" class="glink" onmouseover="ehandler(event,menuitem6);">Logout</a></div> </div></div> <div id="pagelayout"> <img alt="" src="images/leftCurve.gif" height="6" width="6" id="left" /> <img alt="" src="images/rightCurve.gif" height="6" width="6" id="right" /> <div id="pageName"> <h2>$siteName Admin Panel<h2> </div>'; ?> Any ideas on how to do this, it seems to work ok in one of my other scripts. Thanks I've been baffled by this for 2 days now and cannot figure it out after exhaustive searches. I'd like to think I'm doing this correctly, but cannot get it to work.
I'm trying to use a variable within a query WHERE statement, and it shows 0 results. If I directly hardcode the text instead of using the variable, it works. The variable is pulling from a $_GET, and if I echo that variable, it is showing the correct text.
Here's my code:
$Domain = $_GET['Domain']; $result = mysql_query(SELECT Code, Title, Domain, Status FROM tablename WHERE Domain="$Domain" ORDER BY Code');If I swap out "$Domain" for direct text, like "ABC", it works. I have tried swapping out the quotes and single quotes throughout the statement, removing the quotes around $Domain, concatenating the statement separately....all yield erros or the same result. And as stated, if I echo $Domain, it shows "ABC" (or whatever it's supposed to show), so i know it's pulling correctly from the $_GET. Anyone know what I'm doing wrong? Hello Everyone, I am new to forum and could use some help with some php code that isn't working. I am very new to php/html/javascript and all of what I have learned, I learned from forums like this one so first....thank you! I am trying to assign a value from a php variable to the value of my form element. I'm sure there must be a way to do this but I can't seem to get the syntax right. here is my code... first I set the value of $loginname elsewhere in the script like so... <?php $loginname =strtolower(htmlspecialchars(strip_tags($_GET["loginname"]))); ?> This part works fine.. Then I try to set the value of my hidden text field inside the form to the value of $loginname to be passed to a javascript program. Everything works except that the value passed ends up being <?echo and not the expected user name inside of $loginname. <?php echo '<form name ="currentactivity" Id="currentactivity" action="<?php'.htmlspecialchars($_SERVER['PHP_SELF']).'?>" method="post">'; echo '<fieldset><legend><b>Your Current Activity Information</b></legend>'; echo '<input type="text" name="loginnm" style="visibility: hidden" value="<?php echo $loginname;?>">'; echo "<label for='myactivities'>Activity Name:</label>"; echo "<select name='myactivities' Id='myactivities' onchange=\"showdetails(this.form)\" value=''>"; echo "<option value = 'Select an activity'>Select an activity</option>"; for ($i = 1; $i <=$rowcount; $i++) { echo"<option value=$row[activity_name]>$row[activity_name] </option>"; $row = mysql_fetch_array($result); } echo "</select>"; echo '</fieldset>'; echo '</form>'; ?> Please note..the rest of the code is working perfectly, it is just this one value I can't seem to get. Any help you can give will be greatly appreciated. hi guys. i am trying to set a variable to the session global variable. I've initialized the session with session_start(); at the very beginning of my website, and then i try finding if a session variable has been set like so if(isset($_SESSION['user'])) { print 'user is logged in'; } but this works in reverse. i have not set any session variables, but asking if it is set, results in an affirmative answer. so i am thinking this is because of register_globals. because i went to read about register_globals, and it says that if register_globals is turned off, i cannot use any other varibale except members of the session array. i dont know what that is yet, but a question befo in the php manual it says register_globals is deprecated, and it appears i need to enable it to set other variables as session variables besides it's associative array. if this is true, how to enable register_globals and allow other variables to be used as session variables? |