Ninjakreborn Posted February 2, 2007 Share Posted February 2, 2007 I have an area on a clients website where people are allowed to upload a max of 4 photo's. I need to let them upload them, and return an error when they are over 4 images so they can not upload anymore than 4. I have this <?php $select4 = "SELECT * FROM user_images WHERE userid = '" . $_SESSION['userinfo']['id'] . "';"; $query4 = mysql_query($select4); if (count(mysql_fetch_array($query4)) <= 3) { // do the image upload }else { echo "You have already reached your max upload number.<br />"; echo "The file has been discarded.<br />"; } ?> This looks logical to me. However they upload 1 image, the other 3 give an error, and they had only uploaded one. Can someone see what I am doing wrong? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 2, 2007 Share Posted February 2, 2007 mysql_fetch_array selects the current row and moves the pointer forward. To do what you're trying you need to loop through it. There are examples of how to use that function on the php.net page for it http://php.net/mysql_fetch_array. If you just want their number, use SELECT count(*) FROM ... Or use your current query and use mysql_num_rows() Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted February 2, 2007 Author Share Posted February 2, 2007 Perfect. Mysql num rows worked, thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.