I was shocked at the response I got from this community. Its awesome!
<?php
require("tableusers.php");
require("config.php");
echo "CONNECTED TO DATABASE1";
$result = mysql_query("SELECT type, avatar FROM users WHERE username=".$id."");
while($row = mysql_fetch_array($result)){
$avatar = $row['avatar'];
$type = $row['type'];
echo "AVATAR:".$row['avatar']."<br /> TYPE:
".$row['type']."<br />";
}
echo 'Logged in as:'.$id.'<br />
Type: '.$type.'<br />
avatar:<img src="'.$avatar.'">';
if( $type == "admin"){
mysql_close($db);
$contents = $_POST['contents'];
$title = $_POST['title'];
$date = date(d, m, Y, g, i, s, a);
echo "$date";
$id = $username;
echo "Attempt 1 SAVING:
".$title."<br />
WITH CONTENTS: ".$contents."<br />";
$avatar = $row['avatar'];
require("tableblogposts.php");
require("config.php");
echo "CONNECTED TO DATABASE2";
$query = "INSERT INTO blogposts (title, contents, by, avatar, date)
VALUES('$title', '$contents', '$username', '$avatar', '$date')";
mysql_query($query);
echo "SAVED";
echo '<meta HTTP-EQUIV="REFRESH" content="5; url=index.php?message=BLOG+SAVED!">';
}else{
echo "NOT PERMITTED TO VIEW THIS";
}
?>
This is to save a blog post.
What I want it to do is.
Open up the users table and read the "TYPE" and "AVATAR" feilds and save them on a string. Then I wanted to check if the users "TYPE" is admin. if it is then it goes on...
Then I want to close the table and open up the blog post table. where I want the
title, contents, date, avatar, by to be saved. and then redirect to the index page where it will show the message "BLOG SAVED"
I've made it echo all the data because I wanted to see where it goes wrong.
BTW this is the form:
<form name="newblog" action="saveblog.php" method="post">
<b>Blog Title: </b><input type="text" name="title"><font color="red">*</font><br />
<b>Content: </b><textarea name="contents" wrap="physical" rows="15" cols="20">
</textarea><font color="red">*</font><br />
username: <b><? echo "$id"; ?></b><br />
<input type="submit" value="Save blogpost!"></form>