PDA

View Full Version : PHP Video Tutorial part 9, date doesn't post


heirani1
12-17-2007, 05:08 PM
hi, i am following part 9 of the VTM and i am sure i have got all the code correct and when i go to add data into each one it adds it to the bottom of the list apart from the date field. all i get is 0000-00-00, the other 2 fields work perfectly!

heres the code...

<?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 "one of your fields are empty!";

}

///////////////////////////////////////////
$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));*/

?>

<body>
<form id="form1" name="form1" method="post" action="<?php $SERVER {'PHP_SELF'}; ?>">
<table width="424" border="1">
<tr>
<td>Data2</td>
<td>Data3</td>
<td>Data4</td>
</tr>
<tr>
<td><label>
<input name="data2" type="text" id="data2" />
</label></td>
<td><label>
<input name="data3" type="text" id="data3" />
</label></td>
<td><label>
<input name="data4" type="text" id="data4" />
</label></td>
</tr>
<tr>
<td colspan="3"><label>
<div align="center">
<input type="submit" name="Submit" value="Submit" />
<input name="Submit" type="hidden" id="Submit" value="1" />
</div>
</label></td>
</tr>
</table>
</form>
<p>&nbsp;</p>
<table width="424" border="1">
<tr>
<td>ID1</td>
<td>Data2</td>
<td>Data3</td>
<td>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)); ?>

davidj
12-17-2007, 07:52 PM
your going to kick yourself

check the var (data4) in your SQL statement

its missing something!

///

give yourself a smack on the head..

welcome to the forums mate

heirani1
12-18-2007, 09:57 AM
i don't believe it i checked that code convinced it was right, i hate it when things like that happen lol anyway thanks for your help, these tutorials are becoming very helpful. While im here is there any more tutorials i can follow on from after i have done the updating php data - part 11?

Thanks again for your help,

Chris

davidj
12-18-2007, 10:06 AM
no probs

there are other tuts in there which i have done