frankienstien
Programmer
I'm trying to get this page to insert data into a mysql table but after hitting the submit button the data is not being submitted to the database.
i'm not sure what is happening. i know the fields are coming back empty but i don't know why. any hints as why this is not working correctly?
thank you
sorry if this looks like crap i'm still learning php coding.
i'm not sure what is happening. i know the fields are coming back empty but i don't know why. any hints as why this is not working correctly?
thank you
sorry if this looks like crap i'm still learning php coding.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add News Item</title>
<style type="text/css">
<!--
body {
background-color: #CFAEF7;
}
-->
</style>
<script language="javascript" type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
theme : "advanced",
mode: "exact",
elements : "txtText",
theme_advanced_toolbar_location : "top",
plugins : "emotions",
theme_advanced_buttons3_add : "emotions",
});
</script>
</head>
</head>
<body>
<div align="center">
<?php
# database connection
<removed for my safety>
mysql_connect($dbhost,$dbuser,$dbpass) or die("could not connect");
mysql_select_db("$db") or die("could not open database");
############################################################################
#
# Table definitions
$USER_TB = 'calendar_users' ;
$calpath = dirname(__FILE__) ;
$pos = strpos($calpath, "/");
if (!is_integer($pos)) $adpath = $calpath.'\\' ;
else
$calpath = $calpath."/" ;
ob_start(); // set output_buffering ON
if (!isset($_GET['op']))
$op = '';
else
$op = $_GET['op'];
if ($op == ""){echo "You must login first.";
echo "<meta http-equiv=\"refresh\" content=\"3;url=index.php\">";
exit;}
if ($op == "loginok"){echo "Thank you for taking the time to update us on things you like or want us know.<br />
All entries will be reviewed by the administrator.";}
if ($op == "Insert"){$query="INSERT INTO `tblNews` ( `ID` , `Heading` , `Text` , `DateAdded` , `TimeAdded` )
VALUES ('', '" . $txtHeader . "', '" . $txtText . "', CURDATE( ) , CURTIME( ));";
if ($txtHeader ==""){echo "Please enter a Heading for your News Item.";
echo "<br/><br/><a href=javascript:history.back()>Back</a><br/>";
exit;}
if ($txtText ==""){echo "Please enter a Description for your News Item.";
echo "<br/><br/><a href=javascript:history.back()>Back</a><br/>";
exit;}
$result=mysql_query($query);
if (!$result) {exit('<p>Error performing search: ' . mysql_error() . '</p>');}
echo "Sucess <br>";
echo "Your News Item " .$txtHeader. " Has Been Added.<br>";
echo "Retruning you to the home page.";
echo "<meta http-equiv=\"refresh\" content=\"3;url=Default.php\">";
exit;
}
?>
</div>
<div align="center">
<?php
echo "<div align=center><form action=addnews.php?op=Insert method=post><table align=center width=300 border=0><tr><td align=right><div class=menufont>";
echo "<b>".ucfirst(Heading).":</b></div></td><td align=left><input type=text SIZE=50 MAXLENGTH=50 name=txtHeader></td></tr><tr><td align=right><div class=menufont>" ;
echo "<b>".ucfirst(Text).":</b></div></td><td align=left><TEXTAREA NAME=txtText COLS=50 ROWS=10></TEXTAREA></td></tr><tr><td align=left> </td><td align=center>" ;
echo "<input type=submit value=Insert></td></tr>";
echo "</table>" ;
echo "</form>";
echo "</div>" ;
if (!$txtHeading =="")
{if ($txtText ==""){echo "Please enter a Description for your News Item.";}
}
else
{echo "Please enter a Heading for your News Item.";}
?>
</div>
</body>
</html>