Jump to content


New Members
  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About David-London

  • Rank
  1. Hi, I have this array: $cats = array( "A"=>'Business Expansion Specialist', "B"=>'Affiliate Page', "C"=>'Personal: Hobbies', "D"=>'Personal: Pets', "E"=>'Personal: Holidays', "F"=>'Personal: Sport', "G"=>'Personal: C.V.', "H"=>'Personal: Other', "I"=>'For Sale: Antiques', "Z"=>'Other' ); And then from a table I get the variable $cat_cd. $cat_cd contains 'F' so it refers to 'Personal: Sport' If I want to put that in $category, how would I write that? I thought it might be .... $category = $cats['$cat_cd']; I tried that and it didn't work . Thanks
  2. Thanks for he replies.I am converting from the old mysql_query to prepared statements with PDO so sorry for the basic questions !I usually try to research and find the answer and then post the problem.Sometimes that leads to a debate based around the (incorrectly) chosen method/function that I posted. Which I think happened here Maybe using a couple of simple examples will help me understand this. Examples:So. I have a table named cars.The column "plate" is the Primary Index.Other columns are not indexed See image attached.Environment:CENTOS 7.6 kvm [server] v80.0.15 Server Version: Apache/2.4.39Server version: 5.7.26 - MySQL Community Server (GPL)Server charset: UTF-8 Unicode (utf8)PHP version: 7.2.71) Assume there is a form which allows the userto enter a color name. So from that POST we geta variable $color.I want to ask the db if there is a row with color equal to $color in the table carsAnswer should be yes/no What should I use ?2) Secondly, a different script.I get the $color from the form and this time I want to ask ...~"how many rows have color equal to $color"I'd like the answer as 0 or 1 or 2 etc.Do I have to ask if there is a row first, (as in question 1) and then do a count on them if there is data or not ?What should be the code for this?3) Now I have another different form and it lets me enter the plate number (which is indexed)I get $plate variable.I just want to ask same as question (1) Is there a row with plate == $plate in table carsyes or no.I want to know if the code in (3) differs from (1) because of the index.Rather, than write the code I think it should be (like I did before), may I ask what you think it should beso that I can understand clearly? Hopefully I will "get" it.Many thanks
  3. Hi, I have two scripts using almost identical code. One of them works and finds the field (email) - the PRIMARY KEY (email) and the other doesn't (user_key) - not indexed Is this because PHP 7 needs to use only indexes in the WHERE part of SQL Query? Here are the two scripts - first one works $sql = 'SELECT access,fname FROM clients WHERE email=?'; $stmt = $connect->prepare($sql); $stmt->execute([$email]); $data_exists = ($stmt->fetchColumn() > 0) ? true : false; if ($data_exists) { // account found. $row = $stmt->fetch(); $access = $row['access']; $fname = $row['fname']; } else { $err_msg = 'Invalid Email Address and/or Password.'; $email = ''; $pass = ''; require_once ("login_fm.php"); exit; } [/PHP] This second one drops through to the ERROR page. $sql = 'SELECT email,fname,lname,confirm FROM clients WHERE user_key=?'; $stmt = $connect->prepare($sql); $stmt->execute([$the_key]); $data_exists = ($stmt->fetchColumn() > 0) ? true : false; if ($data_exists) { // Account found. $row = $stmt->fetch(); $email = $row['email']; $name = $row['fname'].' '.$row['lname']; $confirm = $row['confirm']; $_SESSION['auth'] = "yes"; $_SESSION['email'] = $email; $_SESSION['name'] = $name; $sql = 'UPDATE clients SET confirm = ?,log_count = log_count+1,last_date=? WHERE email=?'; $stmt= $connect->prepare($sql); $stmt->execute(['y',$today_time,$email]); require_once("index.php"); // SUCCESSFUL LOGIN: THIS LOADS THE START PAGE exit; } // end if else { $err_page_message = "ERROR - Account not found $the_key : $name"; require_once("err.php"); exit; } // end else May be it's a different reason - like I'm too tied ! On the second one. I could rewrite it to just try the update and fail-over to the ERROR page, But it would be nice to know why it isn't working. It's quite simple, I just want to check to see if a row exists with the condition given, that's all. I never had this problem the old mysql but the PDO seems a bit tricky or I'm just using the wrong code lol. Thanks
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.