Jump to content


Photo

Problem with Post form to database !


  • Please log in to reply
3 replies to this topic

#1 NaPalmDK

NaPalmDK
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 13 August 2006 - 12:09 PM

My problem is that there only get added the first 2 from the formular ! (type+status) rest are empty !


Site there send data !
<? if($_GET[done] == "1") {
echo "<center><font color=green size=2 face=Arial>Øllet er Tilføjet !</font></center>";
} 
?>
<head>
<meta http-equiv="Content-Language" content="da">
</head>

<div align="center">
	&nbsp;<table border="0" width="550" cellspacing="0" cellpadding="0" style="border-top: 1px black solid; border-right: 1px black solid; border-left: 1px black solid; border-bottom: 1px black solid" id="table1">
		<tr>
			<td bgcolor="#CCCCCC" style="border-bottom: 1px black solid">&nbsp;&nbsp;<b><font face="Arial">Til Føj En Øl.....</font></b></td>
		</tr>
		<tr>
			<td>
			<form method="POST" action="beeradd.php">
				<table border="0" width="100%" cellpadding="2" id="table2">
					<tr>
						<td><b><font face="Arial" size="2">Øl Type:</font></b></td>
						<td><select size="1" name="type">
						<option value="01">01 - Pilsner</option>
						<option value="02">02 - Lager</option>
						<option value="03">03 - English Strong Bitter (ESB)
						</option>
						<option value="04">04 - English Pale Ale</option>
						<option value="05">05 - Indian Pale Ale (IPA)</option>
						<option value="06">06 - Swartsbeer</option>
						<option value="07">07 - Belgisk Strong Ale</option>
						<option value="08">08 - Belgisk Pale Ale</option>
						<option value="09">09 - British Brown Ale</option>
						<option value="10">10 - Weizen</option>
						<option value="11">11 - Dunkelweizen</option>
						<option value="12">12 - Belgisk wit</option>
						</select></td>
						<td><b><font size="2" face="Arial">Status:</font></b></td>
						<td><select size="1" name="status">
						<option value="Planlagt">Planlagt</option>
						<option value="Gæring">Gæring</option>
						<option value="Lagering">Lagering</option>
						<option value="Karbonering">Karbonering</option>
						<option value="Drikke Klar">Drikke Klar</option>
						<option value="Drukket">Drukket</option>
						<option value="Helt Ud">Helt Ud</option>
						</select></td>
					</tr>
					<tr>
						<td height="7" colspan="4">
						<fieldset style="padding: 2">
						<legend align="center">
						<p align="left"><b><font size="2" face="Arial">Smags 
						Barometer</font></b> </p>
						</legend>
						<div align="center">
							<table border="0" width="300" cellspacing="0" cellpadding="0" id="table3">
								<tr>
									<td width="100"><font face="Arial" size="2">
									Let</font></td>
									<td width="100">
									<p align="center">
									<select size="1" name="smag1">
									<option value="1">1</option>
									<option value="2">2</option>
									<option value="3">3</option>
									<option value="4">4</option>
									<option value="5">5</option>
									</select></td>
									<td align="right" width="100">
									<font face="Arial" size="2">Kraftig</font></td>
								</tr>
								<tr>
									<td width="100"><font face="Arial" size="2">
									Mild</font></td>
									<td width="100">
									<p align="center">
									<select size="1" name="smag2">
									<option value="1">1</option>
									<option value="2">2</option>
									<option value="3">3</option>
									<option value="4">4</option>
									<option value="5">5</option>
									</select></td>
									<td align="right" width="100">
									<font face="Arial" size="2">Bitter</font></td>
								</tr>
								<tr>
									<td width="100"><font face="Arial" size="2">
									Tør</font></td>
									<td width="100">
									<p align="center">
									<select size="1" name="smag3">
									<option value="1">1</option>
									<option value="2">2</option>
									<option value="3">3</option>
									<option value="4">4</option>
									<option value="5">5</option>
									</select></td>
									<td align="right" width="100">
									<font face="Arial" size="2">Sød</font></td>
								</tr>
							</table>
						</div>
						</fieldset></td>
					</tr>
					<tr>
						<td height="6">
						<b><font size="2" face="Arial">Bryg Dato:</font></b></td>
						<td height="6">
						<input type="text" name="dato" size="18"> dd-mm-åååå</td>
						<td height="6">
						</td>
						<td height="6">
						</td>
					</tr>
					<tr>
						<td height="12" colspan="4">
						<p align="center">
						<textarea rows="7" name="komentar" cols="62"></textarea></td>
					</tr>
				</table>
				<p align="center"><input type="submit" value="Send" name="B1"><input type="reset" value="Nulstil" name="B2"></p>
			</form>
			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
	</table>
</div>

Page there riceive data !
<?
include("../_doh/db.php.inc");
?>
<?
mysql_query("INSERT INTO beer (`beer_style`, `beer_status`, `beer_taste1`, `beer_taste2`, `beer_taste3`, `beer_brygdag`, `beer_coment`) values ('$_POST[type]', '$_POST[status]', '$POST[samg1]', '$POST[smag2]', '$POST[smag3]', '$POST[dato]', '$POST[komentar]')") or die(mysql_error());

header("Location: addbeer.php?done=1");
?>

Database table:
CREATE TABLE `beer` (
  `beer_id` tinyint(10) NOT NULL auto_increment,
  `beer_style` varchar(200) NOT NULL default '',
  `beer_status` varchar(20) NOT NULL default '',
  `beer_taste1` tinyint(1) default '0',
  `beer_taste2` tinyint(1) NOT NULL default '0',
  `beer_taste3` tinyint(1) NOT NULL default '0',
  `beer_coment` text NOT NULL,
  `beer_brygdag` varchar(20) NOT NULL default '',
  PRIMARY KEY  (`beer_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;


#2 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,431 posts
  • LocationBelgium

Posted 13 August 2006 - 12:38 PM

first i suggest you start using "proper" coding (saved me always from strange bugs, errors, etc...)

for your page that sends data
<?php
if ($_GET['done'] == "1") {
 ...
}
?>

for your page that receives it!
<?php
// For readability have i added some newlines here
$Sql = sprintf(
"INSERT INTO `beer` (`beer_style`, `beer_status`, `beer_taste1`, `beer_taste2`, `beer_taste3`, `beer_brygdag`, `beer_coment`) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
$_POST['type'], $_POST['status'], $POST['samg1'], $POST['smag2'], $POST['smag3'], $POST['dato'], $POST['komentar']
);

if (mysql_query($Sql)) {
   // We don't wanna have error's like "headers already sent..." therefor this does the job as well!
   echo "<script>window.location.href='addbeer.php?done=1';</script>";
} else {
  echo mysql_error();// TODO: i know that the db_resource is optional, however i should consider providing this anyhow!
}
?>


#3 NaPalmDK

NaPalmDK
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 13 August 2006 - 12:46 PM

Thanx gonna try it !

As i tryed to say im all new to php :)

#4 NaPalmDK

NaPalmDK
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 13 August 2006 - 01:11 PM

Dident work still not  adding all data to the database only type and status are added




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users