hi i am building a cms system for my website, i am able to put data into a mysql database with the following code(look below).
i also have a login system for accessing the cms, everything worked so far. I am facing a problem now.
Ok so user signup info is stored in a differant database, and i am using another database to store the cms content
--blog
|-author
|-post
so my blog databse contains two tables. on the post section i store the content of a post.
the author section contains author name and author email columns.
whenever someone trying to post new content the following code will check for the username if it is already exists or not if not then it will insert the username and useremail. here lies the problem i can check whether the username already exist or not, but if not i am not able to insert new username and email.
my php code-
<?php
$mysql_server = 'localhost';
$mysql_username = 'Avik@localhost';
$mysql_password = '';
$mysql_database = 'blog';
$mysql_table = 'post';
$mysql_usertable = 'author';
$success_page = 'postsuccess.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['form_name'] == 'save')
{
$db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
if (!$db)
{
die('Failed to connect to database server!<br>'.mysql_error());
}
mysql_select_db($mysql_database, $db) or die('failed to connect to database<br>'.mysql_error());
$post_username = $_POST['username'];
$post_useremail = $_POST['useremail'];
$sql = "SELECT authorname FROM ".$mysql_usertable." WHERE authorname = '".$post_username."'";
$result = mysql_query($sql, $db);
if (!$data = mysql_fetch_array($result))
{
$sql = "INSERT `".$mysql_usertable."` (`id`, `authorname`, `authoremail`) VALUES (NULL, '$post_username', '$post_useremail')";
}
$post_title = $_POST['title'];
$post_topic = $_POST['topic'];
$post_tags = $_POST['tags'];
$post_content = $_POST['elm1'];
$sql = "INSERT `".$mysql_table."` (`title`, `topicid`, `tags`, `postdate`, `content`) VALUES ('$post_title', '$post_topic', '$post_tags', CURDATE(), '$post_content')";
$result = mysql_query($sql, $db);
mysql_close($db);
header('Location: '.$success_page);
}
?>
am i doing something wrong? please help.