dynamic news code script error
Posted: Thu Nov 10, 2005 8:07 am
feyd | Please use
the code for the addnewsform.htm file is
The code for the addnews.php file is:
I reckon its not passing the inputs from the form correctly to the arrays but unsure how this is done does anybody have any advice. Try it for yourself at maccms.co.uk/addnewsform.htm.
Many thanks in advance
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hi,
Iam working on a dynamic news script provided by a magazine tutorial but gives me the following error when I try to enter a test news item into the database it reportsCode: Select all
The query is:
INSERT into dynamic_news values ('0','','','','')
The news story was successfully added to the database.
Add another news storythe code for the addnewsform.htm file is
Code: Select all
<HTML>
<HEAD>
<TITLE>Add news form</TITLE>
</HEAD>
<BODY>
<FORM ACTION="addnews.php" METHOD=POST>
<TABLE border=0 cellspacing=0 cellpadding=0>
<TR><TD>Date</TD>
<TD><INPUT NAME="Array[Date]" TYPE=TEXT id="Array[Date]"SIZE=8></TD>
</TR><BR><TR><TD>Headline</TD><TD><INPUT TYPE=TEXT NAME="Array[Headline]"SIZE=50><TR><TD><BR>
<TR><TD>Story</TD><TD><TEXTAREA NAME="Array[Story]"ROWS=8 COLS=80></TEXTAREA></TD></TR><BR><BR>
</TABLE><INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Save news story to database">
</FORM>
</BODY>
</HTML>The code for the addnews.php file is:
Code: Select all
<html>
<head>
<title>Add news story to database</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
//match the form fields to the variables
$Array[Date]=trim($Array[Date]);
$Array[Headline]=trim($Array[Headline]);
$Array[Story]=trim($Array[Story]);
//assign variables to your database details
$DBName="maccms1";
$TableName="dynamic_news";
$mysql_link=mysql_connect("localhost","username","password");
//insert array variables into database
$Query="INSERT into $TableName values ('0','$Array[Date]','$Array[Headline]','$Array[Extracopy]','$Array[Topic1]')";
//print on screen the record added
print("The query is:<BR>$Query<P>\n");
//Tell me if the record has been added
if(mysql_db_query($DBName,$Query, $mysql_link)){
print("The news story was successfully added to the database.<BR>
<A HREF=\"addnewsform.htm\">Add another news story</A>\n");
}else{
print("Sorry - we could not add your story<BR>\n");
}
//close the connection to the database
mysql_close($mysql_link);
?>
</body>
</html>I reckon its not passing the inputs from the form correctly to the arrays but unsure how this is done does anybody have any advice. Try it for yourself at maccms.co.uk/addnewsform.htm.
Many thanks in advance
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]