PDA

View Full Version : data not submitting to database.


Predator
04-01-2007, 03:50 PM
hi i am on the php beginners tutorial and i am on part 9. I have watched the video tutorial and done everything it says. I am learning so much and i thank you for that. I am 15 atm and im not clever you guys at this forums so any help would be much appreciated.

Here is my code atm.
<?php
require_once("Connections/connection.php"); // database connection

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

if ($sumbit && $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 is empty!";

}

///////////////////////////////////////////////
$query = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = mysql_fetch_array($result); // contains all the database data
///////////////////////////////////////////////

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

}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="200" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>data2</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 colspan="3"><div align="center">
<input type="submit" name="Submit" value="Submit" />
<input name="submit" type="hidden" id="submit" value="1" />
</div></td>
</tr>
</table>
</form>
<p>&nbsp;</p>
<table width="429" height="68" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>ID</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)); ?>
</table>
</body>
</html>


That is my code, and my problem is when i run it and enter details and i press sumbit, it come up with the message "One of your fields is empty!" but i have entered all the fields. I would like to know what i am doing wrong.
Thank you, any help would be much appreciated.

Predator
04-01-2007, 04:45 PM
o found out what was wrong i spelled submit wrong. sorry my fault. :)

davidj
04-01-2007, 04:55 PM
in this line


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



you have sumbit not submit


always check your spelling!