Jump to content

Problems reading a table


jeffstyle

Recommended Posts

Hi all,I have some problems reading a table. I'll post all the relevant code here.Adding an entry:

mysql_query("INSERT INTO photo (photo, photocode, w, h)VALUES ('$_POST[photo]', '$_POST[photo]', '$_POST[w]', '$_POST[h]')");

(this works fine, and yes, I know that photo and photocode are getting the same value at the moment)Reading the same entry and giving it an option to be editted:

<?php$showphoto = mysql_query("SELECT * FROM photo ORDER BY photocode ASC");while($photoitem = mysql_fetch_array($showphoto)) {?><TR>	<TD><FONT><?php echo $photoitem['photo']; ?></FONT></TD>	<TD><FONT><?php echo $photoitem['w']; ?></FONT></TD>	<TD><FONT><?php echo $photoitem['h']; ?></FONT></TD>	<TD><FONT><FORM action="photo_edit.php" method="post">	<INPUT type="hidden" name="code" value="<?php echo $photoitem['photocode']; ?>" />	<INPUT class="form" type="submit" value=">>" />	</FORM></FONT></TD></TR><?php}?>

(this also works fine)And in the last page, when I click the button to edit the entry I want:

<?php$code = $_POST['code'];$showphoto = mysql_query("SELECT * FROM photo WHERE (photocode = '$code')");while($photoitem = mysql_fetch_array($showphoto)) {?><TR>	<TD><TEXTAREA class="form" name="file" rows="1" cols="9"><?php echo $photoitem['photo']; ?></TEXTAREA></TD>	<TD><TEXTAREA class="form" name="w" rows="1" cols="7"><?php echo $photoitem['w']; ?></TEXTAREA></TD>	<TD><TEXTAREA class="form" name="h" rows="1" cols="12"><?php echo $photoitem['h']; ?></TEXTAREA></TD></TR><?php}?>

And this is where the trouble begins.I'm getting the error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /customers/j-o-e.nl/j-o-e.nl/httpd.www/admin/photo_edit.php on line 26 Line 26 is the line starting with "while".I was thinking, the $code might be wrong so it can't find any results matching the WHERE. But when I echo $code, it gives the exact same value as I've entered before, and the exact same value I can see in the table when I browse the table in PHPMyAdmin.Well, that's weird. To make it even more weird, I'm using this exact same code for different parts of the site where only the names "photo" are changed to for example "agenda" or "music" etc, and that all works just perfectly fine.And to add more weirdness, when I submit the form in the 3rd part, I'm using the following code:

mysql_query("UPDATE photoSET photo = '$_POST[photo]', photocode = '$_POST[photo]', w = '$_POST[w]', h = '$_POST[h]'WHERE photocode = '$code'");

And this actually works. Or well, it does change the row to empty values as the textfields in the previous form don't show and thus don't get values.Another test I did is to manually change the WHERE part to WHERE photocode = 'photo1' (which is an existing name in the table) and it does work.And another test I also did is to match it on the W and H fields, and guess what, that also works...So yeah.. I'm completely lost now, I just can't see why this isn't working and it's doing my head in..Does any of you have a clue why this isn't working?Thanks in advance for reading/helping! :)

Link to comment
Share on other sites

Hi, For first case try: $showphoto = mysql_query("SELECT * FROM photo WHERE photocode = '$code'"); without ( )And for other.Before query, try echo $_POST['photo']; and so on, to see does it returns some data..I'm not sure can you use $_POST[photo] instead of $_POST['photo']And be sure that you are sending data with POST, not GETGood luck.

Link to comment
Share on other sites

Hi,Thanks for your time.It's actually working now I think!I did what you said, removed the () around the WHERE part, and it shows what I want. I'll have to do some more testing to be sure but it looks like it's working.Still this is so very weird as I'm using the () in all the other pages and it's working fine there.Oh well.. not gonna spend any more time on it, it seems to work so that's fine :)Thanks a lot!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...