從資料庫中檢索搜索結果的 php 腳本在我的本地計算機(XAMPP 服務器)上完美運行但是在我的虛擬主機上運行它顯示 HTTP 錯誤 500(當前無法處理此請求。)它在本地服務器上完美運行但是拒絕在我的網站上作業。
這是代碼
/*dbconnect file */
<?php
$servername='localhost';
$username="x";
$password="x";
try
{
$con=new PDO("mysql:host=$servername;dbname=advitrea_app_advit_mis_crm",$username,$password);
$con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
//echo 'connected';
}
catch(PDOException $e)
{
echo '<br>'.$e->getMessage();
}
?>
這是主要的搜索資料庫檔案:
<?php
include 'connectdb_viewcontact.php';
$searchErr = '';
$contact_details='';
if(isset($_POST['save']))
{
if(!empty($_POST['search']))
{
$search = $_POST['search'];
$stmt = $con->prepare("select * from advitrea_app_advit_mis_crm where First_Name like '%$search%' or Last_Name like '%$search%'");
$stmt->execute();
$contact_details = $stmt->fetchAll(PDO::FETCH_ASSOC);
//print_r($contact_details);
}
else
{
$searchErr = "Please enter the information";
}
}
?>
<html>
<head>
<title>view contact</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
.container{
width:70%;
height:30%;
padding:20px;
}
th, td {
padding-top: 10px;
padding-bottom: 20px;
padding-left: 30px;
padding-right: 40px;
}
</style>
</head>
<body>
<div class="container">
<h3><u>View Contact by entering First/Last Name</u></h3>
<br/><br/>
<form class="form-horizontal" action="#" method="post">
<div class="row">
<div class="form-group">
<label class="control-label col-sm-4" for="email"><b>Search contact Information:</b>:</label>
<div class="col-sm-4">
<input type="text" class="form-control" name="search" placeholder="search here">
</div>
<div class="col-sm-2">
<button type="submit" name="save" class="btn btn-success btn-sm">Submit</button>
</div>
</div>
<div class="form-group">
<span class="error" style="color:red;">* <?php echo $searchErr;?></span>
</div>
</div>
</form>
<br/><br/>
<h3><u>Search Result</u></h3><br/>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>#</th>
<th>customer ID</th>
<th>Date</th>
<th>Salutation</th>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th>Address</th>
<th>Pincode</th>
<th>Mobile No1</th>
<th>Mobile No2</th>
<th>Email Id</th>
<th>Birthday</th>
<th>Education</th>
<th>Type</th>
<th>Customer Profile</th>
<th>Industry</th>
<th>Company Name</th>
<th>Company Website</th>
<th>Designation</th>
<th>Annual Income</th>
</tr>
</thead>
<tbody>
<?php
if(!$contact_details)
{
echo '<tr>No data found</tr>';
}
else{
foreach($contact_details as $key=>$value)
{
?>
<tr>
<td><?php echo $key 1;?></td>
<td><?php echo $value['Customer_ID'];?></td>
<td><?php echo $value['Date'];?></td>
<td><?php echo $value['Salutation'];?></td>
<td><?php echo $value['First_Name'];?></td>
<td><?php echo $value['Middle_Name'];?></td>
<td><?php echo $value['Last_Name'];?></td>
<td><?php echo $value['Address'];?></td>
<td><?php echo $value['Pin_Code'];?></td>
<td><?php echo $value['Mobile_No_1'];?></td>
<td><?php echo $value['Mobile_No_2'];?></td>
<td><?php echo $value['Email_Id'];?></td>
<td><?php echo $value['Birthday'];?></td>
<td><?php echo $value['Education'];?></td>
<td><?php echo $value['Type'];?></td>
<td><?php echo $value['Customer_Profile'];?></td>
<td><?php echo $value['Industry'];?></td>
<td><?php echo $value['Company_Name'];?></td>
<td><?php echo $value['Company_Website'];?></td>
<td><?php echo $value['Designation'];?></td>
<td><?php echo $value['Annual_Income'];?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</div>
</body>
uj5u.com熱心網友回復:
在頁面頭部設定啟用以除錯 PHP 錯誤:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/530863.html
