I'm writing a simple form which takes values and adds them into a database, however if I choose to do it with functions instead of calling an external script, it seems as though the variables are not being set or being unset somehow. Here is a snippet of the code I'm working with, the database function is commented since I'm trying to troubleshoot and just print vars at this point.
function print_form() {
/echo ("<div id=main>");/
echo ("<form action=$_SERVER[PHP_SELF] method=post>");
echo ("<b>Article Name</b>");
echo (" <input type=text name=art_name size=50>");
echo ("<br>");
echo ("<b>Your Name</b>");
echo ("    <input type=text name=added_by size=50>");
echo ("<br><br>");
echo ("<b>Article</b>");
echo ("<br><br>");
echo ("<textarea name=art_body rows=25 cols=75></textarea>");
echo ("<br><br>");
echo ("<input type=submit>");
echo ("</form>");
echo ("</div>");
}
function update_frontpage() {
/$connect=mysql_connect(localhost,,);/
$current_date = date("Ymd\THis");
/mysql_selectdb("cms",$connect) or die(mysql_error());/
/$query="INSERT INTO frontpage_news VALUES ('','$art_name','$current_date','$added_by','$art_body')";/
/mysql_query($query) or die (mysql_error());/
/mysql_close();/
/echo "You're article has been added, click <a href=index.php>here</a> to go back to the frontpage";/
echo "($art_name,$current_date,$added_by,$art_body)";
}
if($_POST[art_body]) {
update_frontpage();
}else{
print_form();
}
the var art_body is being set because if left unset it fails the if test and prints the form again, but if its set it seems to be set as blank as when printing out vars its just blank except for $current_time
If I call an external script with the exact same code as is in the update_frontpage function it works fine and the variables are being set...
I'm sure its something retarded I'm missing but any thoughts would be greatly appreciated 🙂
Drew