Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Help php

blues101

Recruit
Basic Member
Messages
2
Reaction score
0
Points
16
Patulong nmn po mga kasymbianize newbie po sa php. Maraming salamat po. Gumagana nmn po cya sa localhost. pero sa hosting yan po error.

Fatal error: Call to a member function prepare() on null in /srv/disk15/2514008/www/kawayan.co.nf/admin/Furniture.php on line 40

ito po code ko sa db:

<?php

$DB_HOST = 'fdb7.biz.nf';
$DB_USER = '2514008_kawayandb';
$DB_PASS = 'kawayan123';
$DB_NAME = 'kawayandb';

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);
return $DB_con;
}
catch(PDOException $e){
echo 'Connection failed: '.$e->getMessage();
}


at ito nmn po sa display:

<?php

$stmt = $DB_con->prepare('SELECT ID, Name, Description, Image FROM tbl_prod ORDER BY ID DESC'); // ito po ung error
$stmt->execute();

if($stmt->rowCount() > 0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
?>
<div class="col-md-3 col-sm-12 text-center" >
<p class="page-header"><?php echo $Name." / ".$Description; ?></p>
<img src="user_images/<?php echo $row['Image']; ?>" class="img-rounded" width="250px" height="250px" />

<a class="btn btn-info" href="editform.php?edit_id=<?php echo $row['ID']; ?>" title="click for edit" onclick="return confirm('Are you sure you want to edit this record ?')"><span class="glyphicon glyphicon-edit"></span> Edit</a>
<a class="btn btn-danger" href="?delete_id=<?php echo $row['ID']; ?>" title="click for delete" onclick="return confirm('Are you sure to delete this record?')"><span class="glyphicon glyphicon-remove-circle"></span> Delete</a>
</span>
</div>
<?php
}
 
Last edited:
Try mo kung gagana.


connect.php

<?php
global $DB_con;

$DB_HOST = 'fdb7.biz.nf';
$DB_USER = '2514008_kawayandb';
$DB_PASS = 'kawayan123';
$DB_NAME = 'kawayandb';


try
{
$DB_con = new PDO("mysql:host=".$DB_HOST, $DB_USER, $DB_PASS);
$DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$database = "`" . str_replace("`", "``", $DB_NAME) . "`";
$DB_con->query("CREATE DATABASE IF NOT EXISTS $database");
$DB_con->query("SET CHARACTER SET utf8");
$DB_con->query("USE $database");
$DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
}
catch(PDOException $e)
{
die($e->getMessage());
}
?>


close.php

<?php
require_once 'connect.php';
$DB_con=null;
?>




index.php

<?php
require_once 'connect.php';

$query ="SELECT ID, Name, Description, Image FROM tbl_prod ORDER BY ID DESC";
$Name="Sample";
$Description="Test only";


try
{
$select = $DB_con->prepare($query);
if($select->execute())
{
if($select->rowCount() > 0)
{
$result = $select->fetchAll(PDO::FETCH_ASSOC);
for($i =0; $i < count($result) ; $i++)
{
echo'
<div class="col-md-3 col-sm-12 text-center" >
<p class="page-header"><?php echo $Name." / ".$Description; ?></p>
<img src="user_images/<?php echo $result[$i]['Image']; ?>" class="img-rounded" width="250px" height="250px" />

<a class="btn btn-info" href="editform.php?edit_id=<?php echo result[$i]['ID']; ?>" title="click for edit" onclick="return confirm('Are you sure you want to edit this record ?')"><span class="glyphicon glyphicon-edit"></span> Edit</a>
<a class="btn btn-danger" href="?delete_id=<?php echo result[$i]['ID']; ?>" title="click for delete" onclick="return confirm('Are you sure to delete this record?')"><span class="glyphicon glyphicon-remove-circle"></span> Delete</a>
</span>
</div>';
}
}
else
{
die('No data availabe data, or matching records. <br/><br/>Query: '. $query);
}
}
}
catch (Exception $ex){return array('error'=> TRUE,'message'=> 'Execution failed, please contact system support','failure'=> $ex,'query'=> $query);}


require_once 'close.php';
?>
 
Last edited:
Back
Top Bottom