PHP - Isset Not Reading Variable
Can someone help me understand why when I run this script I can see that {$_SESSION['user_level']} has changed for each user I login into for, but, for some reason the elseif statement never gets executed although I can see thru the debug line of i inserted (line 4: echo statement for user_level) does show that the 'user_level' variable does equals '1'? WHY?
How come only the 'first_name" If statement executes and never the elseif? Code: [Select] <?php // Changing Header Due to User Status // Add links if the user is an administrator: if ( isset($_SESSION['first_name'])) { echo 'Welcome user'; echo ", {$_SESSION['first_name']}!"; echo ", {$_SESSION['user_level']}!"; echo '<a href="../registration/login/logout.php" title="Logout"> | Logout</a> <a href="../registration/login/change_password.php" title="Change Your Password"> | Change Password</a> <a href="../addevent/" title="My Events"> | My Events</a> <a href="../addvenue/" title="My Places"> | My Places</a> <a href="../registration/login/register.php" title="Register for the Site"> | Register</a> <a href="../registration/login/forgot_password.php" title="Password Retrieval"> | Retrieve Password</a> '; } elseif ( isset($_SESSION['user_level']) == '1' ) { echo 'Welcome Admin'; echo ", {$_SESSION['first_name']}!"; // echo ", {$_SESSION['user_level']}!"; echo '<a href="../registration/login/logout.php" title="Logout"> | Logout</a> <a href="../registration/login/change_password.php" title="Change Your Password"> | Change Password</a> <a href="../addevent/" title="My Events"> | My Events</a> <a href="../addvenue/" title="My Places"> | My Places</a> <a href="../registration/login/register.php" title="Register for the Site"> | Register</a> <a href="../registration/login/forgot_password.php" title="Password Retrieval"> | Retrieve Password</a> '; echo '<a href="view_users.php" title="View Users"> | Users</a> <a href="../registration/login/view_activities_types.php" title="All Activity Choice Types"> | Activity Choices</a> <a href="../registration/login/admin/add_activity_type.php" title="Add Activity Choices"> | Add Activity Choices</a> '; } else { // echo ", {$_SESSION['user_level']}!"; } Similar TutorialsHi girls and boys I am trying to set a variable if a session OR a cookie has been set, but am unsure on how to write the statement... if (isset($_SESSION['name'])||isset($_COOKIE['name'])) {$variable = $_SESSION['name']||$_COOKIE['name'];} Obviously not working there, but just need a pointer here. any help is appreciated... I have the following if statement: Code: [Select] if ((isset($select_category) == 'All') || (!isset($select_category)) && (!isset($most_liked))) { The value for the variable gets taken from a drop down menu, which is a list of categories. The problem I am having is with the isset condition check is that the variable is always set, but it does not consider the check for equality with the 'All' condition. Which basically means no matter which category I choose from the drop down menu, it always goes to this very first if statement, and does NOT go to the other elseif statement, and I think it has to do with the isset condition check, because without it it would work, though without it I am getting a notice warning, that the variables are undefined. Any ideas how I can make it check if its equal to 'All' together with the isset condition check? What I am trying to say is no matter which category is chosen, with the isset condition check, the variable is always set, thus the if statement is true, there basically seems to be a contradiction going on. I have a PHP page that makes a checkbox appear after a certain textbox is exited. This part of the functionality is working - the user leaves the textbox, the AJAX call is made, and if certain criteria are met, the checkbox appears or it doesn't.
Here's where I need help. When the checkbox appears on the form and the form is submitted via POST, I can't get its value. Here's the code that's in the HEAD section:
<script type="text/javascript"> $(document).ready(function() { $('#id2').blur(function(){ $.post("biz/add_official.php", { id1: $('#id1').val(), id2: $('#id2').val() }, function(response){ $('#usernameResult').fadeOut(); setTimeout("finishAjax('usernameResult', '"+escape(response)+"')", 400); }); return false; }); }); function finishAjax(id, response) { /* $('#usernameLoading').hide();*/ $('#'+id).html(unescape(response)); $('#'+id).fadeIn(); } //finishAjax </script>And here's the code that's in the FORM section: <span id="usernameResult" style="color:green;"></span> <script> $('.container').find('.checkOfficial input[type="checkbox"]').val() </script>When the form is submitted via POST, how do I see if checkbox was checked or unchecked? Both of these variables appear empty when the form is submitted: $_POST['checkOfficial'] $_POST['usernameResult'] does anyone know how to decode this XML variable value into string values? I also need to know the oposite way: creating variable values into xml. I've tried several code examples but they did filter the requested data. Code: [Select] $xml='<?xml version="1.0" encoding="utf-8"?> <elements> <text identifier="ed9cdd4c-ae8b-4ecb-bca7-e12a5153bc02"> <value/> </text> <textarea identifier="a77f06fc-1561-453c-a429-8dd05cdc29f5"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <textarea identifier="1a85a7a6-2aba-4480-925b-6b97d311ee6c"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <image identifier="ffcc1c50-8dbd-4115-b463-b43bdcd44a57"> <file><![CDATA[images/stories/red/cars/autobedrijf.png]]></file> <title/> <link/> <target/> <rel/> <lightbox_image/> <width><![CDATA[250]]></width> <height><![CDATA[187]]></height> </image> <text identifier="4339a108-f907-4661-9aab-d6f3f00e736e"> <value><![CDATA[Kramer 5]]></value> </text> <text identifier="ea0666d7-51e3-4e52-8617-25e3ad61f8b8"> <value><![CDATA[6000 RS]]></value> </text> <text identifier="90a18889-884b-4d53-a302-4e6e4595efa0"> <value><![CDATA[Eindhoven]]></value> </text> <text identifier="410d72e0-29b3-4a92-b7d7-f01e828b1586"> <value><![CDATA[APK Pick up and return]]></value> </text> <text identifier="45b86f23-e656-4a81-bb8f-84e5ea76f71f"> <value><![CDATA[15% korting op grote beurt]]></value> </text> <text identifier="3dbbe1c6-15d6-4375-9f2f-f0e7287e29f3"> <value><![CDATA[Gratis opslag zomerbanden]]></value> </text> <text identifier="2e878db0-605d-4d58-9806-8e75bced67a4"> <value><![CDATA[Gratis abonnement of grote beurt]]></value> </text> <text identifier="94e3e08f-e008-487b-9cbd-25d108a9705e"> <value/> </text> <text identifier="73e74b73-f509-4de7-91cf-e919d14bdb0b"> <value/> </text> <text identifier="b870164b-fe78-45b0-b840-8ebceb9b9cb6"> <value><![CDATA[040 123 45 67]]></value> </text> <text identifier="8a91aab2-7862-4a04-bd28-07f1ff4acce5"> <value/> </text> <email identifier="3f15b5e4-0dea-4114-a870-1106b85248de"> <value/> <text/> <subject/> <body/> </email> <link identifier="0b3d983e-b2fa-4728-afa0-a0b640fa34dc"> <value/> <text/> <target/> <custom_title/> <rel/> </link> <relateditems identifier="7056f1d2-5253-40b6-8efd-d289b10a8c69"/> <rating identifier="cf6dd846-5774-47aa-8ca7-c1623c06e130"> <votes><![CDATA[1]]></votes> <value><![CDATA[1.0000]]></value> </rating> <googlemaps identifier="160bd40a-3e0e-48de-b6cd-56cdcc9db892"> <location><![CDATA[50.895711,5.955427]]></location> </googlemaps> </elements>'; I want to get the COUNT of the fields (ArrayM11 - ArrayM19), which has the word "YES". The code isn't working. Appreciate any help. $Array1 = array(); for($j=0;$j<count($ArrayM1);++$j) { $result = array_count_values($ArrayM1[$j]); if (isset($result['YES'])) { $points1 = $result['YES']; } } Isn't this code redundant... if (isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == TRUE){ After all, if $SESSION['logged_in'] == TRUE then it is *obviously* set... Debbie Hello all, i am hoping someone can help me. i have some code i have been working on and i am trying to add a 404 page if it cant find the page, i know it will be some sort of if statment, but with me been pretty much a noob at php i am stuck. heres the code that the page calls. Code: [Select] function get_content() { //Get page name from browser if none call it home $page = (isset($_GET['page'])) ? $_GET['page'] : 'home'; //Get The Page Content $sql = "SELECT * FROM content WHERE page = '$page'"; $res = mysql_query($sql) or die (mysql_error()); while($row = mysql_fetch_assoc($res)){ //Show The Page Content echo '<h1>' . $row['title'] . '</h1>'; echo $row['body']; } } thanks all. Hi all I need to do a multiple if isset to get three variables from the URL. Here is my code for just one: if(isset($_GET['category'])) { $fetchproducts = mysql_query(" SELECT * FROM `products` WHERE category = '".$_GET['category']."'"); while($returnedProduct = mysql_fetch_array($fetchproducts)) { include('product-cell.php'); } How do I combine this to check what is the 'type' and 'colour' from the URL and fetch from the SQL accordingly? Many thanks for you help Pete guys this thing called isset() is bugging me.What is the difference in when you say Code: [Select] if(isset($_POST['name'])) and Code: [Select] if($_POST['name']) and Code: [Select] if(!$_POST['name']) and why would someone require a code such as Code: [Select] if($_POST['submit']=='Submit') And what is that code which tells you the user has entered something into the form Thanks People i Have two page login.php and verify.php In login.php user is entering Username and Password and in the action of the form i am writing verify.php. If verification is a success then i will start a session() Code: [Select] session_start(); $_SESSION['ls']="loggedin"; // ls stands for login status $_SESSION['id']=$row['id']; $_SESSION['user_name']=$row['user_name']; $_SESSION['email']=$row['email']; header('location : members.php'); die (" "); and will redirect them to members.php .... Everything is working fine... But in login.php i have written a code on the top... Code: [Select] <?php if(isset($_SESSION['ls']) && isset($_SESSION['id']) && isset($_SESSION['user_name']) && isset($_SESSION['email']) ) { header('location:members.php'); die(" "); } ?> I want if a session is started and if user will access login.php they will automatically go to members.php But this script is not working... Iam not getting whats the problem... also i m not getting any error login.php or anything CODE WRITTEN ON THE TOP OF members.php IS : Code: [Select] <?php session_start(); if(@$_SESSION['ls']!=="loggedin" ) // Checks if the person has done stage one (Registration.php) { header('Location: login.php'); //If they haven't done it, it sends them back. die (" "); } ?> Hi there, I'm inserting data into a mysql database. My submissions works fine, however when a part of the form is not filled out the php scripit crashes. How can I submit all data that is set and skip pieces that aren't filled out? For example I have a plant database which has an option to insert different types of common names for the plant. It's ok if they aren't all filled out. My code is as follows: Code: [Select] <?php //insert general plant data into db $queryplant="INSERT INTO actualplanttable (id, scientific, common1, common2, common3, family, genus, description, planting, growing, care, duration, reference) VALUES ('NULL', '$_POST[scientific]', '$_POST[common1]', '$_POST[common2]', '$_POST[common3]', '$_POST[family]', '$_POST[genus]', '$_POST[description]', '$_POST[planting]', '$_POST[growing]', '$_POST[care]','$_POST[duration]','$_POST[reference]')"; mysql_query($queryplant) or die ('Error updating actualplanttable'); //insert maintenance data into db $querymaintenance="INSERT INTO plantmaintenancelinktable (plant_id, maintenance_id) VALUES ('$inserted_id', '$_POST[maintenance]')"; mysql_query($querymaintenance) or die ('Error updating plantdurationtable'); ?> Should I be trying to work an isset function into this code? Any help would be greatly appreciated. Thanks! Bill... I believe that my problem is with the isset on line 7 and 39, but I do not know of anyway around it. Can someone enlighten me. <?php session_start(); if (isset($_GET['logout'])){ unset($_SESSION['logged_in']); } ?> <html> <head> <title>Add a New Car!</title> <?php if (isset($_POST['submit'])) { //print_r($_POST); $password = md5($_POST['password']); //echo'<p>'.$password.'</p>'; $username = ($_POST['username']); //echo'<p>'.$username.'</p>'; } $db = new PDO('sqlite:login.sqlite'); $login = 'SELECT * FROM login WHERE userid="'.$username.'" AND password="'.$password.'";'; //echo'<p>'.$login.'</p>'; $attempt = $db->query($login); foreach ($attempt as $row) { //print_r($row); $_SESSION['logged_in'] = $username; } ?> </head> <body> <?php if (!isset($_SESSION['logged_in'])){ ?> <form method="post" action="Db_login.php"> <p>Username:<br /><input type="text" name="username" /> </p> <p>Password:<br /><input type="password" name="password" /></p> <p><input type="submit" name="submit" value="Log In!" /></p> </form> <?php } else { ?> <?php if(isset($_POST['submit'])) { print_r($_POST); $make = ($_POST['make']); $model = ($_POST['model']); $year = ($_POST['year']); $fuel = ($_POST['fuel_type']); $vin = ($_POST['vin_number']); $reg = ($_POST['reg_number']); } $db = new PDO('sqlite:cars.sqlite'); $sqlCars = 'INSERT INTO cars ( ) VALUES("'.$make.'","'.$model.'","'.$year.'","'.$fuel.'","'.$vin.'","'.$reg.'");'; echo'<p>'.$sqlCars.'</p.>'; ?> <form method="post" action="Db_new_Cars.php" enctype="multipart/form-data"> <p>Make:<br /><input type="text" name="make" /> </p> <p>Model:<br /><input type="text" name="model" /></p> <p>Year:<br /><input type="text" name="year" /></p> <p>Fuel Type:<br /><input type="text" name="fuel_type" /></p> <p>Vin Number:<br /><input type="text" name="vin_number" /></p> <p>Reg Number:<br /><input type="text" name="reg_number" /></p> <p>Choose a image to upload:<br /> <input type="file" name="myfile"></input></p> <p><input type="submit" name="submit" value="Submit!" /></p> </form> <h1> Protected Content!</h1> <p>You are logged in as <em><?php echo $_SESSION['logged_in']; ?> </em></p> <p><a href="Db_login.php?logout=true">Log out!</a></p> <p><a href="New_Cars.php">Add a new car</a></p> <p><a href="Book_Out_Cars.php">Book out a car</a></p> <?php } ?> </body> </html> why dose this not work <?php if(isset($_SESSION['SESS_ADMIN'])) $loc = ../admin/admin.php; else $loc= ../head/head.php"; ?> <form><INPUT TYPE="button" value="Main Menu" onClick="parent.location='<?php echo $loc; ?>'"></form> </body> </HTML> This is blowing my mind. I have this function and all I want it to do is check to make sure that the var $race is set and = '0'. The default value from the form is '0'. I also want it to check the value of race and if it is anything but the two listed , submit error. Yes I've tried to replace the || with &&.. Nothing works(Meaning that it will error when its not suppose to or it wont error when its suppose to).. Any ideas? Code: [Select] function check_Race ($race,$display_name,$member_id,$description,$ip) { //echo "This is the race". $race; //exit; if (isset($race) && $race ='0' && $race !== 'White' && $race !== 'Black'){ echo "This is an errror.!"; $t_error="19"; $member_id = $member_id; notify_Admin($t_error,$member_id,$ip); // logOut ($t_error); exit; } Hi guys, first time posting here. Anyway, heres my problem. I have this section of code at the beggining of my page: Code: [Select] if (isset($_POST['userChoice'])) { $try = check_word($_POST['userChoice']); echo ("We are into the loop"); } else { echo ("<br/>about to call change word"); changeword(); echo ("<br/> we called the changeword"); } And here is my form: Code: [Select] <html> <head> </head> <body> <form name="wordguess" action="Index.php" method="POST"> <table> <tbody> <tr> Try to guess what the following word is: <?=$scrambled ?> <br/> </tr> <tr> Your Guess: <input type="text" id="userChoice" size="20" /> <br/> </tr> <tr> <td> <input type="submit" name="submit" id="submit" value="Submit"> </td> </tr> <tr> <?=$correct?> </tr> </tbody> </table> </form> </body> </html>' Now, how i assumed it worked was that the first time the page is loaded it would display the form and that's it. However, even when they hit the submit button on the form, its not really doing the POST, so when the page reloads, gives me the same stuff so it always goes on the else part of the if. Any help would be appreciated. Thanks, GoodVibe I want to link this two file but not working,
first file to make drop down option form Hi there, I have just move hosts with our website and it loads the frontpage but non of the subsequent pages. The site works like this, depending on the variables in the address depends which page and which template are loaded into it. If the template is "ros" it loads rosettes template, if it is "tro" it loads trophy template, and then the name of the item, ie "hazel" will load up the hazel product page. All it is doing at the moment is loading the home.php page. The code to do this is below: <? if (!isset($template)) {include ("static/home.php");} else if (isset($id)) { if (!file_exists("site_templates/$template.php")) { echo "OOPS! <P> The template you have requested does not exist!<BR><BR><BR><BR><BR><BR>"; }elseif (file_exists("site_templates/$template.php")) { include ("site_templates/$template.php"); } } ?> It worked with our last host, but refuses to work now. Is there someone out there that can help. Thanks in advance, Phil i know theres a way but i just forget. i want to do a switch function. Code: [Select] switch ($_GET['page']) { case 0: include 'page'; break; case 1: include 'page1'; break; case 2: include 'page2'; break; default: include 'page'; } ?> just like that but if there is no $_GET page i just want it to do the default. instead of doing if isset GET page do switch else default page. i just want it to be simpler by doing something like switch(isset$_GET etc. Running into some problems with my code. I am having the user search the Database with either a UAID or the user's full name. It works fine when you input both the UAID and name; however, I want it to work if only one is give (i.e. just the name or just the UAID). I decided to use the isset($_POST) function of php but I am not getting it to work correctly. PHP believe it is set even though it is empty. Here is my html form. <?php @include 'accesscontrol.php'; 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\">" ."<title> Hello </title>" ."<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />" ."<head>" ."<style type=\"text/css\">" ."h1{" ."border-bottom-style: double;" ."border-bottom-color: black;" ."border-bottom-width: 5px;" ."}" ."p{" ."background-color:#4682B4;" ."}" ."</style>" ."</head>" ."<body style=\"background-color:#B8B8B8\">" ."<table align=\"center\" style=\"background-color:#B8B8B8\" WIDTH=\"100%\" HEIGHT=\"100%\">" ."<tr valign=\"middle\">" ."<td align=\"center\">" ."<form method=\"post\" action=\"user.php\">" ."<table align=\"center\" cellpadding=\"10\" style=\"background-color:#5CADFF\" width=\"500\" height=\"400\">" ."<tr>" ."<th colspan=6 align=\"center\"><h1>Welcome: ".$uid."</h1></th>" ."</tr>" ."<tr>" ."<td colspan=3 width=40% align=center>" ."UAID:<br> <input type=\"text\" size=\"8\" name=\"UAID\" /></td>" ."<td colspan=3 width=60% align=center>" ."Name (Last, First):<br><input type=\"text\" size=\"8\" name=\"last\"/>, <input type=\"text\" size=\"8\" name=\"first\" />" ."</tr>" ."<tr>" ."<td colspan=6 align=\"center\"><input type=\"submit\" value=\"submit\" />" ."</td>" ."</tr>" ."</tr>" ."</table>" ."<tr>" ."</tr>" ."</td>" ."</tr>" ."</table>" ."</body>" ."</html>"; ?> Here is the PHP: <?php @include 'accesscontrol.php'; //include 'common.php'; include 'db.php'; $fname = $_POST['first']; $lname = $_POST['last']; $sql = "SELECT * FROM `user` WHERE UAID='$_POST[UAID]'"; $result = mysql_query($sql); $rows = mysql_fetch_array($result); if(isset($fname) && isset($lname)) { echo "Post first $fname <br>" ."Post last $lname"; $firstname = $rows['firstname']; $lastname = $rows['lastname']; if($fname != $firstname OR $lname != $lastname) { ?> <html> <head> <script language="JavaScript"> alert(" Hello this is crap" ); history.back(); </script>"; </head> </html> <? exit; } else { echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"URL\">" ."<html xmlns=URL>" ."<title> Hi </title>" ."<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />" ."<head>" ."<style type=\"text/css\">" ."h1{" ."border-bottom-style: double;" ."border-bottom-color: black;" ."border-bottom-width: 5px;" ."}" ."p{" ."background-color:#4682B4;" ."}" ."</style>" ."</head>" ."<body style=\"background-color:#B8B8B8\">" ."<table align=\"center\" style=\"background-color:#B8B8B8\" WIDTH=\"100%\" HEIGHT=\"100%\">" ."<tr valign=\"middle\">" ."<td align=\"center\">" ."<table align=\"center\" cellpadding=\"10\" style=\"background-color:#5CADFF\" width=\"600\" height=\"400\">" ."<tr>" ."<th colspan=6 align=\"center\"><h1>Welcome: ".$uid."</h1></th>" ."</tr>" ."<tr>" ."<form method=\"Post\" action=\"userview.php\">" ."<td colspan=3 width=40%>" ."UAID: <input type=\"text\" size=\"8\" name=\"UAID\" value= ".$_POST['UAID']." /></td>" ."<td colspan=3 width=60%>" ."Name (LAST, FIRST):<input type=\"text\" size=\"8\" name=\"last\" value= ".$_POST['last']." />, <input type=\"text\" size=\"8\" name=\"first\" value= ".$_POST['first']." />" ."</td>" ."</tr>" ."<tr>" ."<td colspan=3 width=40%>" ."Department:<input type=\"text\" size=\"8\" name=\"department\" value=" .$rows['BOG'].">" ."</td>" ."<td colspan=3 width=60%>" ."Employee ID:<input type=\"text\" size=\"8\" name=\"empID\" value=" .$rows['employeeID'].">" ."</td>" ."</tr>" ."<tr>" ."<td colspan=3 align=\"center\"><input type=\"submit\" value=\"View\">" ."</form>" ."</td>" ."<form method=\"Post\" action=\"homepage.php\">" ."<td colspan=3 align=\"center\"><input type=\"submit\" value=\"Back\">" ."</td>" ."</tr>" ."</tr>" ."</table>" ."<tr></tr></td></tr></table></body></html>"; }} mysql_free_result($result); ?> Hi i am connecting to my database and i need the script to print something if the field is not empty, I am using the following, but its not working any ideas where i am going wrong? if (isset($row[image_zero])) { |