PDA

View Full Version : Part 9


larryl
04-15-2007, 06:57 AM
When I fill out the form that we have created, I input in the date 2007-04-14, but it returns back to me 0000-00-00 in the new record that appears on the table. Everything else is fine, the other fields are updated correctly. Below I have posted the code I am using, am I making any errors?


<?php
require_once("Connections/connection.php"); //database connection

///////////////////////////////////////
$data2 = $_POST['data2'];
$data3 = $_POST['data3'];
$data4 = $_POST['data4'];
$submit = $_POST['submit'];
///////////////////////////////////////

if ($submit && $data2 && $data3 && $data4){

//////////////////////////////////////
$query = sprintf("INSERT into table1 (field2, field3, field4) values ('$data2', '$data3', 'data4')");
mysql_query($query)or die(mysql_error());
//////////////////////////////////////

}elseif($submit) {

echo "You ****ing dumbass, Fill in the form COMPLETELY!";

}


/////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
/////////////////////////////////////////////////////

/*do {
echo $row['field3']. "<br>";

}while ($row = mysql_fetch_array($result))*/


?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<table width="360" border="1" cellpadding="0">
<tr>
<td><label>data2</label></td>
<td>data3</td>
<td>data4</td>
</tr>
<tr>
<td><input name="data2" type="text" id="data2" /></td>
<td><input name="data3" type="text" id="data3" /></td>
<td><input name="data4" type="text" id="data4" /></td>
</tr>
<tr>
<td height="38" colspan="3" align="center" valign="middle">
<input type="submit" name="Submit" value="Submit" />
</label>
<input name="submit" type="hidden" id="submit" value="1" /></td>

</tr>
</table>
<p>&nbsp;</p>
</form>
<p>&nbsp;</p>
<table width="359" height="49" border="1" cellpadding="0">
<tr>
<td width="48">ID</td>
<td width="96">data2</td>
<td width="96">data3</td>
<td width="99">data4</td>
</tr>


<?php do { ?>
<tr>
<td><?php echo $row['field1_id']; ?></td>
<td><?php echo $row['field2']; ?></td>
<td><?php echo $row['field3']; ?></td>
<td><?php echo $row['field4']; ?></td>
</tr>

<?php }while ($row = mysql_fetch_array($result)) ?>

</table>
</body>
</html>



This is what I get...
data2 data3 data4

ID data2 data3 data4 1 17 apples 2007-04-13 2 15 pears 2007-04-06 3 23 oranges 2007-04-20 4 300 peaches 2007-04-27 5 309 pears 2007-04-28 6 309 pears 2007-04-27 7 22 oranges 0000-00-00 8 22 oranges 0000-00-00 9 400 apples 0000-00-00 10 2 pears 0000-00-00 11 1 peaches 0000-00-00

davidj
04-15-2007, 10:33 AM
where you have


$query = sprintf("INSERT into table1 (field2, field3, field4) values ('$data2', '$data3', 'data4')");



please look at the variable data4

you have missed the $ off the front