i need help in tht the following code, it doesnt add the content in the database, i dnt noe wht went wrong in the code need help , i need help in the add content function, i guess something is wrong in the loop bt cnt figure it out wht
<?php
class database_connect {
var $host;
var $username;
var $password;
var $con;
var $db;
function connect() {
$con = mysql_connect($this->host, $this->username, $this->password) or die(mysql_error());
mysql_select_db($this->db, $con) or die(mysql_error());
}
function get_content($id ='') {
if($id != ''):
$id = mysql_real_escape_string($id);
$sql= "SELECT * FROM info WHERE id = '$id'";
$ret = '<p><a href="index.php">Go back to content</a></p>';
else:
$sql= "SELECT * FROM info ORDER BY id DESC";
endif;
$res = mysql_query($sql) or die (mysql_error());
if(mysql_num_rows($res) != 0):
while ($row = mysql_fetch_assoc($res)){
echo '<h1> <a href="index.php?id=' . $row['id'] . '">' . $row['title'] . '</a> </h1>';
echo '<p>' . $row['body'] . '</p>';
}
else :
echo '<p>doesnt exist</p>';
endif;
echo $ret;
}
function add_content($p) {
$title = mysql_real_escape_string($p['title']);
$body = mysql_real_escape_string($p['body']);
if(!$title || !$body):
if(!$title):
echo "<p>The title Is Required</p>";
endif;
if(!$body):
echo "<p>The body Is Required</p>";
endif;
echo '<p><a href="add-content.php">Try Again</a></p>';
else:
$sql = "INSERT INTO info VALUES (null, '$title' , '$body')";
$res = mysql_query($sql) or die(mysql_error());
echo "Added Sucessfully";
endif;
}
//End of class
}
?>