how to fetch data from table using php and mysql -


i trying fetch email particular row or based on id_code people table... is, enter id_code = 456, if id code exists email of specific id_code has retrieved, , generate token number , insert token number people table. after token generated , inserted, url link has sent token , id.

how since beginner, can tell me going wrong?

here did far:

<?php     error_reporting(1);     session_start();      include 'includes/db.php';     include 'includes/token.php';      //global     $id_code = strtoupper(trim($_post['id_code']));      if ($_post["submit"] == "submit") {         $sql = "select * people id_code = :id_code";         $stmt = $pdo->prepare($sql);         $stmt->bindvalue(':id_code', $id_code);         $stmt->execute();         $result = $stmt->fetch(pdo::fetch_assoc);         if (!empty($_post['id_code'])) {             $sql = "select email people id_code = $id_code";              $stmt = $pdo->prepare($sql);             $stmt->bindvalue(':id_code', $id_code);             $stmt->execute();             $result2 = $stmt->fetch(pdo::fetch_assoc);         } else {             //echo "<br/>validated: false<br/>"; die();             echo 'you not registered..please contact support';         }     } ?> 

as far can see $id_code not defined. value might want use stored in $_post['id_code'] should $id_code = $_post['id_code']; in front of if condition, otherwise $id_code undefined.

update: did $ccode, use binding , should work.

$stmt->bindvalue(':id_code', $id_code); 

replaced by

$stmt->bindvalue(':id_code', $ccode); 

update

please try following code , post result of var_dump():

<?php     error_reporting(1);     session_start();      include 'includes/db.php';     include 'includes/token.php';      //global     $id_code = strtoupper(trim($_post['id_code']));      var_dump("id: ".$id_code);      if ($_post["submit"] == "submit") {         $sql = "select * people id_code = :id_code";         $stmt = $pdo->prepare($sql);         $stmt->bindvalue(':id_code', $id_code);         $stmt->execute();         $result = $stmt->fetch(pdo::fetch_assoc);          var_dump("result: ".$result);          if (!empty($_post['id_code'])) {             $sql = "select email people id_code = $id_code";              $stmt = $pdo->prepare($sql);             $stmt->bindvalue(':id_code', $id_code);             $stmt->execute();             $result2 = $stmt->fetch(pdo::fetch_assoc);              var_dump("result2: ".$result2);          } else {             //echo "<br/>validated: false<br/>"; die();             echo 'you not registered..please contact support';         }     } ?> 

do output script?


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -