PHP Help - Involves MySQL

Started by
4 comments, last by Ekim_Gram 20 years, 1 month ago
Alright, my problem is that I've got a script where I can add an article to the database. But...when I submit the form, I get no message saying whether the query failed or was a success. Here's my source:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<?php
require ("config.inc");
?>
<title> Add An Article </title>
</head>

<?php

// If the form was submitted, process it

if (isset($submit))
{
$query = "insert into articles values ('0', '$article_name', '$type_id', '$system_id' '$year', '$month', '$day')";
if (@mysql_query ($query))
{
echo 'The article has been added';
}
else
{
echo 'The title could not be added.' . mysql_error();
}
}
?>

<form action="<?=$PHP_SELF ?>" method="post">
Game:   <input type="text" name="article_name" size="50" maxlength="100" /> <br />
Type:   <select name="type_id"> <option> Select The Type Of Article </option>

<?php
// Print all the types

$query1 = "SELECT type_id, type FROM types";
$query_result1 = @mysql_query ($query1);
while ($row1 = @mysql_fetch_array ($query_result1))
{
echo "<option value=\"$row1[type_id]\"> $row1[type] </option>\n";
}
?>
</select> <br />

System: <select name="system_id"> <option> Select The System </option>

<?php
// Print all the systems

$query2 = "SELECT system_id, system FROM systems";
$query_result2 = @mysql_query ($query2);
while ($row2 = @mysql_fetch_array ($query_result2))
{
echo "<option value=\"$row2[system_id]\"> $row2[system] </option>\n";
}
?>
</select> <br />

Date Entered:

<select name="year"> <option> Year </option>
<?php
// Print the years

$year = 2003;
while ($year <= 2004)
{
print ("<option value=\"$year\"> $year </option> <br />");
$year++;
}
?>
</select>

<select name="month"> <option> Month </option>
<?php
// Print all the month nubmers

$month = 0;
while ($month <= 12)
{
print ("<option value=\"$month\"> $month </option> <br />");
$month++;
}
?>
</select>

<select name="day"> <option> Day </option>
<?php
// Print all the day number

$day = 0;
while ($day <= 31)
{
print ("<option value=\"$day\"> $day </option> <br />");
$day++;
}
?>
</select> <br />

<input type="submit" name="submit" value="Submit!" />
</form>
</body>
</html>
config.inc just has my connection to the database. I konw for a fact it's not a connection problem because the loops work fine when accessing the different types of articles and stuff. If you would like, I'll put everything online so you can look at the problem yourself. R.I.P. Mark Osback Solo Pa Mi Gente VG-Force Ekim Gram Productions [edited by - Ekim_Gram on March 5, 2004 3:51:52 PM]
Advertisement
Surely you mean,

if(isset($_POST[''Submit''])) {

?
[teamonkey] [blog] [tinyminions]
quote:Original post by teamonkey
Surely you mean,

if(isset($_POST[''Submit''])) {

?


You sure, are a life saver. I shoulda thought about using HTTP headers.




R.I.P. Mark Osback
Solo Pa Mi Gente
VG-Force
Ekim Gram Productions
*sigh* Now I have another problem I can't seem to figure out. I'm getting the following error:

Column count doesn't match value count at row 1  


Here is the SQL code for the table that's being modified:

CREATE TABLE articles(	article_id	 INT UNSIGNED NOT NULL AUTO_INCREMENT,	article   	 VARCHAR (255),	type_id		 INT UNSIGNED,	system_id 	 INT UNSIGNED,	year	         INT UNSIGNED,	month		 INT UNSIGNED,	day		 INT UNSIGNED,	PRIMARY KEY 		(article_id),	INDEX      		  (article));


[edited by - Ekim_Gram on March 5, 2004 4:03:53 PM]
$query = "insert into articles values ('0', '$article_name', '$type_id', '$system_id' '$year', '$month', '$day')";if (@mysql_query ($query))


Possible missing a , between system_id and year?



[edited by - acraig on March 5, 2004 4:08:13 PM]
Wow, today is definately not my day. I think you so much good sir, I can''t believe I didn''t see that.


R.I.P. Mark Osback
Solo Pa Mi Gente
VG-Force
Ekim Gram Productions

This topic is closed to new replies.

Advertisement