나는 특정 사용자 이름에 대해 mysql에서 데이터를 검색하는 PHP 스크립트를 작성했다. 사용자 이름이 선택 쿼리에 전달되고 나는 우편 배달부를 사용하여 PHP 스크립트를 검사합니다. 다음은 내 PHP 코드입니다php select query with parameter error
<?php
//getting the database connection
require_once 'MyDbConnect.php';
//an array to display response
$response = array();
//if it is an api call
//that means a get parameter named api call is set in the URL
//and with this parameter we are concluding that it is an api call
if(isset($_GET['apicall'])){
switch($_GET['apicall']){
case 'getSpecificData':
case 'getSpecificData':
if(isTheseParametersAvailable(array('your_username'))){
//getting values
$your_username = $_POST['your_username'];
$heroes = array();
$sql = "SELECT your_username,your_mobile,referral_name,referral_contact,referral_email,
loan_type,loan_amount FROM mytable WHERE your_username = ? ";
$sql->bind_param("s",$your_username);
$stmt->execute();
$stmt->bind_result($your_username, $your_mobile,$referral_name,$referral_contact,
$referral_email,$loan_type,$loan_amount);
//looping through all the records
while($stmt->fetch()){
$temp = [
'your_username'=>$your_username,
'your_mobile'=>$your_mobile,
'referral_name'=>$referral_name,
'referral_contact'=>$referral_contact,
'referral_email'=>$referral_email,
'loan_type'=>$loan_type,
'loan_amount'=>$loan_amount
];
//pushing the array inside the hero array
array_push($heroes, $temp);
}
echo json_encode($heroes);
}
break;
default:
$response['error'] = true;
$response['message'] = 'Invalid Operation Called';
}
}
else{
//if it is not api call
//pushing appropriate values to response array
$response['error'] = true;
$response['message'] = 'Invalid API Call';
}
function isTheseParametersAvailable($params){
//traversing through all the parameters
foreach($params as $param){
//if the paramter is not available
if(!isset($_POST[$param])){
//return false
return false;
}
}
//return true if every param is available
return true;
}
?>
문제는 선택 쿼리에 있습니다. 필자는 위의 PHP 코드에서 언급 한대로 select 쿼리를 작성할 때 아무 것도 얻지 못합니다. 내가 선택 쿼리를 작성하는 경우하지만 난 = "_ 이름, your_mobile, referral_name, referral_contact, referral_email, loan_type, WHERE _ 이름 = '로한'MYTABLE FROM loan_amount SELECT"를 적절한 데이터를
$의 SQL을 얻을 다음과 같이;
누군가 내게 오류의 원인을 설명해 주실 수 있습니까? 어떤 도움이라도 대단히 감사하겠습니다.
미안 당신이 봐 주시기 바랍니다 수있는 잘못된 코드를 붙여 넣습니다. 나는 질문을 편집했다. – FargoArgoCargo