php - PDO Statement Not Setting Values -



php - PDO Statement Not Setting Values -

i'm trying run pdo update statement, none of fields beingness updated. here pdo query. i've gone through , tried find values beingness changed , found beingness assigned nothing. found problem right when values escaped (you'll see comment placed there). know i'm overlooking haven't been able figure out yet.

if(isset($_post['submit'])) { if(isset($_post['name'])){ $name = $_post['name'];}else{ $name = '';} if(isset($_post['city'])){ $city = $_post['city'];}else{ $city = '';} if(isset($_post['state'])){ $state = $_post['state'];}else{ $state = '';} if(isset($_post['address_line1'])){ $address_line1 = $_post['address_line1'];}else{ $address_line1 = '';} if(isset($_post['address_line2'])){ $address_line2 = $_post['address_line2'];}else{ $address_line2 = '';} if(isset($_post['city'])){ $city = $_post['city'];}else{ $city = '';} if(isset($_post['state'])){ $state = $_post['state'];}else{ $state = '';} if(isset($_post['zip_code'])){ $zip_code = $_post['zip_code'];}else{ $zip_code = '';} if(isset($_post['last_modified_by'])){ $last_modified_by = $_post['last_modified_by'];}else{ $last_modified_by = 'admin';} $last_modified_date = date('y-m-d h:i:s'); $confirmcode = 'y'; if(isset($_post['bitactive'])){ $bitactive = $_post['bitactive'];}else{ $bitactive = '';} //test portion 1 = values right // echo $address_line1 . "<p>"; // echo $city . "<p>"; // echo $zip_code . "<p>"; // exit; $support_broker_id = $_get['id']; $user_exists = "select * lu_agency agency_id =". $support_broker_id; $statement = $conn->query($sql); $result = $statement->fetch(); $count = $statement->rowcount(); $name = $row['name']; $address_line1 = $row['address_line1']; $address_line2 = $row['address_line2']; $city = $row['city']; $state = $row['state']; $zip_code = $row['zip_code']; $last_modified_by = $row['last_modified_by']; $last_modified_date = $row['last_modified_date']; $bitactive = $row['bitactive']; //test portion two: values right // echo $address_line1 . "<p>"; // echo $city . "<p>"; // echo $zip_code . "<p>"; // exit; if($count > 0) { $sqlupdate = "update lu_agency set name = :name, address_line1 = :address_line1, address_line2 = :address_line2, city = :city, state = :state, zip_code = :zip_code, last_modified_by = :last_modified_by, last_modified_date = :last_modified_date, bitactive = :bitactive agency_id= ". $support_broker_id; //here $city , $support_broker_id have values, others don't show echo $address_line1 . "<p>"; echo $city . "<p>"; echo $zip_code . "<p>"; echo $support_broker_id . "<p>"; exit; $preparedstmt = $conn->prepare($sqlupdate); $preparedstmt->execute( array( ':name'=>$name, ':address_line1'=>$address_line1, ':address_line2'=>$address_line2, ':city'=>$city, ':state'=>$state, ':zip_code'=>$zip_code, ':last_modified_by'=>$last_modified_by, ':last_modified_date'=>$last_modified_date, ':bitactive'=>$bitactive ) ); header("location: http://173.254.127.52/~avenuet7/supporttables.php?msg=1"); } }

$row undefined. should $result:

$result = $statement->fetch(pdo::fetch_assoc); // declared `$result` not `$row`

and why not utilize prepared statements through out:

$user_exists = "select * lu_agency agency_id =". $support_broker_id; // still straight injecting?

final look:

$support_broker_id = $_get['id']; $user_exists = "select * lu_agency agency_id = :support_broker_id "; // not `$sql` utilize `$user_exists`! $statement = $conn->prepare($user_exists); $statement->bindparam(':support_broker_id', $support_broker_id); $statement->execute(); $count = $statement->rowcount(); if($count > 0) { $result = $statement->fetch(pdo::fetch_assoc); $sqlupdate = " update lu_agency set name = :name, address_line1 = :address_line1, address_line2 = :address_line2, city = :city, state = :state, zip_code = :zip_code, last_modified_by = :last_modified_by, last_modified_date = :last_modified_date, bitactive = :bitactive agency_id = :support_broker_id "; $preparedstmt = $conn->prepare($sqlupdate); $preparedstmt->execute( array( ':name' => $result['name'], ':address_line1' => $result['address_line1'], ':address_line2' => $result['address_line2'], ':city' => $result['city'], ':state' => $result['state'], ':zip_code' => $result['zip_code'], ':last_modified_by' => $result['last_modified_by'], ':last_modified_date' => $result['last_modified_date'], ':bitactive' => $result['bitactive'], ':support_broker_id' => $support_broker_id, )); header("location: http://173.254.127.52/~avenuet7/supporttables.php?msg=1"); }

sidenote: add together after making connection:

$conn->setattribute(pdo::attr_errmode, pdo::errmode_exception);

php mysql pdo

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -