logo-dw

Go Back   Dreamweaver Club Forums > Dreamweaver forums > Video Tutorials
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 04-15-2007, 05:57 AM   #1
larryl
 
Join Date: Apr 2007
Posts: 3
Default Part 9

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 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 
"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))*/
 
 
?>
Code:
 
<!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
larryl is offline   Reply With Quote
Old 04-15-2007, 09:33 AM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

where you have

PHP Code:
$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
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:33 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com