php - Call value of prepare/binded values -
i trying call $userid value @ same time of form submit. think options going through $stmt->bind_param don't know how call value.
// record payment received if (isset($_post['submit']) && $_post['submit'] == 'recordpay') { // user validations if($_post['paymentdate'] == '') { $msgbox = alertbox($paydatereq, "<i class='fa fa-times-circle'></i>", "danger"); } else if($_post['paymentfor'] == '') { $msgbox = alertbox($payforreq, "<i class='fa fa-times-circle'></i>", "danger"); } else if($_post['amountpaid'] == '') { $msgbox = alertbox($payamtreq, "<i class='fa fa-times-circle'></i>", "danger"); } else if($_post['paymenttype'] == '') { $msgbox = alertbox($paytypereq, "<i class='fa fa-times-circle'></i>", "danger"); } else { $paymentdate = htmlspecialchars($_post['paymentdate']); $paymentfor = htmlspecialchars($_post['paymentfor']); $amountpaid = htmlspecialchars($_post['amountpaid']); $paymenttype = htmlspecialchars($_post['paymenttype']); $rentmonth = htmlspecialchars($_post['rentmonth']); $rentyear = htmlspecialchars($_post['rentyear']); $notes = htmlspecialchars($_post['notes']); $propertyname = htmlspecialchars($_post['propertyname']); $leaseid = htmlspecialchars($_post['leaseid']); $userid = htmlspecialchars($_post['userid']); if ($_post['penaltyfee'] == '') { $penaltyfee = null; } else { $penaltyfee = htmlspecialchars($_post['penaltyfee']); } if ($rentmonth == '...') { $isrent = '0'; $rntmonth = null; } else { $isrent = '1'; $rntmonth = $rentmonth; } if ($rentyear == '') { $rntyear = null; } else { $rntyear = $rentyear; } $stmt = $mysqli->prepare(" insert payments( leaseid, propertyid, adminid, userid, paymentdate, amountpaid, penaltyfee, paymentfor, paymenttype, isrent, rentmonth, rentyear, notes, lastupdated, ipaddress ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), ? () "); $stmt->bind_param('ssssssssssssss', $leaseid, $propertyid, $rs_adminid, $userid, $paymentdate, $amountpaid, $penaltyfee, $paymentfor, $paymenttype, $isrent, $rntmonth, $rntyear, $notes, $ipaddress ); $stmt->execute(); $stmt->close(); want take `$userid` , associate `userid` in `users` table can echo `primaryphone` column in `users` table. want echo `primaryphone` data submitted on form. >1. call `$userid` `$stmt->bind_param` >2. associate `$userid` userid `users` table pull `primaryphone` edit: code i'm using , loading page, not returning value. placed code under $stmt->execute();
if ($stmt->execute()){ $qryphone = mysqli_query("select primaryphone users userid = '$userid'"); echo $qryphone; } and loads page, doesn't give me primaryphone value. when use
if ($stmt->execute()){ echo $userid; } then userid need, can't it.
edit: fixed.
i put code in after $stmt->close();
$qryphone = "select primaryphone users userid=".(int)$userid; $query = mysqli_query($mysqli, $qryphone); while ($fetch = mysqli_fetch_array($query)) { $primaryphone = '+1'.decryptit($fetch['primaryphone']); echo $primaryphone; }
first of all, mysqli_query() takes atleast 2 parameters, first connection handler , second query, this: mysqli_query($connection, $query)
here's reference:
second, don't mix procedural , object oriented style of mysqli.
and comes issue, first prepare statement, bind necessary parameter, execute query, bind result , fetch value.
here's reference:
so code should this:
if ($stmt->execute()){ // create prepared statement $stmt = $mysqli->prepare("select primaryphone users userid=?"); // bind parameter $stmt->bind_param("s", $userid); // execute query $stmt->execute(); // bind result variables $stmt->bind_result($primaryphone); // fetch value $stmt->fetch(); // echo primaryphone echo $primaryphone; }
Comments
Post a Comment