hello world! First post here!
I'm a newbie trying to make my own cms, everything is working except the import of image into the post, this becomes text.
Here is the code:
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 cms_content WHERE id = '$id'";
else:
$sql = "SELECT * FROM cms_content ORDER BY id DESC"; endif;
$return = '<a href="index.php">go back</a>';
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) != 0):
while($row = mysql_fetch_assoc($res)) {
echo '<div class="title"><h1><a href="index.php?id=' . $row['id'] . '">' . $row['title'] . '</a></h1></div>';
echo '<div class="date"><p>' . $row['date'] . '</p></div>';
echo '<div class="photo"><p>' . $row['photo'] . '</p></div>';
echo '<div class="txt"><p>' . $row['body'] . '</p></div>';
}
else:
echo '<p class="results_">uH oh!</p>';
endif;
echo $return;
}
function add_content($p) {
$title = mysql_real_escape_string($p['title']);
$date = mysql_real_escape_string($p['date']);
$photo = mysql_real_escape_string($p['photo']);
$body = mysql_real_escape_string($p['body']);
// if they write wrong
if(!$title | | !$body):
if(!$title):
echo "<p>The Title is Required</p>";
endif;
if(!$photo):
echo "<p>No photo</p>";
endif;
if(!$body):
echo "<p>The body is Required</p>";
endif;
echo '<p><a href="add-content.php">Try again</a></p>';
else:
// add to db
$sql = "INSERT INTO cms_content VALUES (null, '$title', '$date', '$photo', '$body')";
$res = mysql_query($sql) or die(mysql_error());
echo "<p class='results_'>Added with success!</p>";
// [END] add to db
endif;
// [END] if they write wrong
}
and in the html i got a form
<form enctype="multipart/form-data" method="post" action="index.php">
<input type="hidden" name="add" value="true">
<div>
<label for="title"><p>Title:</p></label>
<input type="text" name="title" id="title" />
</div>
<div>
<input type="file" name="photo"><br>
</div>
<div>
<label for="body"><p>Body:</p></label>
<textarea name="body" id="body" rows="8" cols="40"></textarea>
</div>
<input type="submit" name="submit" value="Add Content">
</form>