form to add data into a database
Posted: Fri Aug 12, 2005 7:45 am
hey people
im new to php
im making the greatest effort to understand it..
well i have this form where i enter the data and it shud get added it its database..
if i manually insert data and view it using another php file it works..but sending the same data through the form doesnt seem to work.ie the database isnt updated.
any kind of suggestions or help is welcome big time.
im new to php
im making the greatest effort to understand it..
well i have this form where i enter the data and it shud get added it its database..
if i manually insert data and view it using another php file it works..but sending the same data through the form doesnt seem to work.ie the database isnt updated.
Code: Select all
<?php
include("dbconnect.php");
if(!empty($title))
{
$title=addslashes($title);
$user=addslashes($user);
$message=addslashes($message);
//$date=date("F,j,Y");
//$date2=mktime();
$sql="INSERT INTO mynews(id,title,user,date,message)VALUES('NULL','$title','$user','$date','$message')";
$query=mysql_query($sql) or die("cannot query the database" .mysql_error());
echo("database updated.");}
else{
?>
<form action="<?php echo $PHP_SELF;?>" method="POST" enctype="multipart/form-data" name="news">
<p>please fill out the following fields:</p>
<table width="800" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="117"><font size="1">news topic/title :</font></td>
<td width="577"> <font size="1">
<input type="text" name="$title" size="50">
</font> </td>
</tr>
<tr>
<td width="117"><font size="1">username:</font></td>
<td width="577"><font size="1">
<input type ="text" name ="$user" size ="50">
</font> </td>
</tr>
<tr>
<td width="117"><font size="1">message:</font></td>
<td width="577"> <font size="1">
<textarea name="$message" rows=10 cols=43></textarea>
</font> </td>
</tr>
</table>
<p align="left">
<font size="1">
<input type="submit" name="submit" value="submit"></font>
</p>
</form> <?php }?>