Hi
I want to create an admin section which i will be able to edit the content of my site
I have a simple mysql class but i need to implement this on my sql statement when i query tables i dont want to use this $result = mysql_query($sql); but use
$result = $conn->execute_query($sql
pls help
class_mysqlconn.php
<?php
class MySqlConn {
var $mysqlconn;
var $sel_result;
function connect_to_dbase($user, $passwd, $host, $dbase)
{
$this->mysqlconn = $this->connect($user, $passwd, $host);
mysql_select_db($dbase, $this->mysqlconn);
}
function connect($user, $passwd, $host)
{
return mysql_connect($host, $user, $passwd);
}
function execute_query($sel_query)
{
$this->sel_result = mysql_query($sel_query, $this->mysqlconn) or die(mysql_error());
return $this->sel_result;
}
function execute_nonquery($query)
{
if((mysql_query($query, $this->mysqlconn)))
{
return true;
}
else
{
return false;
}
}
function close_conn()class
{
mysql_close($this->mysqlconn);
}
function fixSqlString($str, $find, $replace) {
$ret = "";
for ($x = 0; $x < strlen($str); $x += 1) {
if ($str{$x} == $find) {
$ret = $ret.$replace;
}
else {
$ret = $ret.$str{$x};
}
}
echo "$str-$ret";
return $ret;
}
}
?>
get_values.php
<?php
include('db.php');
include("class_mysqlconn.php");
$conn = new MySqlConn();
$conn->connect_to_dbase($user, $passwd, $host, $dbase);
global $conn;
// Get details from database
if (!($connect_to_dbase())) {
$displayError = messageDisplay($errorMessage['cannot_connect_to_db'],"error");
echo "</tr></table>
$displayError
<table><tr>";
} else {
$startVal = $start - 1;
$sql = "SELECT contentBlockID, name, title, content
FROM contentBlocks $condition ORDER BY $orderBy LIMIT $startVal, $maxDisplay";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)){
$contentBlockID = $row[0];
$name = $row[1];
$title = $row[2];
$content = $row[3];
$contentDisplayed = $content;
$contentDisplayed = strip_tags($content);
$contentDisplayed = (strlen($contentDisplayed) > 200) ? substr($contentDisplayed,0,200)."..." : "$contentDisplayed";
$edit = '<div style="position: absolute; "><form action="content_block_details.php" method="post"><input type="hidden" value="'.$contentBlockID.'" name="contentBlockID"></div>'
. '<input class="adminButton2" type="submit" value="Edit" onclick="this.form.action=\'content_block_details.php\';">';
$delete = '<input class="adminButton2" type="button" value="Delete" onclick="if (confirm(\'Please note: the information will be deleted from the database.\nAre you sure you want to delete this content block?\')) {this.form.action = \'content_block_delete.php\'; this.form.submit();}">';
$class = ($class == "adminRow1") ? "adminRow2" : "adminRow1";
echo '<tr class="'.$class.'">'
.'<td>'.$contentBlockID.'</td>'
.'<td>'.$name.'</td>'
.'<td>'.$title.'</td>'
.'<td>'.$contentDisplayed.'</td>'
.'<td style="text-align: center">'.$edit.'</td>'
.'<td style="text-align: center">'.$delete.'</td><div style="position: absolute; "></form></div></td>'
.'</tr>';
}
}
?>