PHP - Comparison Issues. (if Statement)
Hey there,
Now usually after a while I can always solve bugs with my code but this one really has me at a halt here. So basically I have a function that returns true if the accounts username = demo and false if it doesn't but the following if statement returns true and executes the code every time regardless of the returned value of the function like so: Code: [Select] if(isset($_POST['server_start']) or isset($_POST['server_stop']) or isset($_POST['server_restart']) && $Class['Account']->is_demo_account($_SESSION['account_id']) == false) Now if I run the following code right above that: Code: [Select] if($Class['Account']->is_demo_account($_SESSION['account_id']) == false) echo "it isn't a demo account."; else echo "it is a demo account."; It will echo "it is a demo account" correctly. Now can somebody please tell me why the if statement with the post values in always return true. Thanks for your time! Similar TutorialsHi guys I was just wondering if there is some date combination for which this type of comparisons will not work. var_dump("2010-15-1">"2010-4-01"); Provided the date is always in the YYYY-mm-dd format with optional preceding 0 . Thanks It DOES NOT any of this information for the wrestlers that DO NOT have a manager and if they do then it shows all as undefined variables. I know it has to do with the while statement I'm sure it's how its echoing the info and I don't know how to modify it so that I can echo the variable and if there's no value for the row then it shows N/A as its value. function getWrestling($style, $id) { $id=mysql_real_escape_string($id); if ($style=='singles') { $query = "SELECT bio.charactername AS manager, ebw.finisher AS finisher, ebw.setup AS setup, ebw.music AS music FROM efed_bio_wrestling AS ebw JOIN efed_bio AS bio ON ( ebw.manager_id = bio.id) WHERE ebw.bio_id = '$id'"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)){ ?> <h2>Wrestling</h2> <table class="biotable" cellspacing="10px"> <tr class="biotablerowb"> <td class="biotableheadingb">Manager/Valet:</td> <td class="biotabledatab"><?php if (strlen ($manager) < 1) { print "N/A"; } else { print "$manager";}?></td> </tr> <tr class="biotablerowb"> <td class="biotableheadingb">Finisher:</td> <td class="biotabledatab"><?php if (strlen ($finisher) < 1) { print "N/A"; } else { print "$finisher";}?></td> </tr> <tr class="biotablerowb"> <td class="biotableheadingb">Setup:</td> <td class="biotabledatab"><?php if (strlen ($setup) < 1) { print "N/A"; } else { print "$setup";}?></td> </tr> <tr class="biotablerowb"> <td class="biotableheadingb">Entrance Music:</td> <td class="biotabledatab"><?php if (strlen ($music) < 1) { print "N/A"; } else { print "$music";}?></td> </tr> </table> <?php } }?> Ok, i am adding a few things onto a "php email form" script, everything works as it should apart from this. The php email form, catches the submitted data and emails it accordingly, then after that, i use some of the data and show it, one form value i would like to show is from a radio button. Theres two radio buttons in one group. The radio buttons group name is "postage", value1 = "first" value2 = "second". $post1 is one cost, and $post2 is another cost, both get submitted an received fine. And as it stands when i submit the form without the line below, and tell it to echo "postage", it works fine. IF though i add this line after: if ($postage = "first") {$post_cost = $post1;} elseif ($postage = "second") {$post_cost = $post2;} If simply just comes threw as "first" everytime regardless, Why?? Heres the code for this section: //Collect postage details if(isset($_REQUEST['postage'])){$postage = stripslashes($_REQUEST['postage']);} if(isset($_REQUEST['post1']) && !empty($_REQUEST['post1'])){$post1 = stripslashes($_REQUEST['post1']);} if(isset($_REQUEST['post2']) && !empty($_REQUEST['post2'])){$post2 = stripslashes($_REQUEST['post2']);} if(isset($_REQUEST['Total:']) && !empty($_REQUEST['Total:'])){$total = stripslashes($_REQUEST['Total:']);} //Get disired postage type $post_cost = 0; if ($postage = "first") {$post_cost = $post1;} elseif ($postage = "second") {$post_cost = $post2;} //Work out total to pay $totaltopay = $total+$post_cost; ?> Thanks Andy Am trying to redirect a user based on their login details. it works fine till it get to a particular department.. "Marine Logistics". when i try to log in with ID of someone in that department, it redirects to invalid login page. the code below. what am i missing?
$sql1 = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password'"); $data = mysql_fetch_array($sql1); $department = $data['department']; if ($department== "Admin") { header("Location: admin/dash_admin.php"); exit; } else if ($department == "ICT" ) { if ($data['position'] == "HOD") { header("Location: ICT/HOD/hod_dash.php"); exit; } else{ header("Location: ICT/staff/staff_dash.php"); exit; } exit; } // check if user is in account department else if ($department == "Account" ) { if ($data['position'] == "HOD") { header("Location: account/HOD/account_dash.php"); exit; } else { header("Location: account/staff/staff_dash.php"); exit; } exit; } //check if user is in Supply chain/ Asset Integrity department else if ($department == "Supply Chain/ Asset Integrity" ) { if ($data['position'] == "HOD") { header("Location: supply_chain/HOD/hod_dash.php"); exit; } else{ header("Location: supply_chain/staff/staff_dash.php"); exit; } exit; } // check if user is in manpower department else if ($department == "Manpower" ) { if ($data['position'] == "HOD") { header("Location: manpower/HOD/hod_dash.php"); exit; } else{ header("Location: manpower/staff/staff_dash.php"); exit; } exit; } // check if user is in Business Development Department else if ($department == "Business Development" ) { if ($data['position'] == "HOD") { header("Location: business_development/HOD/hod_dash.php"); exit; } else{ header("Location: business_development/staff/staff_dash.php"); exit; } exit; } // check if user is in HR else if ($department == "HR" ) { if ($data['position'] == "HOD") { header("Location: HR/HOD/hod_dash.php"); exit; } else{ header("Location: HR/staff/staff_dash.php"); exit; } exit; } //check if user is in Marine Logistics Department else if ($department== "Marine Logistics" ) { if ($data['position'] == "HOD") { header("Location: logistics/HOD/hod_dash.php"); exit; } else{ header("Location: logistics/staff/staff_dash.php"); exit; } exit; } //check if user is from Maintenance Department else if ($department == "Maintenance" ) { if ($data['position'] == "HOD") { header("Location: Maintenance/HOD/hod_dash.php"); exit; } else{ header("Location: Maintenance/staff/staff_dash.php"); exit; } exit; } //check if user is from Admin/services Department else if ($department == "Admin / Services" ) { if ($data['position'] == "HOD") { header("Location: admin_services/HOD/hod_dash.php"); exit; } else{ header("Location: admin_services/staff/staff_dash.php"); exit; } exit; } } else{ header("Location: indexWrongPassOrUser.php"); exit; } Hi, I'm having a slight issue with some coding (see below). It worked a few minutes ago before I add "Packages" & "Safety & Technology" titles to the MySQL database. Hopefully the attached image has worked, but if it hasn't go to www.bikescarsandvans.co.uk/test.php and select the first Audi A3 additional extras drop down menu and you'll see whats going wrong. Code: [Select] $query_title = "SELECT * FROM extras JOIN car_to_extra ON (car_to_extra.extras_id = extras.id) WHERE car_to_extra.car_id = '{$car_row['id']}' ORDER BY extras.price ASC"; $title_results = mysql_query($query_title) or die ("Error in query: $query_title. ".mysql_error()); $current_heading = ''; print "<div class='addtional_extras'>";// ADDED TO TRY TO SORT OUT POSITIONING ISSUE while ($title_row = @ mysql_fetch_array($title_results )) { if ($current_heading != $title_row["title"]) { // The heading has changed from before, so print the new heading here. $current_heading = $title_row["title"]; print " <div class='title_tab2'>" . $title_row["title"] . "</div> "; } ?> <a class='data' href='#' onmouseout='hideTooltip()' onmouseover='showTooltip(event,"<?php print "" . $title_row["info"] . "<br/>(£" . $title_row["price"] . ")"; ?>");return false'> <?php print " <img class='extra_img' src=\"". $title_row["img"] ."\" alt='" . $title_row["img_alt"] . "' /></a> "; }// CLOSES WHILE LOOP ($title_row = @ mysql_fetch_array($title_results )) print "</div>";// CLOSES DIV IMAGE55 Here's the code, this is the PHP in my html contacts page (that IS in fact saved with a PHP extension): <div class = "centercontainer"> Hi Everyone. I am new to SQL and trying to write a query against the following results table that would allow me to list the subjects where the student Mary has got a higher score than Tom.
Subject
Student
Teacher
Score
Maths
Tom
Anderson
67
Maths
Mary
Anderson
68
English
Tom
Lewis
55
English
Mary
Lewis
44
French
Tom
Joubert
87
French
Mary
Joubert
76
Geography
Tom
Arnold
76
Geography
Mary
Arnold
82
I believe I should be using the join clause but am unable to get this to work.
Thanks
Hi! gud pm guys! I have a simple problem which i can't seem to workout so i kinda need your expert help! I'm trying to compare a variable to a string in my db, the variable and the entry on my db has a format of (car - branch), I made this simple function to do that but it doesn't seem to compare properly.. Code: [Select] function get_car_code($branch) { global $connection; $query = "SELECT code "; $query .= "FROM car_code "; $query .= "WHERE branch =" . '"$branch"'; $query .= " LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); return $result_set; } when its called back it doesn't return anything.. I'm thinking its the white spaces (or I'm wrong) but i needed them so i cant removed them.. Any suggestions? Thanks in advance! I have a couple of loops that are supposed to 1) list all the values of one table as check boxes then 2)compare them to the values of another table. If they match that checkbox is supposed to be pre-checked. I have some code but it is not working just right yet and I was hoping someone could help me. Code: [Select] <?php include("../../../cart/includes/openDbConn.php"); $sql = "SELECT Name FROM FabricType"; $dogettype = 'SELECT Type FROM FabricsTypes WHERE SKU = "'.$sku.'";'; $result = mysql_query($sql); while($results = mysql_fetch_array($result)) { if( $i % 3 == 0 ) { echo '</tr><tr>'; } $result2 = mysql_query($dogettype); while($results2 = mysql_fetch_array($result2)) { if(trim($results2['Type']) == trim($results['Name'])) { $ischecked = 'checked="checked"'; $value = 1; } else { $ischecked = ''; $value = 0; } } $i++; $tn = trim(ucfirst($results["Name"])); echo '<td> <label> <input type="checkbox" name="typeGroup1[]" '.$ischecked.' value="'.$results['Name'].'"> '.$tn.' </label> </td>'; } ?> With this code it echoes the check boxes correctly but only checks it if it is the last value in $results2. If I move the second while loop like so: Code: [Select] <?php include("../../../cart/includes/openDbConn.php"); $sql = "SELECT Name FROM FabricType"; $dogettype = 'SELECT Type FROM FabricsTypes WHERE SKU = "'.$sku.'";'; $result = mysql_query($sql); while($results = mysql_fetch_array($result)) { if( $i % 3 == 0 ) { echo '</tr><tr>'; } $result2 = mysql_query($dogettype); while($results2 = mysql_fetch_array($result2)) { if(trim($results2['Type']) == trim($results['Name'])) { $ischecked = 'checked="checked"'; $value = 1; } else { $ischecked = ''; $value = 0; } $i++; $tn = trim(ucfirst($results["Name"])); echo '<td> <label> <input type="checkbox" name="typeGroup1[]" '.$ischecked.' value="'.$results['Name'].'"> '.$tn.' </label> </td>'; } } ?> It only echoes out the first results of $results for however many values there are in $results2. Thanks for any help. Hi, its me again! So i have this function which gets all the events in my db according to its mall_id and a date (year-month). I merged the $month and $year so i can compare it to the date field in my table. I used DATE_FORMAT to modify my date field so i can compare them but it doesn't seem to work perfectly, Code: [Select] function select_all_events($mall_id, $month, $year, $public) { global $connection; $monthname = $month; $monthnum = date("n", strtotime("01-".$monthname."-2011 00:00:00")); if($monthnum < 10) { $monthnum = "0" . $monthnum; } $selected_date = $year . "-" . $monthnum; $query = "SELECT *, DATE_FORMAT(date ,'%Y-%m' ) AS date "; $query .= "FROM table "; $query .= "WHERE malls_id=" . $mall_id; $query .=" AND date =" . $selected_date; if($public == true) { $query .= " AND visible = 1"; } $query .= " ORDER BY date DESC"; $result_set = mysql_query($query, $connection); confirm_query($result_set); return $result_set; } I tried echoing $selected_date, the format is correct, the problem seems to be the comparison.. Also i tried doing it like this: Code: [Select] $query = "SELECT * "; $query .= "FROM table "; $query .= "WHERE malls_id=" . $mall_id; $query .=" AND DATE_FORMAT(date ,'%Y-%m' ) =" . $selected_date; but the results are mismatched, like when i choose 2012 January it display's 2011 December ... This dates are making my head dizzy and costing me time..lol Any ideas? Thanks in advance! I need some idea of why my code works on 2 servers except the one that it needs to work on. Below is the code including the sites where the phpinfo is loaded. Please help me figure this one out, it's probably simple but I don't see it. phpinfo of the one not working as expected phpinfo of the one that works as expected The problem is here I think? Quote $insertGoTo = SITE_URL."?pg=registered&addr=".$myid; header('Location:'.$insertGoTo); The code is too long to be posted... in reply... Hi guys I am looking for a loop which will run untill there is a difference of 10 minutes. The timestamp I wish to use is "ISO 8601 date (added in PHP 5)" [ date("c")] If anyone know some code for this it would be much appreicated. I can do the loop its just the comparison between the two timestamps as part of the loop I have no idea where to start on. Cheers, and thanks in advance. all my dates I'm reading from a database are formatted mm/dd/yyyy and I want to find the number of days difference from the duedate and the datepaid (dayslate) . ? I'm compiling and running C++ applications from PHP. I'm using backticks to capture the output of the applications ran. The output is just some simple text. In my case "Miles per gallon = x" where x is just a number. I cannot for the life of me get the comparison to return true. For example Code: [Select] $command1="./a.out1 <input1"; $a = `$command1`; $command2="./a.out2 <input2"; $b = `$command2`; if(strcmp($a,$b)==0){ ... } else{ // this is always executing ... } The two strings $a and $b are both "Miles per gallon = 10". I have checked both variables using var_dump(bin2hex($a)) and get dump1= string(42) "4d696c6573207065722067616c6c6f6e203d203130" dump2= string(42) "4d696c6573207065722067616c6c6f6e203d203130" Any idea on what's happening? Hello everyone:
I'm having trouble with code that compares a Form value ($uname) to Field values (username) from my database. In testing, I'm using the same Form data over and over, and I now have several identical records instead of just one unique record for this user.
if (empty($_POST["uname"])) { $unameErr = "* Username is required"; } else { $uname = test_input($_POST["uname"]); if (!preg_match("/^[a-zA-Z0-9]*$/",$uname)) { $unameErr = "* Only letters and numerals are allowed"; } else { // Now sure the username is legit, we check to see if it's a // unique username by comparing it to all usernames already in member table. require_once 'login.php'; // This file contains database access credentials $db_conn = new mysqli($db_hostname, $db_username, $db_password, 'login'); if($db_conn->connect_error) die ('Connect Error: ('.$db_conn->connect_errno.')'.$db_conn->connect_error); $query = "select username from member"; // Only selecting the field to compare to $result = $db_conn->query($query); if(!$result) die ('Database access failed: ('.$db_conn->connect_errno.')'.$db_conn->connect_error); $rows = $result->num_rows; for($i = 0; $i <= $rows; $i++) { if(mysqli_fetch_assoc($result) == $uname) { $unameErr = "* Username already in use. Please choose another."; mysql_close($db_conn); exit; } } $query = "insert into member values(NULL, '$uname', '$pwd1', '$fname', '$lname')"; $result = $db_conn->query($query); if(!$result) die ("Database insertion failed: ".mysql_error()); } }This is my first attempt at this using PHP and am pleased that I can at least access my db. But I just can't figure out how to make this comparison check. Thanks in advance for any help you offer. ~Landslyde hi everyone
i keep seeing the following Comparison Operators:
<>i see it used in the following context: if ($connection <> 'SSL') { $connection = 'NONSSL'; }be grateful if somone would tell me what it means, i looked online but could not find the symbol thanks Hi
i am trying to compare to arrays
$a = Array ( [q1] => no [q3] => yes [q2] => yes );
$b = Array ( [q1] => no [q3] => yes [q2] => yes );
But when i intersect them it results in one element only, dont know why???
$c = array_intersect($a,$b);
print_r($c);
output -
Array ( [q1] => no )
Code: [Select] if( date('j') < 1 && > 14) { $EnrollDate = "1/".date('n')."/".date('y'); }else { $EnrollDate = "15/".date('n')."/".date('y'); } What could be wrong here, i cant work! I have this $str variable which say holds "String" and in my comparison I'm checking if it's content is "string" and it is supposed to return true but it isnt because of the case, how do I compare them without the case being an issue ? |