PDA

View Full Version : Problem "One of your fields is empty" - PHP Video tuts Part9


irock
12-12-2007, 09:53 PM
I'm having a problem with part 9 of the PHP video tutorials.
I'm not sure exactly where I went wrong with it but I would guess its just the syntax - It can be hard to spot the difference between () and {} in the video, maybe thats what my mistake is.

Anyway, everytime I run the page at the end of the tutorial I get the echoed result "One of yout fields is empty !"

Heres what my dwc.php file looks like:

http://pastie.caboo.se/127816

I pasted it there rather than making the thread unreadable.

davidj
12-13-2007, 05:42 AM
you have named your fields

textfield
textfield2
textfield3

they should reflect the $_POST references

lux
12-13-2007, 11:11 AM
This is wrong:
<td><?php echo $row{'field2'};?></td>

This is right:
<td><?php echo $row['field2']; ?></td>

$row is an associate array that contains the values returned from the database query

to see all the ids and values in the array use the function var_dump() like this

<?php var_dump($row) ?>

davidj
12-13-2007, 12:42 PM
or


echo "<pre>";
print_r($row);
echo "</pre>";

irock
12-13-2007, 06:17 PM
I've changed the names of the fields to data2, data3, data2

Now I get "Column count doesn't match value count at row 1" on submitting. :(

I'm getting lost.

irock
12-13-2007, 06:20 PM
I've changed the names of the fields to data2, data3, data2

Now I get "Column count doesn't match value count at row 1" on submitting. :(

I'm getting lost.

Just realised its because I was trying to insert a value into field1 which autoincrements.


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


Right:

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


I think I'm starting to grasp it. I suppose the key is to stick with it.

davidj
12-14-2007, 06:30 AM
the reason you got the error is because in your SQL Insert statement you have 4 columns declared but only 3 variables with data

the error you get tells you this...

"Column count doesn't match value count at row 1".


(field1, field2, field3, field4) values ('$data2', '$data3', '$data4')");