0
我試圖在表單提交的同時調用$userId
值。我認爲我唯一的選擇是通過$stmt->bind_param
,但我不知道如何調用這個值。準備/綁定值的調用值
// Record a 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 INTO
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();
I then want to take the `$userID` and associate it with another `userId` in the `users` table so I can echo the `primaryPhone` column in `users` table. I only want to echo the `primaryPhone` from the data submitted on the form.
>1. Call `$userId` from `$stmt->bind_param`
>2. Associate the `$userId` with userId from `users` table to pull `primaryPhone`
編輯:這是我正在使用的代碼和它的加載頁面,只是沒有返回值。我把這段代碼$stmt->execute();
if ($stmt->execute()){
$qryPhone = mysqli_query("SELECT primaryPhone FROM users WHERE userId = '$userID'");
echo $qryPhone;
}
下和加載頁面,但並沒有給我primaryPhone值。但是當我使用
if ($stmt->execute()){
echo $userId;
}
然後我得到我需要的userId,但我不能做任何事情。
編輯:固定。
我把這個代碼後$stmt->close();
$qryPhone = "SELECT primaryPhone FROM users WHERE userId=".(int)$userId;
$query = mysqli_query($mysqli, $qryPhone);
while ($fetch = mysqli_fetch_array($query)) {
$primaryPhone = '+1'.decryptIt($fetch['primaryPhone']);
echo $primaryPhone;
}
準備語句,綁定參數,執行並得到結果。這麼做阻礙了你?有什麼問題? –
讓我難以忍受的是語法,因爲每當我嘗試這樣做時,腳本就會中斷。 –
請解釋*腳本中斷*。它顯示任何錯誤? –