Home > other >  How to resolve HTTP ERROR 500 on running this PHP script on hosting server?
How to resolve HTTP ERROR 500 on running this PHP script on hosting server?

Time:11-10

The php script to retrieve the search results from database runs perfectly on my local machine(XAMPP server) However on running it on my webhost it shows a HTTP ERROR 500(currently unable to handle this request.) It works perfectly on the local server however refuses to work on my website.

This is the code

/*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();
}
    
?>

And here is the main searchdatabase file:

<?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 >
    <h3><u>View Contact by entering First/Last Name</u></h3>
    <br/><br/>
    <form  action="#" method="post">
    <div >
        <div >
            <label  for="email"><b>Search contact Information:</b>:</label>
            <div >
              <input type="text"  name="search" placeholder="search here">
            </div>
            <div >
              <button type="submit" name="save" >Submit</button>
            </div>
        </div>
        <div >
            <span  style="color:red;">* <?php echo $searchErr;?></span>
        </div>
        
    </div>
    </form>
    <br/><br/>
    <h3><u>Search Result</u></h3><br/>
    <div >          
      <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>

CodePudding user response:

Set enable in head of page for debugging PHP errors:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
  • Related