PHP - Losing Variable
I am not sure If I am loosing my variable or if it is just getting cancelled out by the syntax.
The error I get is this: Query string: "SELECT * FROM timeslip WHERE 1 and Initials=" ORDER BY "Date" ASC, "Cost" ASC Failed with error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"SELECT * FROM timeslip WHERE 1 and Initials=" ORDER BY "Date" ASC, "Cost" ASC' at line 1 Initials should have the value of GEC at this moment Here is my code: $qry_str="SELECT * FROM timeslip WHERE 1 "; if($_POST['Initials']) { $Initials=$_POST['Initials']; $qry_str.='and Initials="'.$Initials . '"'; } if($_POST['Identifier']) { $Identifier=$_POST['Identifier']; $qry_str.='and Identifier LIKE "%'.$Identifier . '%"'; } if($_POST['Type']) { $Type=$_POST['Type']; $qry_str.='and Type LIKE "%'.$Type . '%"'; } if($_POST['Terms']) { $Terms=$_POST['Terms']; $qry_str.='and Terms LIKE "%'.$Terms . '%"'; } if($_POST['Memo']) { $Memo=$_POST['Memo']; $qry_str.='and Memo LIKE "%'.$Memo . '%"'; } if($_POST['date1']) { $date1=$_POST['date1']; $date2=$_POST['date2']; $start=date('Y-m-d', strtotime($date1)); $end=date('Y-m-d', strtotime($date2)); $qry_str.="and Date >= $start and Date <= $end "; } if($_POST['order1'] && $_POST['order2']) { $order1=$_POST['order1']; $order2=$_POST['order2']; $qry=$_POST['qry']; $qry_str=' "'.$qry.'" ORDER BY "'.$order1 . '" ASC, "'.$order2 . '" ASC '; } elseif(isset($_POST['order1'])) { $order1=$_POST['order1']; $qry=$_POST['qry']; $qry_str='$qry ORDER BY $order1 ASC'; } else { if(isset($_POST['order2'])) { $order2=$_POST['order1']; $qry=$_POST['qry']; $qry_str='$qry ORDER BY $order2 ASC'; } } if( !$result = mysql_query($qry_str) ) { echo "<br>Query string: $qry_str<br>Failed with error: " . mysql_error() . '<br>'; } Similar TutorialsI am trying to retain information from the $get variable after checking if a user, (Joomla code), is logged in but it is not working. (url: http://domain.com/script.php?file=data) define( '_JEXEC', 1 ); define( 'DS', DIRECTORY_SEPARATOR ); define('JPATH_BASE', '/path/to/joomla/dir/'); require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); $mainframe =& JFactory::getApplication('site'); $mainframe->initialise(); $session =& JFactory::getSession(); $user =& JFactory::getUser(); // get username and name of user $username = $user->get('username'); $name = $user->get('name'); if (empty($username)) { die('Not logged in'); } $file = $_GET['file']; echo &file; exit; Any help appreciated. Hey there, Pretty frustrated with this. It seems so simple, but I've been staring at it and toying with it for ages, so I figured I'd post here. I have a variable called "$isTaken" that seems to be losing its value in an essential step in my function. Take a look. function subdomainTaken($inputtedSubdomain) { //Initialize $isTaken to 'true' $isTaken = true; echo "isTaken STARTS AS: <i>" . $isTaken . "</i><br />"; //FOR TESTING PURPOSES ONLY. VARIABLE HAS VALUE HERE //Check subdomain in database $subdomainDBQuery = mysql_query("SELECT * FROM `companies` WHERE company_subdomain = '$inputtedSubdomain'"); $foundResult = mysql_num_rows($subdomainDBQuery); if ($foundResult > 0) { $isTaken = true; } else { $isTaken = false; } return $isTaken; } By the time I get to the if statement, $isTaken has no value. I've echoed it to be sure. Any ideas? Thanks, Frank I'm having an issue with holding a session variable in the statement below $Color is losing its value in the if statement. For example int the ( ) $Color is a zero while in the echo part $Color is being displayed correctly as Blue. I'd describe myself as a "basic" php programmer....
I'm trying to build my first multi-page forms.
The first page is calculator_q1.php
No session variables are needed here, I have omitted a few options, the code looks like this
<form id="page1" method="post" action="calculator_q2.php"> <h1>1. Which best describes the primary and secondary sports combination that will be played on your pitch?</h1> <table> <tr><td>Rugby only</td><td><input type="radio" name="1_primary_secondary_combo" value="Rugby only"></td></tr> <tr><td>Rugby/Soccer</td><td><input type="radio" name="1_primary_secondary_combo" value="Rugby Soccer"></td></tr> <tr><td>Soccer/Hockey</td><td><input type="radio" name="1_primary_secondary_combo" value="Soccer Hockey"></td></tr> </table> <input class="blue" type="submit" value="Next"> </form>The 2nd page is calculator_q2.php. This has some php to start the session, copy the result of form 1 to a session var, I do a debug echo and the variable is printed correctly so I think have captured it correctly. In extract, I do this: <?php //Start the session session_start(); //Store our posted values in the session variables $_SESSION['1_primary_secondary_combo'] = $_POST['1_primary_secondary_combo']; ?> <?php $debug=True; if ($debug) { echo ("Debug: session for q1 = ".$_SESSION['1_primary_secondary_combo']); } ?> <form id="page2" method="post" action="calculator_q3.php"> <h1>2. Please choose a preferred surface</h1> <table> <tr><td>3G Rubber Crumb Filled Turf</td><td><input type="radio" name="2_preferred_surface" value="3G Rubber Crumb Filled Turf "></td></tr> <tr><td>Sand Filled Turf</td><td><input type="radio" name="2_preferred_surface" value="Sand Filled Turf"></td></tr> <tr><td>Sand Dressed Turf or<br>a Water Based Surface</td><td><input type="radio" name="2_preferred_surface" value="Sand Dressed Turf or a Water Based Surface"></td></tr> </table> <p> <script> function submitForm(action){ document.getElementById('page2').action = action; document.getElementById('page2').submit(); } </script> <input class="blue" type="button" onclick="submitForm('/calculator_q1.php')" value="Previous" /> <input class="blue" type="button" onclick="submitForm('/calculator_q3.php')" value="Next" /> </form>So far so good, but when I introduce page 3 (calculator_q3.php) then it prints the previous page's (from page 2) variable but can't find the session variable from question 1. This is from calculator_q3.php: <?php //Start the session session_start(); //Store our posted values in the session variables $_SESSION['2_preferred_surface'] = $_POST['2_preferred_surface']; ?> <?php $debug=True; if ($debug) { echo ("Debug: session for q1 = ".$_SESSION['1_primary_secondary_combo']); echo ("<br>Debug: session for q2 = ".$_SESSION['2_preferred_surface']); } ?> <form id="page3" method="post" action="calculator_q4.php"> <h1>3. Please choose one watering option</h1> <table> <tr><td>With a Rain Gun System</td><td><input type="radio" name="3_watering_option" value="With a Rain Gun System"></td></tr> <tr><td>With a Rain gun System + Water Borehole</td><td><input type="radio" name="3_watering_option" value="With a Rain gun System + Water Borehole"></td></tr> <tr><td>Not Required</td><td><input type="radio" name="3_watering_option" value="Not Required"></td></tr> </table> <p> <script> function submitForm(action){ document.getElementById('page3').action = action; document.getElementById('page3').submit(); } </script> <input class="blue" type="button" onclick="submitForm('/calculator_q2.php')" value="Previous" /> <input class="blue" type="button" onclick="submitForm('/calculator_q4.php')" value="Next" /> </form>To see this in action see: http://www.sports.ha...lculator_q1.php Any insights would be appreciated. Many thanks. This is what I have $eeee = $_POST['forum_reply']; $eeee = strip_tags($eeee, '<p>'); echo $eeee; this is what prints out Quote Untitled document testinggg this is a print_r of $_Post Quote Array ( [forum_reply] => testinggg [form_reply_submit] => Reply ) Please someone tell me what in binary's name is going on! I seem to be losing my array value when it comes to the "Game Time" section of my script. I am printing out the array a long the entire time and this is where I lose it and can't figure out why. <form name="form1" method="post" action=""> <span class="whitetitle">How many teams?</span> <ul class="pageitem"> <li> <SELECT name="teams" onchange="document.form1.submit();"> <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="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> </SELECT> </li> </ul> </form> <? if($_POST['teams']) { ?> <form method="post" name="form2" action=""> <span class="whitetitle">Team Name</span> <?php $teams=$_POST['teams']; $count=0; while($count<$teams) { ?> <ul class="pageitem"> <li class="bigfield"> <input placeholder="Name" type="text" name="teamname[]"/> </li> </ul> <? $count++; } ?> <input type="hidden" value="<?=$teams?>" name="teams" /> <input type="submit" name="Submit" value="Next"> </form> <? } ?> <? if ($_POST['teamname']) { $teams=$_POST['teams']; $teamname=$_POST['teamname']; ?> <form name="form" method="post" action=""> <span class="name"><? print_r ($_POST['teamname']);?></span> <ul class="pageitem"> <li class="radiobutton"><span class="name">Season</span> <input name="schedule" type="radio" value="season" onClick="this.form.action='';this.form.submit()" /></li> <li class="radiobutton"><span class="name">Playoffs</span> <input name="schedule" type="radio" value="playoffs" onClick="this.form.action='';this.form.submit()"/></li> </ul> <input type="hidden" value="<?=$teams?>" name="teams" /> <input type="hidden" value="<?=$teamname?>" name="teamname" /> </form> <? } if($_POST['schedule']) { $teams=$_POST['teams']; $schedule=$_POST['schedule']; $teamname=$_POST['teamname']; ?> <form name="form4" method="post" action=""> <span class="name"><? print_r ($_POST['teamname']);?></span> <span class="whitetitle">Games per Night</span> <ul class="pageitem"> <li> <SELECT name="games" onchange="document.form4.submit();"> <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="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> </SELECT> </li> </ul> <input type="hidden" value="<?=$teamname?>" name="teamname" /> <input type="hidden" value="<?=$teams?>" name="teams" /> <input type="hidden" value="<?=$schedule?>" name="schedule" /> </form> <? } if($_POST['games']) { $teams=$_POST['teams']; $schedule=$_POST['schedule']; $games=$_POST['games']; $teamname=$_POST['teamname']; $count=0; ?> <form name="form5" method="post" action=""> <span class="name"><? print_r ($_POST['teamname']);?></span> <span class="whitetitle">Times</span> <ul class="pageitem"> <? while($count<$games) { ?> <li> <input placeholder="Times" type="text" name="times[]"/> </li> <? $count++; } ?> </ul> <input type="hidden" value="<?=$teamname?>" name="teamname" /> <input type="hidden" value="<?=$teams?>" name="teams" /> <input type="hidden" value="<?=$schedule?>" name="schedule" /> <input type="hidden" value="<?=$games?>" name="games" /> <input type="submit" name="Submit" value="Next"> </form> <? } if($_POST['times']) { echo $_POST['teams']; print_r ($_POST['teamname']); echo $_POST['schedule']; echo $_POST['games']; echo implode(",",$_POST['times']); } ?> Alright I know scraping is frowned upon.. but its for a client... Anyways.. The below is supposed to form an array $kw for output. But its breaking on line 27: Code: [Select] foreach ($kw as $keyword => $pages) Ive concluded my array is being broken and then formed into an empty string, but I can't figure out where it wen't wrong. I want to say the trouble comes from lines 20-23: Code: [Select] foreach($data as $temp) { $kx = text_between('"','"',$temp); if (is_array($kx)) $kw[key($kx)] = current($kx); } The full version.. Code: [Select] <?php function text_between($start,$end,$string) { $keyword = ''; if ($start != '') {$temp = explode($start,$string,2);} else {$temp = array('',$string);} $temp = @explode($end,$temp[1],2); $temp2 = @explode($end,$temp[1],3); $pages = (int)@str_replace(',','',$temp2[1]); if ($pages) $keyword[$temp[0]] = $pages; return $keyword; } function gsscrape($keyword) { $keyword=str_replace(" ","+",$keyword); $keyword=str_replace("%20","+",$keyword); global $kw; $data=file_get_contents('http://clients1.google.com/complete/search?hl=en&gl=us&q='.$keyword); $data=explode('[',$data,3); $data=explode('],[',$data[2]); foreach($data as $temp) { $kx = text_between('"','"',$temp); if (is_array($kx)) $kw[key($kx)] = current($kx); } } #simple to use, just use yourscriptname.php?keywords echo $_SERVER['QUERY_STRING']; if ($_SERVER['QUERY_STRING']!='') { gsscrape($_SERVER['QUERY_STRING']); foreach ($kw as $keyword => $pages) { gsscrape($keyword); } } #all results are in array $kw... echo "<pre>"; print_r($kw); echo "</pre>"; ?> Hi everyone - I am trying to figure out how I can allow my logged in users to leave a php page and go to an html page without losing them as "currently logged in" - I have a site that is mixed with html and php pages and this is what I am needing: i have a user, they are logged in and are visiting a php page. then they want to go to another page(only logged in users can access the php page) - so they click on the html page they want to go to, great! - but then they want to visit another page that is a php page and requires them to be logged in in order to access it. How can i accomplish this without having them log in yet again? is this possible? i am using sessions. Afternoon, Not sure if i've been staring at the screen for too long or not, but have a log in script which saves the password as a session variable and I can pass that variable across my page like so: <?php session_start(); //Print_r ($_SESSION); echo "Erm, I have reached page.php and the password is ".$_SESSION['password']; ?> However, I want to make this secure, so I added a function to it which when you log in says if $_SESSION['password'] does not exist then send me away, like so: <?php session_start(); function checklogin() { session_start(); if(!isset($_SESSION['password'])) { header("location: /index/"); exit; } } checkLogin(); Print_r ($_SESSION); echo "Erm, I have reached page.php and the password is ".$_SESSION['password']; ?> However, using the function and a valid log-in it (as shown above) it chucks me out of the page even though $_SESSION['password'] exists? Am I doing something really stupid here? Thank you Alright, I've spent over a week trying to fix this now - And Im getting frustrated! I asked at other forums, I asked co-workers and I asked friends-of-friends, and nobody can explain what happens. Let's take a look at this first: $name = mysql_real_escape_string($_POST['name']); mysql_query(sprintf("UPDATE em_users SET name='%s' WHERE id='" . $in_user['id'] . "'", $name)); This will insert NO data on the Name field in the database. Obviously, I thought the $_POST variable wasn't passed correctly, but echo'ing it just before the query WILL show data. And as I said, I tried everything possible for the last week. Switching variables, adding static text on the $name variable instead of using the $_POST content (this does work). I used very very simple test data on the form, such as my name "Mark" or "test" and "hey". The query is correctly executed everytime. The truely WEIRD thing is, if I ensure there is content in $name before executing the query it will work as expected everytime. Like this: $name = mysql_real_escape_string($_POST['name']); $name && mysql_query(sprintf("UPDATE em_users SET name='%s' WHERE id='" . $in_user['id'] . "'", $name)); Of course I could do this, but I want to know why my code does or doesn't work + it's a lot of work to do for something that worked fine a week ago. It has spread to a lot of forms on my website that $_POST variables aren't processed correctly - and it happened out of nowhere. Even on codes that havnt changed in months. I really need help on fixing this! This project has been in development for nearly two years, and without a fix it's pretty much lost I am working with a fellow who runs an eCommerce shop. The transaction resolution comes in on a querystring.
I do not yet know what web server software is being used, nor if any security appliance/software is installed.
One of the values in the querystring starts with the @ character.
We know the web server gets this as there entries in the web server's access log that shows thing value is present.
It is not available in PHP's $_GET array.
We are trying to get an idea of where this value, and it's key, is getting discarded.
Is there a known problem with (actual server software being used not yet known) web server software discarding a key/value if the value has the @ character in the querystring?
So maybe this is normal, or maybe there is a "better way." The only simple solution appears to be to always save $_POST data to $_SESSION["post"] on the off-chance some visitor some day ever decides to do a $_GET request from a referral link.
3 weeks of my life has been lost to correcting the neverending 'illegal string offset' and 'undefined index' errors etc. by making sure every last variable is declared... Anyway, blah blah blah, that's my rant. Is there a better way? Or is this "how everybody does it?" It seems stupid to have to do all of this.
I recently had a customer say that one of my forms isn't working. For some reason the ID number is getting lost when she submits the form. The form code looks like: ... print "<form method='post' name='form' action='update.php'>"; ... print "<input type='hidden' name='id' value=\"$id\" />"; print "<input type='submit' name='submit' value=\"Save Session\" />"; print "</form>"; ... And the PHP code that gets executed looks like: ... //GET SESSION ID if(isset($_GET['id'])) { //ID from HTML link, before updates have been made $id = $_GET['id']; } elseif(isset($_POST['id'])) { //ID from form, after updates have been made $id = $_POST['id']; } else { $id = ''; } //IF SESSION ID IS VALID if(preg_match("/^\d+$/", $id)) { ... //ELSE, INVALID ID } else { $msg = "<span class='errorText'>Session ID not found or invalid.</span>"; } ... For some reason she usually gets the "Session ID not found..." error when submitting the form. Do you see any problems with the above code? Note that she has been able to sucessfully use the form before (in the same day); we have nearly 1,800 records submitted using these forms; and I am unable to duplicate the issue. So I'm at a loss on what to do next. Also, she talked with her IT person about the form. The IT person was able to submit data on his computer. So he reset her Internet options which seemed to fix the problem on her end temporarily. Note that she is using IE 7. She also said that she doesn't have access to any other browsers. I'm tempted to chalk this up as a personal computer issue, but wanted to get your input first. I have the following code, works rotates the image. But it seems to lose its transparency and add color when rotated to say 45. How can I avoid this? // File and rotation $filename = 'placeholder.png'; $degrees = 45; // Content type header('Content-type: image/png'); // Load $source = imagecreatefrompng($filename); // Rotate $rotate = imagerotate($source, $degrees, 0); // Output imagepng($rotate); ?> Hello, I am creating a simple catalog feature on my website for logging collections in a list format. Using built in pagination (cakephp) on my list to sort by name, I lose my images after the sort. Any ideas how to get around this? Here is the code. View: Code: [Select] <td><div align='center'> <?php echo $this->Html->toggleBoolean($nintendo['Nintendo']['box']); ?> </div></td> Helper: Code: [Select] function toggleBoolean($value){ if ($value == 1) return "<img src='../img/fam/tick.png' alt='Yes' />"; else return "<img src='../img/fam/cross.png' alt='No' />"; } Regards, Ash Hello,
I have a secure login script that uses sessions to maintain a users logged in status. I regenerate the session ID on each page reload for added security. Sometimes, I will lose sessions, and I am hard time figuring out why. It seems to be when I have a slow internet connection. I am wondering what could be causing this?? I have a few ideas, do any of these seem plausible.
-A max execution error, returns a fatal error.
-An ajax request get sent before the previous request returns, so the session ID's dont match an I am kicked out.
Any other ideas would be helpful.
Best,
James
Hey all, I am having a situation where I have a singleton class with a static array in it. I insert an element into that array, and then I redirect the user to another page. At that page, I then retrieve that array (it's stored in the session vars), but the array is then empty when I retrieve it. I can't figure out why. Here are some pertinent code snippets. First, the class with the static array: class Logger { private static $instance = NULL; private static $messages = array(); //Private constructor to prevent this class from being instantiated multiple times private function __construct() { } //The clone function is private to prevent cloning of this class private function __clone() { } //Returns the singleton instance of this class public static function GetInstance() { if (!self::$instance) { self::$instance = new Logger; } return self::$instance; } public static function GetMessageCount() { return count(self::$messages); } public static function LogMessage($new_message) { self::$messages[] = $new_message; } public static function GetMessages() { return self::$messages; } public static function ClearMessages() { self::$messages = array(); } } Here is the code where I insert something into the aformentioned array (the process is that a user tries to log in, but the login fails, and so we insert a message into the array saying that the login credentials failed). //Retrieve the message logging instance from the session data to be able to pass messages to the user. $message_log = $_SESSION['user_messages']; $user = $_SESSION['user_account']; //Create a new instance of the database management class and //try to connect to the database $dbm = new DBM(); if ( !$dbm->isConnected() ) { $message_log::LogMessage("We are sorry, but we are unable to access the database at this time. Please try again later."); } else { //Retrieve the user login information $useremail_dirty = $_POST['useremail']; $password_dirty = $_POST['userpassword']; //Check to see if the email we were given exists in the database, and if the password matches $doesPasswordMatch = $dbm->doesPasswordMatch ( $useremail_dirty, $password_dirty ); if ( $doesPasswordMatch ) { //Correct login information was received. Login the user and redirect appropriately. $user->Login(); header ( "Location: ".BASE_URL."/userpage.php" ); exit; } else { //If an incorrect email or password was given, report that information to the user. $message_log::LogMessage("Incorrect login information."); } } //The user has failed to login. Redirect to the appropriate page. header ( "Location: ".BASE_URL."/loginfailed.php" ); And finally, given an unsuccessful login attempt, this is where I pick back up the array of messages to display the messages to the user: $message_log = $_SESSION['user_messages']; $all_messages = $message_log::GetMessages(); print $message_log::GetMessageCount()."<br>"; print count($all_messages)."<br>"; foreach ($all_messages as $message_string) { $prepared_string = prepare_text_for_html_output($message_string); echo $prepared_string."<br>"; } $message_log::ClearMessages(); Unfortunately, the "all_messages" variable has nothing in it...it's like the messages that I logged in the previous PHP script never even existed. I am calling session_start, so don't worry about that (even though it's not seen in these code snippets). What could be going wrong? I have four session variables, two I am valueing using $_POST elements from a previous page's form, the other two I am valueing using items retrieved from a database. Here is the code - ---------------------------------------------------- <?php session_start(); $_SESSION['UserLastName'] = strtolower(trim($_POST['txtLastName'])); $_SESSION['BadgeID'] = trim($_POST['txtBadgeID']); //get list for supervisor drop down $q1 = sprintf("select * from emps where emp_last = '".$_SESSION['UserLastName']."' and emp_badge = '".$_SESSION['BadgeID']."'"); $rs_emp_info = hitMSSQL($q1,"intra_sql","employees","xxxx","xxxx",1); $_SESSION['SSN'] = $rs_emp_info->fields("emp_ssn"); $_SESSION['CostCenter'] = $rs_emp_info->fields("emp_costcenter"); if ($_POST['rdoAction'] == 0) { header("Location: http://webapps/injury/empForm.php"); } ?> ---------------------------- When I get to the next page, empForm.php, the Last name and badge ID session vars are populated but the SSN and Cost Center session vars are not. I have tried several things including putting an exit(); after my header statement and first putting the database items into plain old $vars and then trying to populate the session vars with the value of the regular $vars, but nothing seems to work. I have a session_start() at the top of all of my scripts. Any idea why I am losing these values? (and why this box that I am typing into on this site is bouncing around so badly that I can't see what I am typing here???) Hey, I know how to use the PHP GD functions but how would I resize an image > 1000 width to 1000 width and just resizing the height to w/e needed to keep aspect ratio if the image is set to 1000 width in pixels of course. I don't mess with images much so idk the whole ratio thing. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=323252.0 |