Thursday 19 October 2017

php - Fatal error: Uncaught PDOException

itemprop="text">

I am having below error when trying to
delete an item.





Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or

view not found: 1146 Table 'databaseName.tableName' doesn't exist in

/storage/h1/735/500735/public_html/delete.php:21 Stack trace: #0

/storage/h1/735/500735/public_html/delete.php(21):
PDOStatement->execute()
#1 {main} thrown in

/storage/h1/735/500735/public_html/delete.php
on line 21




Note :
tableName here is
tblcart



delete.php




session_start();
require("dbconfig.php");

if
(isset($_GET['delete_id'])) {
$stmt_select = $DB_con->prepare('SELECT *
FROM tblcart WHERE productID =:id');

$stmt_select->execute(array(':id'=>$_GET['delete_id']));

$result=$stmt_select->fetch(PDO::FETCH_ASSOC);

$stmt_delete =
$DB_con->prepare('DELETE FROM tblCart WHERE productID =:id AND userID
=:userID');
$stmt_delete->bindParam(':id',$_GET['delete_id']);

$stmt_delete->bindParam(':userID',$_SESSION['userid']);

$stmt_delete->execute();


header("Location:
cart.php");

}
?>


Refer
to the error note, error occured on line
$stmt_delete->execute(); . If I run the code through my
local pc localhost it functioning well but when running on web hosting server I am
getting this error.



EDIT
:



Here is the
dbconfig.php




dbconfig.php





$DB_HOST = 'localhost';
$DB_USER = 'root';
$DB_PASS =
'password';
$DB_NAME = 'databaseName';



try{
$DB_con = new
PDO("mysql:host={$DB_HOST};dbname={$DB_NAME}",$DB_USER,$DB_PASS);

$DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

}
catch(PDOException $e){
echo $e->getMessage();

}
?>

class="post-text" itemprop="text">
class="normal">Answer





Database and table
names
on Linux servers, case-sensitive is
"on".



Database and table
names
on Windows servers, case-sensitive is
"off".



This is why
it works on your computer(windows) and not on the web hosting
server(linux)



Change the delete statement from :



$stmt_delete =
$DB_con->prepare('DELETE FROM tblCart WHERE productID =:id AND userID
=:userID');



To
:



$stmt_delete =
$DB_con->prepare('DELETE FROM tblcart WHERE productID =:id AND userID
=:userID');


Difference
is tblCart to tblcart
.



Reference href="https://stackoverflow.com/a/6134059/6140684">here.



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...