Dean C
04-07-2003, 08:27 AM
Ok well its taken me about a week to get the layout coded up for my new site and i have the news intigrated succesfully. I'm proud of myself ;)
Well currently the news has to be added manually through the db so i tried writing a script to add the news through a page quickly and easily.
Here is what i have:
<html>
<head><title>Add News</title></head>
<body>
<?php
$form = "<form action=\"$PHP_SELF\" method\"post\">";
$form .= "<b>Title</b>";
$form .= "<input type=\"text\" name=\"title\" size=\"50\" value=\"$title\"><br />";
$form .= "Content:<br /> <textarea name=\"content\" cols =\"45\" rows=\"4\">$comments</textarea><br />";
$form .= "<input type=\"submit\" name=\"submit\" value =\"submit\"></form>";
if (!$submit) {
$msg = $form;
} else if (!$title or !$content) {
$msg = "<b>Please complete all fields</b><br /><br />";
$msg .= $form;
} else if ($submit and $content and $title) {
$conn = @msql_connect("localhost","root","mist") or die("Could not connect to db");
$rs = @mysql_select_db("designdevise",$conn) or die ("Could not select db");
$sql = "insert into news (title,content) values (\"$title\",\"$content\")";
$query = @mysql_query($sql,$conn) or die("Could not execute query");
if($query)
{
$msg = "News added";
}
}
echo($msg);
?>
</body>
</html>
Now its just not working right. The page loads. But when i click submit to post the news it doesn't come up with the message that the news has been added or it could not execute the query. It's just a blank page. I'm sure this is such an easy problem to fix if someone could point me in the right direction ;)
Regards
- miSt
Well currently the news has to be added manually through the db so i tried writing a script to add the news through a page quickly and easily.
Here is what i have:
<html>
<head><title>Add News</title></head>
<body>
<?php
$form = "<form action=\"$PHP_SELF\" method\"post\">";
$form .= "<b>Title</b>";
$form .= "<input type=\"text\" name=\"title\" size=\"50\" value=\"$title\"><br />";
$form .= "Content:<br /> <textarea name=\"content\" cols =\"45\" rows=\"4\">$comments</textarea><br />";
$form .= "<input type=\"submit\" name=\"submit\" value =\"submit\"></form>";
if (!$submit) {
$msg = $form;
} else if (!$title or !$content) {
$msg = "<b>Please complete all fields</b><br /><br />";
$msg .= $form;
} else if ($submit and $content and $title) {
$conn = @msql_connect("localhost","root","mist") or die("Could not connect to db");
$rs = @mysql_select_db("designdevise",$conn) or die ("Could not select db");
$sql = "insert into news (title,content) values (\"$title\",\"$content\")";
$query = @mysql_query($sql,$conn) or die("Could not execute query");
if($query)
{
$msg = "News added";
}
}
echo($msg);
?>
</body>
</html>
Now its just not working right. The page loads. But when i click submit to post the news it doesn't come up with the message that the news has been added or it could not execute the query. It's just a blank page. I'm sure this is such an easy problem to fix if someone could point me in the right direction ;)
Regards
- miSt