PHP / MySQL script not working
I am new to databases and I have put this code together
PHP:<?
$today = date("Y-m-d"); // Date using PHP
?>
<center><b>Submit News</b></center>
<form action= "<?=$PHP_SELF?>" method= "post">
Insert title here:<br>
<input type= "text" name= "title"><p>
Date:<br>
<input type="text" name="date" value="<? echo($today); ?>"><p>
Insert text here:<br>
<textarea name="text" rows="20" cols="100"></textarea><p>
<input type="submit" value="Submit News" name="submitnews">
<input type="reset" value="Clear all fields"><p>
<?
$database = mysql_connect ("localhost", "***", "***") // Connect to database server
or die ("Could not connect to database server"); // Prints Could not connect to database server if connect fails.
echo ("Connected to database server<br>"); // Prints connected to database server in connection is succesfull
mysql_select_db ("***") // Connect to database
or die ("Could not connect to database"); // Prints Could not connect to database if connect fails
echo ("Connected to database<br>"); // Prints Connected to database if connect suceeds
if ($submitnews) // Checks to see if the Submit button has been clicked on
{
$sql= MYSQL_QUERY ("INSERT INTO site_news(id,title,text,date)".
"VALUES ('NULL', '$title', '$text', '$today')"); // Inserts the data into the table
if (mysql_query($sql))
{
echo("News added to database");
}
else
{
echo("Error adding news to database");
}
}
?>
As you have probably figured out, it is supposed to connect to the database and insert whatever i put in the form into the table site_news. It seems to connect to the database but it says "Error adding news to database" What is wrong with the code?
Also how waould I make a page displaying the contents of the table, and would HTML code work if I put it into the form?
Thanks in advance
Last edited by not_taken, August 6th, 2003 03:31 PM (Edited 1 times)

