#1, you
can put the mysql_query in upper case, lower case, OR mixed case and it does NOT matter which. So, the fact that it has to be in lower case is just wrong.
#2, you had some wierd ways you were calling through your code, so i cleaned it up.
#3, was $name and $content suposed to be values passed from a different page? IF SO, this should work :
Code: Select all
<?php
if (($_POST['name'] == "") || ($_POST['content'] == ""))
{
echo "<form name=form method=post action=addnews_action.php>";
echo "Fill In Required Places<br>";
echo "You Have Missed Places<br>";
if ($_POST['name'] == "")
{
echo "<p class=bodymd>Name<br><input type=text name=Name><br><br>Content:<br>".$_POST['content']."</p>";
}
else
{
echo "<input type=hidden name=Name value=".$_POST['name'].">";
}
if ($_POST['Content'] == "")
{
echo "<p class=bodymd>Name:<br><b>".$_POST['Name']."</b><br><br>Content<br><textarea name=Content rows=10 cols=50></textarea></p>";
}
else
{
echo "<input type=hidden name=Content value=".$_POST['Content'].">";
}
echo "<input type=submit name=Submit value=Submit>";
echo "<input type=reset name=Reset value=Clear Form>";
echo "</form>";
exit;
}
$conn = mysql_connect("localhost","login","12345") or die ("Couldn't connect to DB.");
$db = mysql_select_db("db") or die(MySQL_Error()); // change DB to your database name..
$sql= "INSERT INTO news (id, name, content)". "VALUES ('NULL', '".$_POST['name']."', '".$_POST['content']."')";
$result=MySQL_Query($sql) or die(MySQL_Error());
{
echo "<p class=bodymd><b>".$_POST['Name']."</b>, Your New Was Added</p>";
}
?>
if it wasn't and you just declared the variables and their values before the code you posted, then THIS should work :
Code: Select all
<?php
if (($Name == "") || ($Content == ""))
{
echo "<form name=form method=post action=addnews_action.php>";
echo "Fill In Required Places<br>";
echo "You Have Missed Places<br>";
if ($Name == "")
{
echo "<p class=bodymd>Name<br><input type=text name=Name><br><br>Content:<br>".$Content."</p>";
}
else
{
echo "<input type=hidden name=Name value=".$Name.">";
}
if ($Content == "")
{
echo "<p class=bodymd>Name:<br><b>".$Name."</b><br><br>Content<br><textarea name=Content rows=10 cols=50></textarea></p>";
}
else
{
echo "<input type=hidden name=Content value=".$Content.">";
}
echo "<input type=submit name=Submit value=Submit>";
echo "<input type=reset name=Reset value=Clear Form>";
echo "</form>";
exit;
}
$conn = mysql_connect("localhost","login","12345") or die ("Couldn't connect to DB.");
$db = mysql_select_db("db") or die(MySQL_Error()); // Change db to your Database Name.
$sql= "INSERT INTO news (id, name, content)". "VALUES ('NULL', '".$Name."', '".$Content."')";
$result=MySQL_Query($sql) or die(MySQL_Error());
{
echo "<p class=bodymd><b>".$Name."</b>, Your New Was Added</p>";
}
?>
PLEASE NOTE
If you are NOT passing the variables from a nother page and you just defined the variables before the code you posted, YOU MUST use the same casing that you used when you first defined them as they are case-sensative. I found that out the hard way myself.
Anyways, that should help you man. Have fun.