gpt4 book ai didi

php - 编译 PHP 和 PostgreSQL 后页面空白

转载 作者:行者123 更新时间:2023-11-29 13:20:07 24 4
gpt4 key购买 nike

问题

编译此代码后,我在显示页面时遇到问题,但我看不出它有什么问题,而且由于它没有出现在网络上,所以我无法调试。

PHP 和 PostgreSQL 代码:

<?php       
// Connecting, selecting database
$dbconn = pg_connect("host=***** port=*****
dbname=***** user=***** password=*****")
or die('Could not connect: ' . pg_last_error());

//collect
if(isset($_POST['search'])) {
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i"."".$searchq);

// Performing SQL query
$query = "SELECT * FROM enumbers WHERE code LIKE '%$searchq%'") or die ("could not search!");
$result = query($query);
if($result = 0){
$output = 'There is no such E-Number!'
}else{
while($row = mysql_fetch_array($query)) {
$code = $row['code'];
$name = $row['name'];
$type = $row['type'];
$vegan = $row['vegan'];

$output .= '<div> '.vegan.' ';
}
}
}
?>

表格和打印代码:

 <div id="tablebox">
<!-- Search bar -->
<p>Is It Vegan?</p>
<form name="form1" method="post" action="searchEnumbers.php">
<input name="search" type="text" size="30" maxlength="5" />
<input name="submit" type="submit" value="Search" />
</form>

<?php
print("$output");
?>
</div>

更新

我认为问题可能是我正在使用一些 MySQL 代码,但我无法判断是否是。

最佳答案

您正在使用 mysql_fetch_array 而不是 postgres 方法。请看样本

    <?php 
// Connecting, selecting database
$dbconn = pg_connect("host=**** port=****
dbname=**** user=**** password=****")
or die('Could not connect: ' . pg_last_error());
$output = '';

//collect
if(isset($_POST['search'])) {
$searchq = $_POST['search'];
// $searchq = preg_replace("#[^0-9a-z]#i"."".$searchq);

// Performing SQL query
$query = "SELECT * FROM enumbers WHERE code LIKE '%$searchq%'";
$ret = pg_query($dbconn, $query);
if(!$ret){
echo pg_last_error($dbconn);
exit;
}
$output = '';
while($row = pg_fetch_assoc($ret)){
$code = $row['code'];
print_r($row);
$name = $row['name'];
$type = $row['type'];
$vegan = $row['vegan'];

$output .= '<div> '.vegan.' ';
}
}
echo "Operation done successfully\n";
pg_close($dbconn);

?>

关于php - 编译 PHP 和 PostgreSQL 后页面空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43501972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com