PHP - If('00' == '0000') Returns True
<?php if('00' == '000') echo 'weired'; ?> Please consider the code above. Strangely it echoes the word "weired". Also if('00' == '000000000000000') returns true and so forth. What is really going on? Thanks in advance By the way the php version is 5.3.9 on wampserver 2.2 Similar TutorialsSo in my last thread I was working on checking if a file was there...I resorted to something not in the library and used $pic_exists_jpg = fopen($jpg_path,'r'); $pic_exists_jpeg = fopen($jpeg_path,'r'); $pic_exists_gif = fopen($gif_path,'r'); $pic_exists_png = fopen($png_path,'r'); if ($pic_exists_jpg != '0') { $jpg_test = '1'; } elseif ($pic_exists_jpg == '1') { $jpg_test = '2'; } elseif ($pic_exists_jpg == '0') { $jpg_test = '2'; } elseif ($pic_exists_jpeg != '0') { $jpeg_test = '1'; } elseif ($pic_exists_gif != '0') { $gif_test = '1'; } elseif ($pic_exists_png != '0') { $png_test = '1'; } now for some reason php is being a poo and no matter what returning that there is a file there. no matter what method i use be it fopen or file_exists or anything else, it saying I have a file in that directory BUT I DO NOT! THERE IS NOT ONE OF THOSE FILES. I know I have my paths right because If I echo them directly I get the picture...what the heck?! soo i get info from a form and i want to search for it in my db .. if i find user_name AND user_password the $result returns true .. otherwise false .. <?php require_once("../includes/connection.php"); ?> <?php $user_name=$_POST["user_name"]; $user_password=$_POST["user_password"]; ?> <?php $query = "SELECT * FROM users WHERE '{$user_name}' = user_name AND '{$user_password}'= user_password "; $result = mysql_query($query,$connection); if($result==false){ redirect("../index.php");} elseif($result==true){ redirect("../welcome.php"); } ?> <?php //close connection! mysql_close($connection); ?> but the problem is that it always returns TRUE !!!! whats the problem here exactly ??? Hi I don't know exactly what to do to see correct date of birth into my sql database. I have following code i.e. $month=$_POST['month']; $year=$_POST['year']; $date=$_POST['date']; $date_value="$month/$date/$year"; echo"YYYY-mm-dd format:$date_value"; and sql insert statement is like this $sql = "INSERT INTO table_name(fname, lname, gender, add1, add2, city, state, zip, country, email, phone, cellphone, dob, photo1) VALUES('$fname','$lname','$gender','$add1','$add2','$city','$state','$zip','$country','$email','$phone','$cellphone', '$date_value','" . $image['name'] . "')"; I don't know what exactly I need to do? Even though I changed the setting in php ini to register_globals = On I would appreciate any kind of help regarding this matter. Thanks Smita $looponce = 1; foreach ($this->info as $k => $v) { if ( (($k == 'subject') && ($v['required'])) && (!$this->settings['customSubject'])) { for ($i = 0; $i <= 0; $i++) { $output[] = $this->display_errors('error_system_subject'); } } if ( (($k == 'name') && (!$v['required'])) || ((!array_key_exists("name", $this->info)) && ($looponce == 1)) ) { $output[] = $this->display_errors('error_system_name'); $looponce++; } } That is my loop that i check things in. What i'm more interested in is the name if statement. If currently checks for a name key in an array(below) and makes sure that it is set to required. If it's not set to required, print out a system error and die()'s. I'm looking for ways to remove the need for program errors and just change them to what is needed to run. What i know how to do is, get into the inner array, what i don't know is how to edit the data and put it back exactly as it was given to me. The inner array data can be put back in any order, but the outer array must be in exact order as it was given. above code $this->info = $formdata; $formdata = array( 'name' => array('name'=>"Full Name", 'required'=>false, 'type'=>'text'), # This needs to be required=>true, but i can't trust the user, which is why i have the error. 'telephone' => array('name'=>"Telephone", 'required'=>false, 'type'=>'phone'), ); Any help is greatly appreciated, also am i doing the foreach loop in the code above in an efficient manner or is there another way? Is there any reason why I would want to use this... Code: [Select] $_SESSION['loggedIn'] = TRUE; versus this... Code: [Select] $_SESSION['loggedIn'] = 1; (The first one is easier to read...) Debbie I am wondering if these "true" values are the same to PHP... Code: [Select] <a href="' . BASE_URL . 'members/log_in.php?addComment=true">Log In</a> Code: [Select] if (isset($_GET['addComment']) && ($_GET['addComment']==TRUE)){ Debbie Apart from the fact this can cause an infinite loop is it OK to use? $user->reset_token = $user->generate_password(32); // Make sure the token is unique while(TRUE) { $count = ORM::factory('manager')->where('reset_token', '=', $user->reset_token)->count_all(); if($count < 1) break; $user->reset_token = $user->generate_password(32); } Or would you approach the logic for this differently? Thoughts appreciated. Cheers <?php $id1 = '5' ; $id = array(1,2,3,4,5,6,7); foreach($id as $value){ if($id1==$value){ echo 'One of them matches, ' ; echo 'Do not execute command <BR>' ; } ////// if ends here } ////// loop ends here ?> How to do something if all statements are false ? like when id $id1 = '10' , ? Just a silly question. I've been using 1 and 0 to tell if something is true or false, such as if a feature is enabled or not. I see that some use the words true and false. Is there a proper way or is either way correct? Thanks! hi i have set 2 varibles, and want to echo them out if they are true, i have this script but doesnt work, please help. <?php $month=$_GET['month']; $year=$_GET['year']; If($year!=0 && $month!=0) { echo $month; echo $year; } ?> cheers matt I have a statement $account = $_SESSION['account_id']; $postedby = $account_id; /*both echo out to the same number*/ if($account == $postedby){ echo "DELETE BUTTON"; } i echo'ed out both $account and $postedby and both return 1 but the if statement fails to read as true. HELP!!! thanks in advance! Hi Not that often I play with these (and normally just a single font I use). However I am trying to generate an image with a ttf bit of text on it. No problem using Tuffy.ttf (the normal one I use), but I want to use some arrow characters which it doesn't support. I have tried using Wingding and Webdings but neither work with GD. Am I missing something (hopefully something obvious)? All the best Keith Hey here is my code im trying to redirect the index.php to index.php?id=1 the way i have done it doesn't look really good is there a better way to do it please? im trying to redirect to id=1 because otherwise i wont be able to echo out anything... id 1 is default category so is there a way to tell it if $id is empty echo from id 1? <?php $id = $_GET['id']; if($id == ''){ echo "<meta http-equiv=Refresh content=0;url=index.php?id=1>"; } $result = mysql_query("SELECT * FROM pages WHERE id='$id' ",$connect); while($row = mysql_fetch_assoc($result)) { echo $row['anything1']; echo $row['anything2']; } ?> Hi, Apologies if this is rather easy but wondered how you would get around the following problem. I have a post being sent on a checked form that has the name set to a value used in my DB, for example: Code: [Select] <input type="checkbox" name="<?PHP echo $rows ["catID"] ?>"> Where name would equal something like 11. I'm trying to right some code that inserts data from the rows that have been checked, bit like the below: Code: [Select] while($rows = $database->fetch_array($result)){ $strSQL='INSERT INTO affiliate_join_cat (ajcCatID, ajcAffID) VALUES ('.$rows["catID"].', '.$_POST["affID"].')'; if ($_POST($rows["catID"])=="on"){ $database->query($strSQL); so my post will look something like 11 = on, dependent on the row checked. But there is something wrong with this part of the code: Code: [Select] $_POST($rows["catID"])=="on" my thoughts are that until catID actually equals 11 this does not evaluate to anything? So have tried using empty and isset to handle it without any success. Not sure what to do next? Thanks in advance so im trying this
$file is not a .txt file
if ($file != "." && $file != ".." && !is_dir("uploads/$fuser/$file") && (pathinfo("uploads/$fuser/$file", PATHINFO_FILENAME)!= "txt")
i tried this but doesnt work
I'm pulling my hair out trying to figure out a simple problem. I've got the following PHP code in an HTML page: $shutoff_date = strtotime($wkend_start_date) - 259200; if ($shutoff_date > $todays_date) { $current_month = date("m"); $current_year = date("y"); $freshman_eligible = 0; if ($current_month >= 2 && $current_month <=7) { $freshman_eligible = 1; } if ($current_month <= 7) { $seniors = $current_year ; } else {$seniors = $current_year + 1; } $juniors = $seniors + 1; $sophomores = $seniors + 2; $freshman = $seniors + 3; echo "HTML Stuff blah, blah, blah"; if ($freshman_eligible = 1) { echo "<option value=\"$freshman\">$freshman</option>";} } The last test to see if $freshman_eligible is equal to 1 is always testing true, and it's actually resetting $freshman_eligible to whatever I put inside the IF statement. No matter what the variable is set to previously, it will reset to whatever I test for in the last section, and hence always tests true. I thought maybe it was an issue with scope, but I'm not sure what the issue would be or how to resolve it. What am I missing??? Hi. I have a simple change password form, when checked and verified and submitted the user is directed to a different web page. I'm getting all the true statements echoed out, but it doesn't go to the go to the next web page. // Thank you Page $insertGoTo = "changepass.php"; header(sprintf("Location: %s", $insertGoTo)); My thought was ounce you get through the while statement without errors you should be able to move to the next check of the actual database... which it does, and it updates the database with the new values. It also echos out Continue 6.... echo "True - Continue 6 GO TO HEADER PAGE"; // Thank you Page $insertGoTo = "changepass.php"; header(sprintf("Location: %s", $insertGoTo)); What am I missing here? Code: <?php session_start(); ?> <?php $submit = $_POST['submit']; // Form Data $email = $_POST['email']; $password_old = $_POST['password_old']; $password_new = $_POST['password_new']; $password_new_con = $_POST['password_new_con']; $errorcount = 0; // Edit anything inbetween the " " for the display error message $errormsg['Email'] = "Email Entered is not in our database"; $errormsg['OldPass'] = "Old Password Entered is Incorrect. Please check your Email"; $errormsg['NewPass'] = "New Password must be between 6 and 32 characters"; $errormsg['NewPassCon'] = "New Passwords do not match."; $errormsg['SecCode'] = "Security Code is Invalid"; $errormsg['dbPass'] = "Invalide Email or activation code. Please Contact <a href='mailto:webmaster@fusionfashionhair.com?subject=Fusion Fashion Hair - Member Activation Error%20Request'>Admin</a>"; $errormsg['NoErr'] = "No Errors, Continue"; $errormsg['PlaceHold'] = ""; $errortrack[] = $errormsg['PlaceHold']; if ($_POST[submit]){ if ($errorstop = "go") { $errorstop="go"; while ($errorstop<>"stop") { //Check for security code if ($_SESSION[key]==$_POST[user_code]){ echo "True - Continue 0"; echo "<p>----------</p>"; $_SESSION[key]=''; } else { echo "False - Stop 0"; $errortrack[] = $errormsg['SecCode']; $errorcount++; $errorstop="stop"; } // check for existance if (!checkEmail($email)) { echo "False - Stop 1"; $errortrack[] = $errormsg['Email']; $errorcount++; $errorstop="stop"; } else { echo "True - Continue 1"; echo "<p>----------</p>"; } // check for existance if (strlen($password_old)>5) { echo "True - Continue 2"; echo "<p>----------</p>"; } else { echo "False - Stop 2"; $errortrack[] = $errormsg['OldPass']; $errorcount++; $errorstop="stop"; } // check for existance if (strlen($password_new)>32||strlen($password_new)<6) { echo "False - Stop 3"; $errortrack[] = $errormsg['NewPass']; $errorcount++; $errorstop="stop"; } else { echo "True - Continue 3"; echo "<p>----------</p>"; } // check for existance if ($password_new_con==$password_new) { echo "True - Continue 4"; echo "<p>----------</p>"; $errorstop="stop";//Get Out of loop } else { echo "False - Stop 4"; $errortrack[] = $errormsg['NewPassCon']; $errorcount++; $errorstop="stop"; } }//End While Loop // Check database require('dbConfig.php'); // Encrypts old password to check with Database Encryped Password $password_old = md5($password_old); $check = mysql_query("SELECT * FROM {$usertable} WHERE email='$email' AND password='$password_old'"); $checknum = mysql_num_rows($check); if ($checknum==1) { echo "True - Continue 5 Set password"; echo "<p>----------</p>"; // Encrypts new password $password = md5($password_new); //run a query to update the account $acti = mysql_query("UPDATE {$usertable} SET password='$password' WHERE email='$email'"); } else { echo "False - Stop 5"; $errortrack[] = $errormsg['dbPass']; $errorcount++; $errorstop="stop"; }//End if checknum echo "True - Continue 6 GO TO HEADER PAGE"; // Thank you Page $insertGoTo = "changepass.php"; header(sprintf("Location: %s", $insertGoTo)); } else { while($errorcount>=0) { // Test display all error messages echo "<p>----------</p>"; echo "<p>Error Count = '$errorcount'</p>"; } die ("PLEASE FILL IN ALL FIELDS"); } } ?> <?php // LINUX PLATFORM OPTION 3 // checkEmail function checks standard email format same as preg_match() // checkEmail function checks DSN records using checkdnsrr Use list() to seperate name and domain using split function // checkdnsrr ONLY WORKS on LINUX PLATFORM // Check to see if domain and username is active // uses fsockopen() to check if its in use using port 25 function checkEmail($email) { // checks proper syntax if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $email)) { // gets domain name list($username,$domain)=split('@',$email); // checks for if MX records in the DNS if(!checkdnsrr($domain, 'MX')) { return false; } return true; } return false; } ?> I had some code that I'm pretty sure used to work, basically something like the below. Code: [Select] if (preg_match("/[a-zA-Z0-9]+/", $_POST['title'])) { echo $_POST['title'];exit(); } Now i just don't get why it always returns true, even when entering special characters like "!#%?".. The only thing which comes to mind, is that i recently made a move to UTF-8.. Hello Was wanting you know if anyone had come across a method whereby the following occurs: On editing an existing record pulled back on a form, if a checkbox is change to TRUE (ticked) and then the record is submitted to update the database, then it should also record the date/time in a particular field e.g. 'checkboxupdate'. I already have a general update time/date field but this is updated whenever a record is updated. I want the new 'checkboxupdate' field to only be updated with the date/time when the submission includes the change to write TRUE to the checkbox field. As an aside I would need to ensure that the checkbox is read only if the value pulled back from the recordset is true........ Hope this makes sense. Thanks Demetri How do I execute display.php if condition is true? I have only included relevant code. $query = "SELECT * FROM airplanes WHERE ama='$ama'"; if (mysql_num_rows($result) == 0) { //print error message if (mysql_num_rows($result) == 1) { // execute display.php. How do I do this? I do plan on changing the 2 ifs to if/else |