[英]Selecting ID from url returns NULL data
I have functions page and details.php. 我有功能页面和details.php。
Functions Page: 功能页面:
function getDetails(){
$con = new Core();
$con->connect();
$param = $_GET['autoid'];
$sql = 'SELECT * FROM auto WHERE autoid=?';
$stmt = $con->myconn->prepare($sql);
$stmt->bind_param("i", $param);
$stmt->execute();
}
home.php: home.php:
<?php
$details = new Details();
$result = $details->showDetails();
while ($row = mysqli_fetch_assoc($result)) {
$id=$row['autoid'];
?>
<tr>
<td><?php echo '<a href="details.php?autoid='.$id.'">
<img src="data:image/jpeg;base64,'.base64_encode($row['foto'] ).'"/></a>'; ?>
</td>
</tr>
<?php }
mysqli_free_result($result);
?>
details.php: details.php:
$details = new Details();
$result = $details->getDetails();
var_dump($result);
When I'm in my home.php I press on a picture and get redirected to details.php. 当我在home.php中时,按一下图片并重定向到details.php。 When I'm there I got the ID in my url and then I var dump but get returned a NULL. 当我在那里时,我在URL中获得了ID,然后我进行了var dump,但返回了NULL。
And because of that my code in details.php doesn't work : 由于这个原因,我在details.php中的代码不起作用:
while ($row = $result) {
<tr>
<td><?php echo $row['merk']; ?> </td>
I'd really appreciate some help. 我真的很感谢您的帮助。 Since I can't figure how to let it work. 由于我不知道如何让它工作。 So basically I don't get anything shown on the details page. 因此,基本上我什么都没有在详细信息页面上显示任何内容。 Besides a NULL of the var_dump. 除了var_dump为NULL外。
You're executing showDetails and not getDetails? 您正在执行showDetails而不是getDetails吗? Also your function getDetails doesn't return anything. 同样,您的函数getDetails不返回任何内容。 I suspect you have to execute getDetails and put a return in the function to make it work. 我怀疑您必须执行getDetails并在函数中添加返回值才能使其正常工作。
Functions Page: 功能页面:
function getDetails(){
$con = new Core();
$con->connect();
$param = $_GET['autoid'];
$sql = 'SELECT * FROM auto WHERE autoid=?';
if(!($stmt = $con->myconn->prepare($sql))) {
echo "Prepare failed: (" . $con->myconn->errno . ") " . $con->myconn->error;
}
if(!($stmt->bind_param("i", $param))) {
echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if(!($stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
if(!($result = $stmt->get_result()) {
echo "Getting result set failed: (" . $stmt->errno . ") " . $stmt->error;
}
return $result; // added return here
}
home.php: home.php:
$details = new Details();
$result = $details->getDetails(); //Changed this to getDetails
while ($row = mysqli_fetch_assoc($result)) {
$id=$row['autoid'];
?>
<tr>
<td><?php echo '<a href="details.php?autoid='.$id.'"><img src="data:image/jpeg;base64,'.base64_encode($row['foto'] ).'"/></a>'; ?> </td>
</tr>
execute()
only returns a Boolean on whether it was successful or not. execute()
仅返回布尔值是否成功。 you need to use get_result()
to get the actual results of the query 您需要使用get_result()
来获取查询的实际结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.