Multiple rows in mysql

  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

ok i am trying to get all the information to show up from only postusername but only one row in the database with the username in postusername col will show up

Code: [ Select ]
<?
/* Requested Username error checking */
$req_user = $_GET['user'];
if(!$req_user || strlen($req_user) == 0 ||
  !eregi("^([0-9a-z])+$", $req_user) ||
  !$database->usernameTaken($req_user)){
  die("Username not registered ");
}


/* Display requested user information */
$req_user_postusername = $database->getUserComments($req_user);
?>
     <br>
     <table width="100%" border="0" class="comments"><tr><td width="24%"><?php
            echo "".$req_user_postusername['username'].""; ?></td>
     <td width="76%"><?php
            echo "".$req_user_postusername['comment'].""; ?></td>
     </tr></table>
 </p>
  1. <?
  2. /* Requested Username error checking */
  3. $req_user = $_GET['user'];
  4. if(!$req_user || strlen($req_user) == 0 ||
  5.   !eregi("^([0-9a-z])+$", $req_user) ||
  6.   !$database->usernameTaken($req_user)){
  7.   die("Username not registered ");
  8. }
  9. /* Display requested user information */
  10. $req_user_postusername = $database->getUserComments($req_user);
  11. ?>
  12.      <br>
  13.      <table width="100%" border="0" class="comments"><tr><td width="24%"><?php
  14.             echo "".$req_user_postusername['username'].""; ?></td>
  15.      <td width="76%"><?php
  16.             echo "".$req_user_postusername['comment'].""; ?></td>
  17.      </tr></table>
  18.  </p>


that is my code and what do i do to make it where all the postusername and comments from that pitucaler postusername will show up?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Hi,

well, could you show us the function getUserComments(), and better, all the definition of class of the object "$database".
THere's probably a loop to implement but we need more informations.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

Code: [ Select ]
function getUserComments($username){
     $q = "SELECT * FROM ".TBL_COMMENTS." WHERE postusername = '$username'";
   $result = mysql_query($q, $this->connection);
   /* Error occurred, return given name by default */
   if(!$result || (mysql_numrows($result) < 1)){
     return NULL;
   }
   /* Return result array */
   $dbarray = mysql_fetch_array($result);
   return $dbarray;
  }
  1. function getUserComments($username){
  2.      $q = "SELECT * FROM ".TBL_COMMENTS." WHERE postusername = '$username'";
  3.    $result = mysql_query($q, $this->connection);
  4.    /* Error occurred, return given name by default */
  5.    if(!$result || (mysql_numrows($result) < 1)){
  6.      return NULL;
  7.    }
  8.    /* Return result array */
  9.    $dbarray = mysql_fetch_array($result);
  10.    return $dbarray;
  11.   }
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

OK you should return only the recordset pointer, so that you can loop all the rows for the display stuff.

Code: [ Select ]
function getUserComments($username){
     $q = "SELECT * FROM ".TBL_COMMENTS." WHERE postusername = '$username'";
   $result = mysql_query($q, $this->connection);
   /* Error occurred, return given name by default */
   if(!$result || (mysql_numrows($result) < 1)){
     return NULL;
   }
   /* Return result array */
   //$dbarray = mysql_fetch_array($result);
   //return $dbarray;
   return $result;
  }
  1. function getUserComments($username){
  2.      $q = "SELECT * FROM ".TBL_COMMENTS." WHERE postusername = '$username'";
  3.    $result = mysql_query($q, $this->connection);
  4.    /* Error occurred, return given name by default */
  5.    if(!$result || (mysql_numrows($result) < 1)){
  6.      return NULL;
  7.    }
  8.    /* Return result array */
  9.    //$dbarray = mysql_fetch_array($result);
  10.    //return $dbarray;
  11.    return $result;
  12.   }

display stuff :
Code: [ Select ]
 
  <?
/* Requested Username error checking */
$req_user = $_GET['user'];
if(!$req_user || strlen($req_user) == 0 ||
  !eregi("^([0-9a-z])+$", $req_user) ||
  !$database->usernameTaken($req_user)){
  die("Username not registered ");
}


/* Display requested user information */
$rs_pointer = $database->getUserComments($req_user);
?>
     <br>
     <table width="100%" border="0" class="comments">
     <?php
     while($req_user_postusername = mysql_fetch_array($rs_pointer))
     {
                        echo "<tr><td width=\"24%\">".$req_user_postusername['username']."</td>"; 
         echo "<td width=\"76%\">".$req_user_postusername['comment']."</td></tr>\n";
        }
        ?>
     </table>
 </p>
  1.  
  2.   <?
  3. /* Requested Username error checking */
  4. $req_user = $_GET['user'];
  5. if(!$req_user || strlen($req_user) == 0 ||
  6.   !eregi("^([0-9a-z])+$", $req_user) ||
  7.   !$database->usernameTaken($req_user)){
  8.   die("Username not registered ");
  9. }
  10. /* Display requested user information */
  11. $rs_pointer = $database->getUserComments($req_user);
  12. ?>
  13.      <br>
  14.      <table width="100%" border="0" class="comments">
  15.      <?php
  16.      while($req_user_postusername = mysql_fetch_array($rs_pointer))
  17.      {
  18.                         echo "<tr><td width=\"24%\">".$req_user_postusername['username']."</td>"; 
  19.          echo "<td width=\"76%\">".$req_user_postusername['comment']."</td></tr>\n";
  20.         }
  21.         ?>
  22.      </table>
  23.  </p>
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

you can add an if statment for the returned value (null or pointer) so that you don't do the display stuff if the return is null ;-)
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

thank you it work and also is there a way where somebody can put in multiple of lines in a text area and when they hit enter it goes down to the next line and it put it in the database in there correctly but when i go to show the users information it comes up all on one line what do i do to make it where they dont have to put in < br> for a enter?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

If I understood what you want ,yeah no problem,

PHP Code: [ Select ]
//...
 
$msg_to_insert = preg_replace ("#(\n)#","<br />",$_POST["message"]);
 
 
  1. //...
  2.  
  3. $msg_to_insert = preg_replace ("#(\n)#","<br />",$_POST["message"]);
  4.  
  5.  

all the carriage return typed in the texarea are replace by "<br />" before inserting in DB.
so you just do nothing else , that'll show the carrage returns when you will display the message
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

so basically where do i put it in if this is my code?

PHP Code: [ Select ]
 
<?
 
 
 
include("session.php");
 
?>
 
<?
 
     $database->updateUserProfile($username, $_POST['profile'], $_POST['likes'], $_POST['dislikes'], $_POST['music'], $_POST['aim'], $_POST['age'], $_POST['city'], $_POST['state'], $_POST['sex'], $_POST['yahoo'], $_POST['msn'], $_POST['link'], $_POST['sexuality'], $_POST['country']);
 
                     header("Location: ../userinfo.php?user=$username");
 
?>
  1.  
  2. <?
  3.  
  4.  
  5.  
  6. include("session.php");
  7.  
  8. ?>
  9.  
  10. <?
  11.  
  12.      $database->updateUserProfile($username, $_POST['profile'], $_POST['likes'], $_POST['dislikes'], $_POST['music'], $_POST['aim'], $_POST['age'], $_POST['city'], $_POST['state'], $_POST['sex'], $_POST['yahoo'], $_POST['msn'], $_POST['link'], $_POST['sexuality'], $_POST['country']);
  13.  
  14.                      header("Location: ../userinfo.php?user=$username");
  15.  
  16. ?>
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Depending on wich field of the form is supposed to be a texarea, just do that stuf on the right $_POST juste before updateUserProfile() call.

ex :
PHP Code: [ Select ]
 
include("session.php");
 
$_POST['likes'] = preg_replace ("#(\n)#","<br />",$_POST["likes"]);
 
//do the same stuff for whatelse $_POST[] needs to be checked
 
$database->updateUserProfile($username, $_POST['profile'], $_POST['likes'], $_POST['dislikes'], $_POST['music'], $_POST['aim'], $_POST['age'], $_POST['city'], $_POST['state'], $_POST['sex'], $_POST['yahoo'], $_POST['msn'], $_POST['link'], $_POST['sexuality'], $_POST['country']);
 
header("Location: ../userinfo.php?user=$username");
 
 
  1.  
  2. include("session.php");
  3.  
  4. $_POST['likes'] = preg_replace ("#(\n)#","<br />",$_POST["likes"]);
  5.  
  6. //do the same stuff for whatelse $_POST[] needs to be checked
  7.  
  8. $database->updateUserProfile($username, $_POST['profile'], $_POST['likes'], $_POST['dislikes'], $_POST['music'], $_POST['aim'], $_POST['age'], $_POST['city'], $_POST['state'], $_POST['sex'], $_POST['yahoo'], $_POST['msn'], $_POST['link'], $_POST['sexuality'], $_POST['country']);
  9.  
  10. header("Location: ../userinfo.php?user=$username");
  11.  
  12.  



If all the fields need to be check you can loop so :
PHP Code: [ Select ]
 
include("session.php");
 
foreach ($_POST as $key=>$value)
 
   $_POST[$key] = preg_replace ("#(\n)#","<br />",$value);
 
$database->updateUserProfile($username, $_POST['profile'], $_POST['likes'], $_POST['dislikes'], $_POST['music'], $_POST['aim'], $_POST['age'], $_POST['city'], $_POST['state'], $_POST['sex'], $_POST['yahoo'], $_POST['msn'], $_POST['link'], $_POST['sexuality'], $_POST['country']);
 
header("Location: ../userinfo.php?user=$username");
 
 
  1.  
  2. include("session.php");
  3.  
  4. foreach ($_POST as $key=>$value)
  5.  
  6.    $_POST[$key] = preg_replace ("#(\n)#","<br />",$value);
  7.  
  8. $database->updateUserProfile($username, $_POST['profile'], $_POST['likes'], $_POST['dislikes'], $_POST['music'], $_POST['aim'], $_POST['age'], $_POST['city'], $_POST['state'], $_POST['sex'], $_POST['yahoo'], $_POST['msn'], $_POST['link'], $_POST['sexuality'], $_POST['country']);
  9.  
  10. header("Location: ../userinfo.php?user=$username");
  11.  
  12.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

ok that work but when the user go to edit the profile again it puts in a extra <br> than nessorly
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

OK you have to fill the texarea before re-edit with <br /> turned back to \n.

<textarea>.preg_replace("#(<br />)#, "\n", $message_to_edit).</textarea>

ask any question ;-)
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

PHP Code: [ Select ]
<? echo "<textarea name='profile' cols='75' rows='10' class='textarea' wrap=virtual>".$req_user_profile['profile']."</textarea>";?>
so where would that go in there?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

an another way, insert the texareas like there are and add the <br /> just before displaying stuff
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

users are going to be edit there profile ?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

you don't do the preg_replace just before updateUserProfile() so the mess are stored like there are typed(without "<br />".
Like it was before, and you add the <br /> at the last moment just for the displaying stuff :

Code: [ Select ]
 <?
/* Requested Username error checking */
$req_user = $_GET['user'];
if(!$req_user || strlen($req_user) == 0 ||
  !eregi("^([0-9a-z])+$", $req_user) ||
  !$database->usernameTaken($req_user)){
  die("Username not registered ");
}


/* Display requested user information */
$rs_pointer = $database->getUserComments($req_user);
?>
     <br>
     <table width="100%" border="0" class="comments">
     <?php
     while($req_user_postusername = mysql_fetch_array($rs_pointer))
     {
         echo "<tr><td width=\"24%\">".$req_user_postusername['username']."</td>"; 
       echo "<td width=\"76%\">".preg_replace("#(\n)#", "<br />", $req_user_postusername['comment'])."</td></tr>\n";
      }
      ?>
     </table>
 </p>
  1.  <?
  2. /* Requested Username error checking */
  3. $req_user = $_GET['user'];
  4. if(!$req_user || strlen($req_user) == 0 ||
  5.   !eregi("^([0-9a-z])+$", $req_user) ||
  6.   !$database->usernameTaken($req_user)){
  7.   die("Username not registered ");
  8. }
  9. /* Display requested user information */
  10. $rs_pointer = $database->getUserComments($req_user);
  11. ?>
  12.      <br>
  13.      <table width="100%" border="0" class="comments">
  14.      <?php
  15.      while($req_user_postusername = mysql_fetch_array($rs_pointer))
  16.      {
  17.          echo "<tr><td width=\"24%\">".$req_user_postusername['username']."</td>"; 
  18.        echo "<td width=\"76%\">".preg_replace("#(\n)#", "<br />", $req_user_postusername['comment'])."</td></tr>\n";
  19.       }
  20.       ?>
  21.      </table>
  22.  </p>
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

thank you so much
  • knexor2
  • Proficient
  • Proficient
  • User avatar
  • Posts: 445
  • Loc: US

Post 3+ Months Ago

Eh...just thought I'd throw out this little function for you...

nl2br()
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

and that does?
  • knexor2
  • Proficient
  • Proficient
  • User avatar
  • Posts: 445
  • Loc: US

Post 3+ Months Ago

Click the link :P

It places <br />'s before each newline in the given string.

nl2br("Hello\nworld") = Hello<br />\nworld
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

ok thank you for the comment thing and things but now i was wondering on how i can delete them like a piticular comment. I have put in like a id system in the database.

Image

that is what it looks like now. can anybody help me?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

HI, I would be happy to help you but I don't really understand the question in fact :-)
What does "piticular" mean, I found nothing on english-french traductors :scratchhead: .

Do you mean you've got the comment ID and want to delete him?

in a usual way you do :
PHP Code: [ Select ]
//...
 
$q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$given_id." LIMIT 1";
 
mysql_query($q) or die (mysql_error()."<br />".$q);
 
 
  1. //...
  2.  
  3. $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$given_id." LIMIT 1";
  4.  
  5. mysql_query($q) or die (mysql_error()."<br />".$q);
  6.  
  7.  

Or maybe you want a more complex delete based on a table join?
or what about "like a ID system"?
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

ok what i want to do is put a button under reply to post that says delete and have it delete that comment. and i have each of the comments a automatic id number!
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

forget this one, I quoted myself instead of edit :-)
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Ok , so that's very simple,

While querying the comments in order to display them, think about getting the comment ID,
dipslay a self link (to the same script but with a parameter del=id_comment to remove) for example :


just bellow the reply link :
PHP Code: [ Select ]
//...
 
print "<a href=\"".$_SERVER["PHP_SELF"]."?del=".$data["id_comment"]."\">Remove</a>";
 
 
  1. //...
  2.  
  3. print "<a href=\"".$_SERVER["PHP_SELF"]."?del=".$data["id_comment"]."\">Remove</a>";
  4.  
  5.  


At the biggining of this same script you just test $_GET["del"], that'll mean that the link was clicked before and you 've got to do a delete stuff (assuming that TBL_COMMENT has been defined):
PHP Code: [ Select ]
//...
 
if(isset($_GET["del"]))
 
{
 
   $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET["del"]." LIMIT 1";
 
   mysql_query($q) or die (mysql_error()."<br />".$q);
 
}
 
 
  1. //...
  2.  
  3. if(isset($_GET["del"]))
  4.  
  5. {
  6.  
  7.    $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET["del"]." LIMIT 1";
  8.  
  9.    mysql_query($q) or die (mysql_error()."<br />".$q);
  10.  
  11. }
  12.  
  13.  

And then, once this comment isn't anymore in the DB, go on with the comment displaying stuff like you've yet made it, thinking about adding the remove links abobe for each comment ...

In fact, the comment displaying script will call itself saying do a delete stuff before showing the comment
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

gisele wrote:
PHP Code: [ Select ]
//...
if(isset($_GET["del"]))
{
   $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET["del"]." LIMIT 1";
   mysql_query($q) or die (mysql_error()."<br />".$q);
}
 
  1. //...
  2. if(isset($_GET["del"]))
  3. {
  4.    $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET["del"]." LIMIT 1";
  5.    mysql_query($q) or die (mysql_error()."<br />".$q);
  6. }
  7.  


so this right here do i put it in my database.php or where?

also for some reason this will not work and i dont know why. its deleting a user from the database.

PHP Code: [ Select ]
   function procDeleteUser(){
 
      global $session, $database, $form;
 
      /* Username error checking */
 
      $subuser = $this->checkUsername("deluser");
 
     
 
      /* Errors exist, have user correct them */
 
      if($form->num_errors > 0){
 
         $_SESSION['value_array'] = $_POST;
 
         $_SESSION['error_array'] = $form->getErrorArray();
 
         header("Location: ".$session->referrer);
 
      }
 
      /* Delete user from database */
 
      else{  
 
      if($database->AdminDeleteComments($deluser)){
 
        if($database->AdminDeleteProfile($deluser)){
 
       if($database->AdminDeleteMoreComments($deluser)){
 
       if($database->AdminDeleteActive($deluser)){
 
         }
 
         }
 
       }
 
       }
 
       header("Location:".$session->referrer);
 
      }
 
   }
  1.    function procDeleteUser(){
  2.  
  3.       global $session, $database, $form;
  4.  
  5.       /* Username error checking */
  6.  
  7.       $subuser = $this->checkUsername("deluser");
  8.  
  9.      
  10.  
  11.       /* Errors exist, have user correct them */
  12.  
  13.       if($form->num_errors > 0){
  14.  
  15.          $_SESSION['value_array'] = $_POST;
  16.  
  17.          $_SESSION['error_array'] = $form->getErrorArray();
  18.  
  19.          header("Location: ".$session->referrer);
  20.  
  21.       }
  22.  
  23.       /* Delete user from database */
  24.  
  25.       else{  
  26.  
  27.       if($database->AdminDeleteComments($deluser)){
  28.  
  29.         if($database->AdminDeleteProfile($deluser)){
  30.  
  31.        if($database->AdminDeleteMoreComments($deluser)){
  32.  
  33.        if($database->AdminDeleteActive($deluser)){
  34.  
  35.          }
  36.  
  37.          }
  38.  
  39.        }
  40.  
  41.        }
  42.  
  43.        header("Location:".$session->referrer);
  44.  
  45.       }
  46.  
  47.    }


and this is the databse
PHP Code: [ Select ]
function AdminDeleteComments($deluser){
 
        $q = "DELETE from ".TBL_COMMENTS." where postusername = '$subuser'";
 
      return mysql_query($q, $this->connection);
 
           }
 
               function AdminDeleteMoreComments($deluser){
 
        $q = "DELETE from ".TBL_COMMENTS." where username = '$subuser'";
 
      return mysql_query($q, $this->connection);
 
           }  
 
         
 
    function AdminDeleteProfile($deluser){
 
        $q = "DELETE from ".TBL_USERS." where username = '$subuser'";
 
      return mysql_query($q, $this->connection);
 
           }
 
          function AdminDeleteActive($deluser){
 
        $q = "DELETE from ".TBL_ACTIVE_USERS." where username = '$subuser'";
 
      return mysql_query($q, $this->connection);
 
           }
  1. function AdminDeleteComments($deluser){
  2.  
  3.         $q = "DELETE from ".TBL_COMMENTS." where postusername = '$subuser'";
  4.  
  5.       return mysql_query($q, $this->connection);
  6.  
  7.            }
  8.  
  9.                function AdminDeleteMoreComments($deluser){
  10.  
  11.         $q = "DELETE from ".TBL_COMMENTS." where username = '$subuser'";
  12.  
  13.       return mysql_query($q, $this->connection);
  14.  
  15.            }  
  16.  
  17.          
  18.  
  19.     function AdminDeleteProfile($deluser){
  20.  
  21.         $q = "DELETE from ".TBL_USERS." where username = '$subuser'";
  22.  
  23.       return mysql_query($q, $this->connection);
  24.  
  25.            }
  26.  
  27.           function AdminDeleteActive($deluser){
  28.  
  29.         $q = "DELETE from ".TBL_ACTIVE_USERS." where username = '$subuser'";
  30.  
  31.       return mysql_query($q, $this->connection);
  32.  
  33.            }


what is wrong with that? it is not working at all? why is that?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Hi,
the local variable name is changed
between
AdminDeleteComments($deluser)
and
where postusername = '$subuser'";

that should be :
where postusername = '$deluser'";


And my script yeah you can make it like a member function of database database::DeleteComment() (like user deleting ones).
And call it just before querying and displaying the comment
if(isset($_GET["del"]))
$database->DeleteComment();
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

hi i put the thing in for the comments and it did not work

PHP Code: [ Select ]
<a href=\"".$_SERVER["PHP_SELF"]."?del=".$data["id_comment"]."\">Delete Comment</a


and
PHP Code: [ Select ]
 <?php //...
 
if(isset($_GET["del"]))
 
$database->DeleteComment();
 
 ?>
  1.  <?php //...
  2.  
  3. if(isset($_GET["del"]))
  4.  
  5. $database->DeleteComment();
  6.  
  7.  ?>


and for the database
PHP Code: [ Select ]
function DeleteProfileComment(){
 
      $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET["del"]." LIMIT 1";  
 
       return mysql_query($q, $this->connection);  
 
      }
  1. function DeleteProfileComment(){
  2.  
  3.       $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET["del"]." LIMIT 1";  
  4.  
  5.        return mysql_query($q, $this->connection);  
  6.  
  7.       }




also that did not work for the admin thing

PHP Code: [ Select ]
else{  
 
      if($database->AdminDeleteComments($deluser)){
 
        if($database->AdminDeleteProfile($deluser)){
 
       if($database->AdminDeleteMoreComments($deluser)){
 
       if($database->AdminDeleteActive($deluser)){
 
         }
 
         }
 
       }
 
       }
 
       header("Location:".$session->referrer);
 
      }
  1. else{  
  2.  
  3.       if($database->AdminDeleteComments($deluser)){
  4.  
  5.         if($database->AdminDeleteProfile($deluser)){
  6.  
  7.        if($database->AdminDeleteMoreComments($deluser)){
  8.  
  9.        if($database->AdminDeleteActive($deluser)){
  10.  
  11.          }
  12.  
  13.          }
  14.  
  15.        }
  16.  
  17.        }
  18.  
  19.        header("Location:".$session->referrer);
  20.  
  21.       }


PHP Code: [ Select ]
  function AdminDeleteComments($deluser){
 
        $q = "DELETE from ".TBL_COMMENTS." where postusername = '$deluser'";
 
      return mysql_query($q, $this->connection);
 
           }
 
               function AdminDeleteMoreComments($deluser){
 
        $q = "DELETE from ".TBL_COMMENTS." where username = '$deluser'";
 
      return mysql_query($q, $this->connection);
 
           }  
 
         
 
    function AdminDeleteProfile($deluser){
 
        $q = "DELETE from ".TBL_USERS." where username = '$deluser'";
 
      return mysql_query($q, $this->connection);
 
           }
 
          function AdminDeleteActive($deluser){
 
        $q = "DELETE from ".TBL_ACTIVE_USERS." where username = '$deluser'";
 
      return mysql_query($q, $this->connection);
 
           }
  1.   function AdminDeleteComments($deluser){
  2.  
  3.         $q = "DELETE from ".TBL_COMMENTS." where postusername = '$deluser'";
  4.  
  5.       return mysql_query($q, $this->connection);
  6.  
  7.            }
  8.  
  9.                function AdminDeleteMoreComments($deluser){
  10.  
  11.         $q = "DELETE from ".TBL_COMMENTS." where username = '$deluser'";
  12.  
  13.       return mysql_query($q, $this->connection);
  14.  
  15.            }  
  16.  
  17.          
  18.  
  19.     function AdminDeleteProfile($deluser){
  20.  
  21.         $q = "DELETE from ".TBL_USERS." where username = '$deluser'";
  22.  
  23.       return mysql_query($q, $this->connection);
  24.  
  25.            }
  26.  
  27.           function AdminDeleteActive($deluser){
  28.  
  29.         $q = "DELETE from ".TBL_ACTIVE_USERS." where username = '$deluser'";
  30.  
  31.       return mysql_query($q, $this->connection);
  32.  
  33.            }
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

well i got the admin delete user working but the delete comment is still not working from the code that you had gaven me!
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Hi,

could you show me the concerned parts (delete function + function call + link) of the script please, it'll be easier to see what detail is wrong and to make it work
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

Database
PHP Code: [ Select ]
     
 
   function DeleteProfileComment($del){
 
      $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET[$del]." LIMIT 1";  
 
       return mysql_query($q, $this->connection);  
 
      }
  1.      
  2.  
  3.    function DeleteProfileComment($del){
  4.  
  5.       $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET[$del]." LIMIT 1";  
  6.  
  7.        return mysql_query($q, $this->connection);  
  8.  
  9.       }


my comments
PHP Code: [ Select ]
<?php //...
 
if(isset($_GET["del"]))
 
$database->DeleteComment("del");
 
 ?> <?php
 
          while($req_user_postusername = mysql_fetch_array($rs_pointer))
 
          {
 
echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>
 
 <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />
 
   <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br><a href=\"".$_SERVER["PHP_SELF"]."?del=".$data["id_comment"]."\">Delete Comment</a></span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>
 
 
 
 
 
";
 
 
 
           }
 
           ?>
  1. <?php //...
  2.  
  3. if(isset($_GET["del"]))
  4.  
  5. $database->DeleteComment("del");
  6.  
  7.  ?> <?php
  8.  
  9.           while($req_user_postusername = mysql_fetch_array($rs_pointer))
  10.  
  11.           {
  12.  
  13. echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>
  14.  
  15.  <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />
  16.  
  17.    <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br><a href=\"".$_SERVER["PHP_SELF"]."?del=".$data["id_comment"]."\">Delete Comment</a></span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>
  18.  
  19.  
  20.  
  21.  
  22.  
  23. ";
  24.  
  25.  
  26.  
  27.            }
  28.  
  29.            ?>
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Well first there's no use a parameter to pass in delete comment function.

$database->DeleteComment("del"); (in the call)

function DeleteProfileComment($del){ (in the class)

you can do this

$database->DeleteComment("del"); )

function DeleteProfileComment($del){ ()

Because $_GET is a superglobal and can be accesses from any where and any context.

just do this :

PHP Code: [ Select ]
 
$q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET["del"]." LIMIT 1";  
 
 
  1.  
  2. $q = "DELETE FROM ".TBL_COMMENTS." WHERE ID_FIELD = ".$_GET["del"]." LIMIT 1";  
  3.  
  4.  

and no parameter for the function , that'll be enough.

Anyway that's not the problem that can work.

In fact the problem seems to be in the comment deleting link .

You use $data["id_comment"] but that was just a generic example, in fact you told be that you had an ID system for the comment but I've got no idea of how you get it just before that's why I put $data["id_comment"] as an example.
I assumed that you retrieved in the same query that retrieves the comments informations.
You should do so anyway, and change my example $data[« id_comment »] by the right value something like $req_user_postusername['something'] (something =>name of the id field)

Ask any question ;-)
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

you have lost me. i am confused on what you are saying. from the code that i put on here can you give me the code to put in?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

here, see I replaced $data["id_comment"] in that part by $req_user_postusername['comment_id'].
But all is left to do, is replace comment_id by the real name of the ID field in the comment table. In fact I've got no idea of the name you gave to it in the database.
SO the right value will be in that link so that the right value will be passed $_GET["del"]
PHP Code: [ Select ]
 
//...  
 
if(isset($_GET["del"]))  
 
$database->DeleteComment("del");
 
 ?> <?php  
 
          while($req_user_postusername = mysql_fetch_array($rs_pointer))  
 
          {  
 
echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>
 
 <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />
 
   <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br><a href=\"".$_SERVER["PHP_SELF"]."?del=".$req_user_postusername['comment_id']."\">Delete Comment</a></span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>
 
 
 
 
 
";
 
 
 
           }  
 
 
  1.  
  2. //...  
  3.  
  4. if(isset($_GET["del"]))  
  5.  
  6. $database->DeleteComment("del");
  7.  
  8.  ?> <?php  
  9.  
  10.           while($req_user_postusername = mysql_fetch_array($rs_pointer))  
  11.  
  12.           {  
  13.  
  14. echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>
  15.  
  16.  <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />
  17.  
  18.    <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br><a href=\"".$_SERVER["PHP_SELF"]."?del=".$req_user_postusername['comment_id']."\">Delete Comment</a></span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>
  19.  
  20.  
  21.  
  22.  
  23.  
  24. ";
  25.  
  26.  
  27.  
  28.            }  
  29.  
  30.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

ok it will come up with the comment id number but when i click on delete it does nothing and comes up to http://www.gothicgreenwire.com/mycomments.php?del=114 and it says username not registured because it need to say http://www.gothicgreenwire.com/mycommen ... user=admin or what ever there username is.

here is the database php
PHP Code: [ Select ]
function DeleteProfileComment($del){
 
      $q = "DELETE FROM ".TBL_COMMENTS." WHERE id = ".$_GET[$del]." LIMIT 1";  
 
       return mysql_query($q, $this->connection);  
 
      }
  1. function DeleteProfileComment($del){
  2.  
  3.       $q = "DELETE FROM ".TBL_COMMENTS." WHERE id = ".$_GET[$del]." LIMIT 1";  
  4.  
  5.        return mysql_query($q, $this->connection);  
  6.  
  7.       }


here is the mycomments php
PHP Code: [ Select ]
<?php //...  
 
if(isset($_GET["del"]))  
 
$database->DeleteComment("del");  
 
 ?> <?php  
 
          while($req_user_postusername = mysql_fetch_array($rs_pointer))  
 
          {  
 
echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>  
 
 <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />  
 
   <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br><a href=\"".$_SERVER["PHP_SELF"]."?del=".$req_user_postusername['id']."\">Delete Comment</a></span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>  
 
 
 
 
 
";  
 
 
 
           } ?>
  1. <?php //...  
  2.  
  3. if(isset($_GET["del"]))  
  4.  
  5. $database->DeleteComment("del");  
  6.  
  7.  ?> <?php  
  8.  
  9.           while($req_user_postusername = mysql_fetch_array($rs_pointer))  
  10.  
  11.           {  
  12.  
  13. echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>  
  14.  
  15.  <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />  
  16.  
  17.    <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br><a href=\"".$_SERVER["PHP_SELF"]."?del=".$req_user_postusername['id']."\">Delete Comment</a></span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. ";  
  24.  
  25.  
  26.  
  27.            } ?>
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

So no problem just add also this parameter in the target url :
PHP Code: [ Select ]
 
//...  
 
if(isset($_GET["del"]))  
 
$database->DeleteComment("del");
 
 ?> <?php  
 
          while($req_user_postusername = mysql_fetch_array($rs_pointer))  
 
          {  
 
echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>
 
 <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />
 
   <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br><a href=\"".$_SERVER["PHP_SELF"]."?user=".$req_user_postusername['username']."&amp;del=".$req_user_postusername['comment_id']."\">Delete Comment</a></span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>
 
 
 
 
 
";
 
 
 
           }  
 
 
  1.  
  2. //...  
  3.  
  4. if(isset($_GET["del"]))  
  5.  
  6. $database->DeleteComment("del");
  7.  
  8.  ?> <?php  
  9.  
  10.           while($req_user_postusername = mysql_fetch_array($rs_pointer))  
  11.  
  12.           {  
  13.  
  14. echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>
  15.  
  16.  <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />
  17.  
  18.    <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br><a href=\"".$_SERVER["PHP_SELF"]."?user=".$req_user_postusername['username']."&amp;del=".$req_user_postusername['comment_id']."\">Delete Comment</a></span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>
  19.  
  20.  
  21.  
  22.  
  23.  
  24. ";
  25.  
  26.  
  27.  
  28.            }  
  29.  
  30.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

still did not work. why wont you take a look on there http://www.gothicgreenwire.com
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

argh!
sorry it couldn't work,
I did not take you last script with $req_user_postusername['id'] :-)
I cannot test since can't login

try this :

PHP Code: [ Select ]
 
//...    
 
if(isset($_GET["del"]))    
 
$database->DeleteComment("del");  
 
 ?> <?php    
 
          while($req_user_postusername = mysql_fetch_array($rs_pointer))    
 
          {    
 
echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>  
 
 <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />  
 
   <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br><a href=\"".$_SERVER["PHP_SELF"]."?user=".$req_user_postusername['username']."&amp;del=".$req_user_postusername['id']."\">Delete Comment</a></span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>  
 
 
 
 
 
";  
 
 
 
           }
 
 
  1.  
  2. //...    
  3.  
  4. if(isset($_GET["del"]))    
  5.  
  6. $database->DeleteComment("del");  
  7.  
  8.  ?> <?php    
  9.  
  10.           while($req_user_postusername = mysql_fetch_array($rs_pointer))    
  11.  
  12.           {    
  13.  
  14. echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>  
  15.  
  16.  <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />  
  17.  
  18.    <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br><a href=\"".$_SERVER["PHP_SELF"]."?user=".$req_user_postusername['username']."&amp;del=".$req_user_postusername['id']."\">Delete Comment</a></span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>  
  19.  
  20.  
  21.  
  22.  
  23.  
  24. ";  
  25.  
  26.  
  27.  
  28.            }
  29.  
  30.  


by the way, you should put the user name in the url,
once it'll work you should think about session in PHP.
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

It's geting late here, I go to bed, I'll check this thread tomorow morning :-)
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

here is the new code i added where you have to be loged in also but i still cant figure out why its not working.

PHP Code: [ Select ]
<?php //...  
 
if(isset($_GET["del"]))  
 
$database->DeleteComment("del");  
 
 ?> <?php  
 
          while($req_user_postusername = mysql_fetch_array($rs_pointer))  
 
          {  
 
echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>  
 
 <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />  
 
   <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br>";
 
   if($session->logged_in){ echo"<a href=\"".$_SERVER["PHP_SELF"]."?user=".$req_user_postusername['username']."&amp;del=".$req_user_postusername['comment_id']."\">Delete Comment</a>";}
 
   echo "</span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>";  
 
 
 
           } ?>
  1. <?php //...  
  2.  
  3. if(isset($_GET["del"]))  
  4.  
  5. $database->DeleteComment("del");  
  6.  
  7.  ?> <?php  
  8.  
  9.           while($req_user_postusername = mysql_fetch_array($rs_pointer))  
  10.  
  11.           {  
  12.  
  13. echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>  
  14.  
  15.  <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />  
  16.  
  17.    <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br>";
  18.  
  19.    if($session->logged_in){ echo"<a href=\"".$_SERVER["PHP_SELF"]."?user=".$req_user_postusername['username']."&amp;del=".$req_user_postusername['comment_id']."\">Delete Comment</a>";}
  20.  
  21.    echo "</span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>";  
  22.  
  23.  
  24.  
  25.            } ?>
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

noooooo !

The new code you added isn't the last corrected one ! :-)
in fact this code is wrong because it kept "del=".$data["id_comment"]." instead in "del=".$req_user_postusername["id"]."

So the right code is :

PHP Code: [ Select ]
 
//...    
 
if(isset($_GET["del"]))    
 
$database->DeleteComment("del");    
 
 ?> <?php    
 
          while($req_user_postusername = mysql_fetch_array($rs_pointer))    
 
          {    
 
echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>    
 
 <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />    
 
   <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br><a href=\"".$_SERVER["PHP_SELF"]."?user=".$req_user_postusername['username']."&amp;del=".$req_user_postusername['id']."\">Delete Comment</a></span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>    
 
 
 
 
 
";    
 
 
 
           }
 
 
  1.  
  2. //...    
  3.  
  4. if(isset($_GET["del"]))    
  5.  
  6. $database->DeleteComment("del");    
  7.  
  8.  ?> <?php    
  9.  
  10.           while($req_user_postusername = mysql_fetch_array($rs_pointer))    
  11.  
  12.           {    
  13.  
  14. echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>    
  15.  
  16.  <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />    
  17.  
  18.    <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br><a href=\"".$_SERVER["PHP_SELF"]."?user=".$req_user_postusername['username']."&amp;del=".$req_user_postusername['id']."\">Delete Comment</a></span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>    
  19.  
  20.  
  21.  
  22.  
  23.  
  24. ";    
  25.  
  26.  
  27.  
  28.            }
  29.  
  30.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

actually i fixed it and i ment to post that but for some reason you have to click the link twice to get the comment to delete..

PHP Code: [ Select ]
<?php //...    
 
if(isset($_GET["del"]))
 
$database->DeleteProfileComment("del");  
 
   
 
          while($req_user_postusername = mysql_fetch_array($rs_pointer))    
 
          {    
 
echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>  
 
 <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />  
 
   <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br>";
 
    if($session->logged_in){ echo"<a href=\"".$_SERVER["PHP_SELF"]."?del=".$req_user_postusername['id']."\">Delete Comment</a>";}
 
    echo "</span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>";  
 
 
 
           } ?>  
  1. <?php //...    
  2.  
  3. if(isset($_GET["del"]))
  4.  
  5. $database->DeleteProfileComment("del");  
  6.  
  7.    
  8.  
  9.           while($req_user_postusername = mysql_fetch_array($rs_pointer))    
  10.  
  11.           {    
  12.  
  13. echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>  
  14.  
  15.  <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />  
  16.  
  17.    <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br>";
  18.  
  19.     if($session->logged_in){ echo"<a href=\"".$_SERVER["PHP_SELF"]."?del=".$req_user_postusername['id']."\">Delete Comment</a>";}
  20.  
  21.     echo "</span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>";  
  22.  
  23.  
  24.  
  25.            } ?>  
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

No in fact that works but the delete function call is between the comment querying stuff and the comments displaying stuff.

SO when you retrived the comments, the delete hasn't been done yet.
And when you click for the second time, the delete stuff was done thow the delete comment is still displayed.

Well in fact I don't know if you get what I try to explain, but anyway you just have to move :

PHP Code: [ Select ]
 
if(isset($_GET["del"]))  
 
$database->DeleteProfileComment("del");
 
 
  1.  
  2. if(isset($_GET["del"]))  
  3.  
  4. $database->DeleteProfileComment("del");
  5.  
  6.  

just before
PHP Code: [ Select ]
 
$rs_pointer = $database->getUserComments($req_user);
 
 
  1.  
  2. $rs_pointer = $database->getUserComments($req_user);
  3.  
  4.  


so that the delete stuff is called before the query that retrieves the comments ;-)

did you get that?
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

it is befor it no?

PHP Code: [ Select ]
<?php //...    
 
if(isset($_GET["del"]))  
 
$database->DeleteProfileComment("del");    
 
   
 
          while($req_user_postusername = mysql_fetch_array($rs_pointer))    
 
          {    
 
echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>    
 
 <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />    
 
   <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br>";  
 
    if($session->logged_in){ echo"<a href=\"".$_SERVER["PHP_SELF"]."?del=".$req_user_postusername['id']."\">Delete Comment</a>";}  
 
    echo "</span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>";    
 
 
 
           } ?>
  1. <?php //...    
  2.  
  3. if(isset($_GET["del"]))  
  4.  
  5. $database->DeleteProfileComment("del");    
  6.  
  7.    
  8.  
  9.           while($req_user_postusername = mysql_fetch_array($rs_pointer))    
  10.  
  11.           {    
  12.  
  13. echo "<table width='100%' border='1' cellpadding='1' cellspacing='1' class=main>    
  14.  
  15.  <tr><td width='24%' align='center' valign='middle' bordercolor='#000000'><div align='center'><span class='main'><a href='userinfo.php?user=".$req_user_postusername['username']."'>".$req_user_postusername['username']."</a><br />    
  16.  
  17.    <br /><a href='comment.php?user=".$req_user_postusername['username']."'>Reply to post!</a><br>";  
  18.  
  19.     if($session->logged_in){ echo"<a href=\"".$_SERVER["PHP_SELF"]."?del=".$req_user_postusername['id']."\">Delete Comment</a>";}  
  20.  
  21.     echo "</span></div></td><td width='74%' bordercolor='#000000'><table width='100%' border='0'><tr><td align='right'>".$req_user_postusername['date']."</span><span class='main'></td></tr><tr><td>".preg_replace('#(\n)#', "<br />", $req_user_postusername['comment'])."</td></tr></table></td></tr></table>";    
  22.  
  23.  
  24.  
  25.            } ?>
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

HI,

not at all, like it is, when you call the comment delete function, the query to retrieve the comments has been yet submitted with :
$rs_pointer = $database->getUserComments($req_user);

and while($req_user_postusername = mysql_fetch_array($rs_pointer)) ...etc. is nothing but a loop that browse the yet built up results set.

so this is like you should order the statments :


PHP Code: [ Select ]
 
//first comment delete stuff :
 
if(isset($_GET["del"]))  
 
   $database->DeleteProfileComment("del");
 
//then querying the comments in the database :  
 
$rs_pointer = $database->getUserComments($req_user);
 
 
  1.  
  2. //first comment delete stuff :
  3.  
  4. if(isset($_GET["del"]))  
  5.  
  6.    $database->DeleteProfileComment("del");
  7.  
  8. //then querying the comments in the database :  
  9.  
  10. $rs_pointer = $database->getUserComments($req_user);
  11.  
  12.  


and then you can do the displaying stuff ( links and comments )


If you're not sure, just show all the entire comment script and I'll do the changes.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

so basically you are telling me to take out while($req_user_postusername = mysql_fetch_array($rs_pointer))?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

No

keep it like it is, I just tell you to move

if(isset($_GET["del"]))
$database->DeleteProfileComment("del");

just above
$rs_pointer = $database->getUserComments($req_user);
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

ok actually i like it on how it was where you have to click it twice just to make sute that the user had the right comment that they wanted to delete and also say the user deletes all there comments and then it comes up with this error

Code: [ Select ]
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/happykj/public_html/mycomments.php on line 75



why is that. and also do you know how to do picture uploading and showing in a database or do you know what i mean? also because i want to do more then just one picture


This is a edited post

I am having the user do a photobucket account and take the url for this picture thing but the problem is is that its streching out the users pictures how can i make that stop but have it some how in thies demensions

Code: [ Select ]
<tr class="mainpic_title">
     <td >
      <div align="center"><? echo "<img src='".$req_user_info['mainpic']."' width='500' height='375'>"; ?></div>     
             </td>
     </tr>
  1. <tr class="mainpic_title">
  2.      <td >
  3.       <div align="center"><? echo "<img src='".$req_user_info['mainpic']."' width='500' height='375'>"; ?></div>     
  4.              </td>
  5.      </tr>
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

might anybody know?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

HI,

I'm very sorry I didn't understand the post.
(you probably reached my english limits :-))
is the double click problem fixed?

What have you a php error for?

can you show more about the code around the line 75 code?

Yes, I know how to do picture dowloading :-)

What kind of streching? if you force the displaying dimension (width and height) that'll stretch the picture.
maybe you talk about horizontal/vertical stretching that you want to correct?
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

Also how can i do the downloading of pictures for a user with a limit number of alloud pictures..

i fixed the error in the comments
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

HI,

this is the kind of form for uploading files :
Code: [ Select ]
<html>
  <body>
    <form enctype="multipart/form-data" action="fileupload.php" method="post">
      <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
      File to upload : <input type="file" name="my_file" />
      <input type="submit" Value="upload" />
    </form>
  </body>
</html>
  1. <html>
  2.   <body>
  3.     <form enctype="multipart/form-data" action="fileupload.php" method="post">
  4.       <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
  5.       File to upload : <input type="file" name="my_file" />
  6.       <input type="submit" Value="upload" />
  7.     </form>
  8.   </body>
  9. </html>


See I put "fileupload.php" but you'll put the name of the script that treat the form.

And then in the action script you can use/check those main values around the dowloaded file :
THey are acceesed with the associative array FILE[], the name in [] is the field name of your form (I call it "my_file" in the form)
$_FILES["my_file"]["tmp_name"] give you the temporary path and and name of the file on the server once dowloaded (you see like the stanges path and name of dowloaded files of your mail application or whatelse)

$_FILES["my_file"]["name"] Name of the file when the client uploaded it.(for example you can check and limit the allowed extentions)
$_FILES["my_file"]["size"] size of the file (bytes) so that you can check and limit the size
$_FILES["my_file"]["type"]"MIME type" of the file (ex: text/html, image/gif, etc.)

And then you can copy the file in a choosen directory :

copy($_FILES["my_file"]["name"], "$destination_path.$name_of_the_file");

So you can have a table that stores all the paths and name with a field that is a reference on user id.


About your question, If you want to check if the limit of dowloaded file is reached make a query that counts the rows in this table with the given user_id :

SELECT COUNT(*) AS 'DL_COUNT' FROM image_table WHERE user_id = given_value

Then this will return a unique row with the COUNT of yet dowloaded file.

Feel free to ask any question on the above.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

i am a total noobie when it comes to uploading files. can you create me a full working script maybe? and also when you upload the file it is going to send it to that username?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Ok, I'll try do to a little something, but you have to give me a little time, now it's 10:05 am And I'm workin at my job (yeak it doesn't feel like I'm :-).

But later I'll try to show here an example of picture managment for the users ( form + treatment + pictures tables creating).
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

well basically on how i want it is where a user can upload there picture and have it show on a page called userpictures.php. and where they can delete there pictures if they want to. Also I want it where they have a limited about of pictures like for free account they have 15 and so on.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

Hey man how long do you think it will take you?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Hi,

Sorry i've got a life outside Ozzu :-)

your table will look like that :
Code: [ Select ]
#Structure de la table `picture`


CREATE TABLE `picture` (
 `picture_id` int(11) NOT NULL auto_increment,
 `name` varchar(100) NOT NULL,
 `size` mediumint(9) NOT NULL,
 `user_id` int(11) NOT NULL,
 PRIMARY KEY (`picture_id`)
) ENGINE=InnoDB;
  1. #Structure de la table `picture`
  2. CREATE TABLE `picture` (
  3.  `picture_id` int(11) NOT NULL auto_increment,
  4.  `name` varchar(100) NOT NULL,
  5.  `size` mediumint(9) NOT NULL,
  6.  `user_id` int(11) NOT NULL,
  7.  PRIMARY KEY (`picture_id`)
  8. ) ENGINE=InnoDB;


Create a directory just beside userpictures.php in the same directory and name it "pict" you will store the files in it.


In fact, I made a class, album.

PHP Code: [ Select ]
 
class album
 
{
 
   var $user_id;
 
   var $size_limit = 100000;
 
   var $nb_limit;
 
   var $stored_pictures;
 
   function album($user_id, $nb_limit = 5)
 
   {
 
      $this->user_id = $user_id;
 
      $this->nb_limit = $nb_limit;
 
      $this->size_limit = $size_limit;
 
   }
 
   function display_album()
 
   {
 
      $q = "SELECT picture_id, name, size FROM picture WHERE user_id=".$this->user_id;
 
      $this->stored_pictures = mysql_query($q) or die(mysql_error()."<br />".$q);
 
      if(mysql_num_rows($this->stored_pictures))
 
      {
 
         print "<table border=\"1\">\n<tr><td align=\"center\"><b>Name</b></td><td align=\"center\"><b>Size</b></td><td align=\"center\"><b>Picture</b></td><td align=\"center\"><b>Action</b></td></tr>\n";
 
         while($d = mysql_fetch_row($this->stored_pictures))
 
         {
 
            print "<tr><td>".$d[1]."</td><td align=\"center\">".$d[2]."</td><td align=\"center\"><img src=\"pict/".$d[1]."\" /></td>";
 
            print "<td align=\"center\"><a href=\"".$_SERVER["PHP_SELF"]."?del_pict_id=".$d[0]."\">Delete</a></td></tr>\n";
 
         }
 
         print "</table>\n";
 
      }
 
      else
 
         print "<p>No picture ! </p>\n";
 
   }
 
   function store_picture()
 
   {
 
      //$_FILE is a superglobal so you can get it from there
 
      foreach ($_FILES as $file)
 
      {
 
         print "<p>".$file['name']."<br />";
 
         print "temp :".$file['tmp_name']."<br />";
 
         print "type :".$file['type'] ."<br />";
 
         print "size :".$file['size'] ."<br />";
 
         print "error :".$file['error'] ."</p>";
 
         if($file['size'] >= $this->size_limit)
 
         {
 
            print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";
 
            return false;
 
         }
 
         if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))
 
         {
 
            $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', ".$this->user_id.")";
 
            mysql_query($q) or die(mysql_error()."<br />".$q);
 
         }
 
         else
 
         {
 
            print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";
 
            return false;
 
         }
 
         if(file_exists("pict/".$file['name']))
 
            $file['name'] .= $this->user_id;
 
         copy($file['tmp_name'], "pict/".$file['name']);
 
      }          
 
   }
 
   function delete_picture()
 
   {
 
      $q = "SELECT name FROM picture WHERE picture_id=".$_GET["del_pict_id"];
 
      $r = mysql_query($q) or die(mysql_error()."<br />".$q);
 
      $d = mysql_fetch_row($r);
 
      $file = "pict/".$d[0];
 
      $q = "DELETE FROM Picture WHERE picture_id=".$_GET["del_pict_id"]." LIMIT 1";
 
      mysql_query($q) or die(mysql_error()."<br />".$q);
 
      if(file_exists($file))
 
         unlink($file);
 
   }
 
   function display_upload_form($nb_file = 1)
 
   {
 
      if(!$this->nb_limit <= mysql_num_rows($this->stored_pictures))
 
      {
 
         print "<form method=\"post\" enctype=\"multipart/form-data\" action=\"".$_SERVER["PHP_SELF"]."?up=1\">\n";
 
         for($i = 0;$i < $nb_file;$i++)
 
            print "<p>\nPicucture N°".($i + 1)." : <input type=\"file\" name=\"file".$i."\" size=\"30\"></p>";
 
         print "<input type=\"submit\" value=\"upload\" />\n";
 
      }
 
      else
 
         print "<p>no more upload allowed !</p>";
 
   }
 
}
 
 
  1.  
  2. class album
  3.  
  4. {
  5.  
  6.    var $user_id;
  7.  
  8.    var $size_limit = 100000;
  9.  
  10.    var $nb_limit;
  11.  
  12.    var $stored_pictures;
  13.  
  14.    function album($user_id, $nb_limit = 5)
  15.  
  16.    {
  17.  
  18.       $this->user_id = $user_id;
  19.  
  20.       $this->nb_limit = $nb_limit;
  21.  
  22.       $this->size_limit = $size_limit;
  23.  
  24.    }
  25.  
  26.    function display_album()
  27.  
  28.    {
  29.  
  30.       $q = "SELECT picture_id, name, size FROM picture WHERE user_id=".$this->user_id;
  31.  
  32.       $this->stored_pictures = mysql_query($q) or die(mysql_error()."<br />".$q);
  33.  
  34.       if(mysql_num_rows($this->stored_pictures))
  35.  
  36.       {
  37.  
  38.          print "<table border=\"1\">\n<tr><td align=\"center\"><b>Name</b></td><td align=\"center\"><b>Size</b></td><td align=\"center\"><b>Picture</b></td><td align=\"center\"><b>Action</b></td></tr>\n";
  39.  
  40.          while($d = mysql_fetch_row($this->stored_pictures))
  41.  
  42.          {
  43.  
  44.             print "<tr><td>".$d[1]."</td><td align=\"center\">".$d[2]."</td><td align=\"center\"><img src=\"pict/".$d[1]."\" /></td>";
  45.  
  46.             print "<td align=\"center\"><a href=\"".$_SERVER["PHP_SELF"]."?del_pict_id=".$d[0]."\">Delete</a></td></tr>\n";
  47.  
  48.          }
  49.  
  50.          print "</table>\n";
  51.  
  52.       }
  53.  
  54.       else
  55.  
  56.          print "<p>No picture ! </p>\n";
  57.  
  58.    }
  59.  
  60.    function store_picture()
  61.  
  62.    {
  63.  
  64.       //$_FILE is a superglobal so you can get it from there
  65.  
  66.       foreach ($_FILES as $file)
  67.  
  68.       {
  69.  
  70.          print "<p>".$file['name']."<br />";
  71.  
  72.          print "temp :".$file['tmp_name']."<br />";
  73.  
  74.          print "type :".$file['type'] ."<br />";
  75.  
  76.          print "size :".$file['size'] ."<br />";
  77.  
  78.          print "error :".$file['error'] ."</p>";
  79.  
  80.          if($file['size'] >= $this->size_limit)
  81.  
  82.          {
  83.  
  84.             print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";
  85.  
  86.             return false;
  87.  
  88.          }
  89.  
  90.          if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))
  91.  
  92.          {
  93.  
  94.             $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', ".$this->user_id.")";
  95.  
  96.             mysql_query($q) or die(mysql_error()."<br />".$q);
  97.  
  98.          }
  99.  
  100.          else
  101.  
  102.          {
  103.  
  104.             print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";
  105.  
  106.             return false;
  107.  
  108.          }
  109.  
  110.          if(file_exists("pict/".$file['name']))
  111.  
  112.             $file['name'] .= $this->user_id;
  113.  
  114.          copy($file['tmp_name'], "pict/".$file['name']);
  115.  
  116.       }          
  117.  
  118.    }
  119.  
  120.    function delete_picture()
  121.  
  122.    {
  123.  
  124.       $q = "SELECT name FROM picture WHERE picture_id=".$_GET["del_pict_id"];
  125.  
  126.       $r = mysql_query($q) or die(mysql_error()."<br />".$q);
  127.  
  128.       $d = mysql_fetch_row($r);
  129.  
  130.       $file = "pict/".$d[0];
  131.  
  132.       $q = "DELETE FROM Picture WHERE picture_id=".$_GET["del_pict_id"]." LIMIT 1";
  133.  
  134.       mysql_query($q) or die(mysql_error()."<br />".$q);
  135.  
  136.       if(file_exists($file))
  137.  
  138.          unlink($file);
  139.  
  140.    }
  141.  
  142.    function display_upload_form($nb_file = 1)
  143.  
  144.    {
  145.  
  146.       if(!$this->nb_limit <= mysql_num_rows($this->stored_pictures))
  147.  
  148.       {
  149.  
  150.          print "<form method=\"post\" enctype=\"multipart/form-data\" action=\"".$_SERVER["PHP_SELF"]."?up=1\">\n";
  151.  
  152.          for($i = 0;$i < $nb_file;$i++)
  153.  
  154.             print "<p>\nPicucture N°".($i + 1)." : <input type=\"file\" name=\"file".$i."\" size=\"30\"></p>";
  155.  
  156.          print "<input type=\"submit\" value=\"upload\" />\n";
  157.  
  158.       }
  159.  
  160.       else
  161.  
  162.          print "<p>no more upload allowed !</p>";
  163.  
  164.    }
  165.  
  166. }
  167.  
  168.  


then userpictures.php.

You can create an object album with 2 parameters
- user identiiant (id)
- max picture number (I 've got no idea about how you get it so just pass it here and it'll be managed).
$album = new album($user_id, $max_upload);

so the file will look like this:
PHP Code: [ Select ]
//...
 
//include the class and connects to the DB
 
$album = new album($user_id, $max_upload);
 
//check if he user clicked for removing and call the delete function
 
if($_GET["del_pict_id"])
 
   $album->delete_picture();
 
//check if user is uploading right now and   call the function that treat uploaded files
 
if($_GET["up"])
 
   $album->store_picture();
 
//query and display the user files call ths function.
 
$album->display_album();
 
//this function will display the form for uploading the files
 
$album->display_upload_form($nb_file = 1);
 
 
  1. //...
  2.  
  3. //include the class and connects to the DB
  4.  
  5. $album = new album($user_id, $max_upload);
  6.  
  7. //check if he user clicked for removing and call the delete function
  8.  
  9. if($_GET["del_pict_id"])
  10.  
  11.    $album->delete_picture();
  12.  
  13. //check if user is uploading right now and   call the function that treat uploaded files
  14.  
  15. if($_GET["up"])
  16.  
  17.    $album->store_picture();
  18.  
  19. //query and display the user files call ths function.
  20.  
  21. $album->display_album();
  22.  
  23. //this function will display the form for uploading the files
  24.  
  25. $album->display_upload_form($nb_file = 1);
  26.  
  27.  

check in each function and add what you need.

feel free to ask question.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

so where does
PHP Code: [ Select ]
<?php //...
 
//include the class and connects to the DB
 
$album = new album($user_id, $max_upload);
 
//check if he user clicked for removing and call the delete function
 
if($_GET["del_pict_id"])
 
    $album->delete_picture();
 
//check if user is uploading right now and   call the function that treat uploaded files
 
if($_GET["up"])
 
    $album->store_picture();
 
//query and display the user files call ths function.
 
$album->display_album();
 
//this function will display the form for uploading the files
 
$album->display_upload_form($nb_file = 1); ?>
  1. <?php //...
  2.  
  3. //include the class and connects to the DB
  4.  
  5. $album = new album($user_id, $max_upload);
  6.  
  7. //check if he user clicked for removing and call the delete function
  8.  
  9. if($_GET["del_pict_id"])
  10.  
  11.     $album->delete_picture();
  12.  
  13. //check if user is uploading right now and   call the function that treat uploaded files
  14.  
  15. if($_GET["up"])
  16.  
  17.     $album->store_picture();
  18.  
  19. //query and display the user files call ths function.
  20.  
  21. $album->display_album();
  22.  
  23. //this function will display the form for uploading the files
  24.  
  25. $album->display_upload_form($nb_file = 1); ?>
go?

and if it goes in where the other code goes it give me a error saying
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
SELECT picture_id, name, size FROM picture WHERE user_id=
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

HI,

Ok this goes into your userpictures.php, and this file must include the files that holds the "album" class definition.

And this query has failed because when you call the constructor:

PHP Code: [ Select ]
//...
 
$album = new album($user_id, $max_upload);  
 
 
  1. //...
  2.  
  3. $album = new album($user_id, $max_upload);  
  4.  
  5.  


$user_id is probably empty.

In fact I know that you hold a variable is the URL user, somewhere you give it $req_user_postusername['username'].

If you haven't any id system for user, and are sure that this value is unique for each user that is connecting on the site, give this value instead of $user_id.

But you have to know that this value must match in the pictures table (there is a field for unique values that identify users).
So think about the type of this field.

Where you insert rows picture tables, for this field you have to get the value that'll identify the user, so that you can query on is own pictures each time he comes to userpictures.php.

Well it's very hard for me to be clear in English words but you just have to know that in the call above, $user_id must hold the value that identifies the user so that we are able to query on his own pictures in pictures tables.
And $max_upload the max number of pictures allowed for a user on the server.

Feel free to ask more questions
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

umm you kinda lost me there but its ok.

so say that user just joined and dont have there name in the picture database. how would that person upload there picture to the database? and i want it where it goes under there username and bty most of where it gets the username is
Code: [ Select ]
username = '$username'
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Yeah, that's what I want to say.

Of course change the field "picture_id", in the pictures table so that it can store those $username (is it numéric(keep int)? or string (change to varchar)? .

if you passed this value $username in the constructor :
PHP Code: [ Select ]
//.
 
$album = new album($username , $max_upload); ?>
 
 
  1. //.
  2.  
  3. $album = new album($username , $max_upload); ?>
  4.  
  5.  

It will be hold and used in the class for insert and select statments.

But just check the insert query in store_picture() function, if the field name for the user is correct (if you've have changed it), actually it is called user user_id.

And also the SELECT query in display_album()

That's how we link uploaded pictures with the user, $username value will be sored in the field "user_id" (or whatelse if you change the field name).
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

Unknown column 'admin' in 'where clause'
SELECT picture_id, name, size FROM picture WHERE user_id=admin

that is what it gives me

and also i made it were when you sign up it collects your first and last name

how would i go about making it where a user can search for sombody by there first and last name the database field forthat is firstname, lastname, and username
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

OK,

the error is because you changed the field as a string field so the query have to be changed (you have to add simple quote) :
$q = "SELECT picture_id, name, size FROM picture WHERE user_id=".$this->user_id;

and add simple quotes :

$q = "SELECT picture_id, name, size FROM picture WHERE user_id LIKE '".$this->user_id."'";

think about adding simple quotes in the insert query in store_picture() function.

For other kind of research
you will have to do a join query.

In the simplest way, Maybe you'll have to add functions in the class like that :
get pictures_by_first_name($first_name)
in with you select like on pictures, and users table, I don't know/remember what does users table is named and look like but the query will be something like that (put the right table and fields names) :
PHP Code: [ Select ]
//..
 
$q = "SELECT picture_id, name, size FROM picture JOIN user_table USING(username) WHERE firstname LIKE '".$first_name."'";
 
$result = mysql_query($q) or print mysql_error()."<br /";
 
 
  1. //..
  2.  
  3. $q = "SELECT picture_id, name, size FROM picture JOIN user_table USING(username) WHERE firstname LIKE '".$first_name."'";
  4.  
  5. $result = mysql_query($q) or print mysql_error()."<br /";
  6.  
  7.  

and you return $result so that you can browse the results display like I showed you in the beginning on this thread.

and
get pictures_by_first_name($first_name)

am I clear? :-)
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

erm it comes up

No picture !

no more upload allowed !




and bty no i was not meaning that.. in the user table in the database i have stored all the users info like there username, profile info, firstname, ect. and i want it where a person can search for a firstname of somebody and have it go to header(location "userinfo.php?user=$username");
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

well,

no picture, I guess it's pretty coherent,
Not more upload allowed, I show it in display_upload_form() function, if there is more or equal uploaded pictures files than allowed.
In your case, I think it shows that because when you call the constructor :

PHP Code: [ Select ]
 
//include the class and connects to the DB
 
$album = new album($user_id, $max_upload);
 
 
  1.  
  2. //include the class and connects to the DB
  3.  
  4. $album = new album($user_id, $max_upload);
  5.  
  6.  


$max_upload variable is probably empty.

So if you hadn't put any values for that just before you should give it.
In fact I don't know how you manage that, what does it depend on, so just while you try this script, give a value just before for example

PHP Code: [ Select ]
 
$max_upload = 5;
 
//include the class and connects to the DB
 
$album = new album($user_id, $max_upload);
 
 
  1.  
  2. $max_upload = 5;
  3.  
  4. //include the class and connects to the DB
  5.  
  6. $album = new album($user_id, $max_upload);
  7.  
  8.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

do you understand on what i was trying to do for my user thing?

and bty no i was not meaning that.. in the user table in the database i have stored all the users info like there username, profile info, firstname, ect. and i want it where a person can search for a firstname of somebody and have it go to header(location "userinfo.php?user=$username");


and ermmm


failed av1.jpg 6890 bytes : picture too heavy ! why is it doing that?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Quote:
do you understand on what i was trying to do for my user thing?

do you want a serach enfine for the user (search by firstname, etc...)

Quote:
failed av1.jpg 6890 bytes : picture too heavy ! why is it doing that?

I show it in store_picture() in the picture is too big.
very strange, did you change album::size_limit ?
PHP Code: [ Select ]
//..
 
var $size_limit = 100000;
 
 
  1. //..
  2.  
  3. var $size_limit = 100000;
  4.  
  5.  

that allows till 100000 bytes (100kb)

By the way I realized that I print the values in store_picture() :
print "<p>".$file['name']."<br />";
print "temp :".$file['tmp_name']."<br />";
print "type :".$file['type'] ."<br />";
print "size :".$file['size'] ."<br />";
print "error :".$file['error'] ."</p>";
I should have put comment on them .

anyway keep it like that while debuugging and check what is displayed.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

yes i want it where a user can type in a name of a person and it will pull up there username


and no i did not change the file size

PHP Code: [ Select ]
<?php //...  
 
//include the class and connects to the DB  
 
$max_upload = 5;
 
$album = new album($username , $max_upload);  
 
//check if he user clicked for removing and call the delete function  
 
if($_GET["del_pict_id"])  
 
    $album->delete_picture();  
 
//check if user is uploading right now and   call the function that treat uploaded files  
 
if($_GET["up"])  
 
    $album->store_picture();  
 
//query and display the user files call ths function.  
 
$album->display_album();  
 
//this function will display the form for uploading the files  
 
$album->display_upload_form($nb_file = 1); ?>      <?php class album
 
{
 
    var $user_id;
 
    var $size_limit = 100000;
 
    var $nb_limit;
 
    var $stored_pictures;
 
    function album($user_id, $nb_limit = 5)
 
    {
 
        $this->user_id = $user_id;
 
        $this->nb_limit = $nb_limit;
 
        $this->size_limit = $size_limit;
 
    }
 
    function display_album()
 
    {
 
        $q = "SELECT picture_id, name, size FROM picture WHERE user_id LIKE '".$this->user_id."'";
 
        $this->stored_pictures = mysql_query($q) or die(mysql_error()."<br />".$q);
 
        if(mysql_num_rows($this->stored_pictures))
 
        {
 
            print "<table border=\"1\">\n<tr><td align=\"center\"><b>Name</b></td><td align=\"center\"><b>Size</b></td><td align=\"center\"><b>Picture</b></td><td align=\"center\"><b>Action</b></td></tr>\n";
 
            while($d = mysql_fetch_row($this->stored_pictures))
 
            {
 
                print "<tr><td>".$d[1]."</td><td align=\"center\">".$d[2]."</td><td align=\"center\"><img src=\"pict/".$d[1]."\" /></td>";
 
                print "<td align=\"center\"><a href=\"".$_SERVER["PHP_SELF"]."?del_pict_id=".$d[0]."\">Delete</a></td></tr>\n";
 
            }
 
            print "</table>\n";
 
        }
 
        else
 
            print "<p>No picture ! </p>\n";
 
    }
 
    function store_picture()
 
    {
 
        //$_FILE is a superglobal so you can get it from there
 
        foreach ($_FILES as $file)
 
        {
 
             print "<p>".$file['name']."<br />";
 
            print "temp :".$file['tmp_name']."<br />";  
 
            print "type :".$file['type'] ."<br />";  
 
            print "size :".$file['size'] ."<br />";
 
            print "error :".$file['error'] ."</p>";
 
            if($file['size'] >= $this->size_limit)
 
            {
 
                print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";
 
                return false;
 
            }
 
            if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))
 
            {
 
                $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', ".$this->user_id.")";
 
                mysql_query($q) or die(mysql_error()."<br />".$q);
 
            }
 
            else
 
            {
 
                print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";
 
                return false;
 
            }
 
            if(file_exists("pict/".$file['name']))
 
                $file['name'] .= $this->user_id;
 
            copy($file['tmp_name'], "pict/".$file['name']);
 
        }                
 
    }
 
    function delete_picture()
 
    {
 
        $q = "SELECT name FROM picture WHERE picture_id=".$_GET["del_pict_id"];
 
        $r = mysql_query($q) or die(mysql_error()."<br />".$q);
 
        $d = mysql_fetch_row($r);
 
        $file = "pict/".$d[0];
 
        $q = "DELETE FROM Picture WHERE picture_id=".$_GET["del_pict_id"]." LIMIT 1";
 
        mysql_query($q) or die(mysql_error()."<br />".$q);
 
        if(file_exists($file))
 
            unlink($file);  
 
    }
 
    function display_upload_form($nb_file = 1)
 
    {
 
        if(!$this->nb_limit <= mysql_num_rows($this->stored_pictures))
 
        {
 
            print "<form method=\"post\" enctype=\"multipart/form-data\" action=\"".$_SERVER["PHP_SELF"]."?up=1\">\n";
 
            for($i = 0;$i < $nb_file;$i++)
 
                 print "<p>\nPicucture N°".($i + 1)." : <input type=\"file\" name=\"file".$i."\" size=\"30\"></p>";
 
             print "<input type=\"submit\" value=\"upload\" />\n";
 
        }
 
        else
 
            print "<p>no more upload allowed !</p>";
 
    }
 
} ?>
  1. <?php //...  
  2.  
  3. //include the class and connects to the DB  
  4.  
  5. $max_upload = 5;
  6.  
  7. $album = new album($username , $max_upload);  
  8.  
  9. //check if he user clicked for removing and call the delete function  
  10.  
  11. if($_GET["del_pict_id"])  
  12.  
  13.     $album->delete_picture();  
  14.  
  15. //check if user is uploading right now and   call the function that treat uploaded files  
  16.  
  17. if($_GET["up"])  
  18.  
  19.     $album->store_picture();  
  20.  
  21. //query and display the user files call ths function.  
  22.  
  23. $album->display_album();  
  24.  
  25. //this function will display the form for uploading the files  
  26.  
  27. $album->display_upload_form($nb_file = 1); ?>      <?php class album
  28.  
  29. {
  30.  
  31.     var $user_id;
  32.  
  33.     var $size_limit = 100000;
  34.  
  35.     var $nb_limit;
  36.  
  37.     var $stored_pictures;
  38.  
  39.     function album($user_id, $nb_limit = 5)
  40.  
  41.     {
  42.  
  43.         $this->user_id = $user_id;
  44.  
  45.         $this->nb_limit = $nb_limit;
  46.  
  47.         $this->size_limit = $size_limit;
  48.  
  49.     }
  50.  
  51.     function display_album()
  52.  
  53.     {
  54.  
  55.         $q = "SELECT picture_id, name, size FROM picture WHERE user_id LIKE '".$this->user_id."'";
  56.  
  57.         $this->stored_pictures = mysql_query($q) or die(mysql_error()."<br />".$q);
  58.  
  59.         if(mysql_num_rows($this->stored_pictures))
  60.  
  61.         {
  62.  
  63.             print "<table border=\"1\">\n<tr><td align=\"center\"><b>Name</b></td><td align=\"center\"><b>Size</b></td><td align=\"center\"><b>Picture</b></td><td align=\"center\"><b>Action</b></td></tr>\n";
  64.  
  65.             while($d = mysql_fetch_row($this->stored_pictures))
  66.  
  67.             {
  68.  
  69.                 print "<tr><td>".$d[1]."</td><td align=\"center\">".$d[2]."</td><td align=\"center\"><img src=\"pict/".$d[1]."\" /></td>";
  70.  
  71.                 print "<td align=\"center\"><a href=\"".$_SERVER["PHP_SELF"]."?del_pict_id=".$d[0]."\">Delete</a></td></tr>\n";
  72.  
  73.             }
  74.  
  75.             print "</table>\n";
  76.  
  77.         }
  78.  
  79.         else
  80.  
  81.             print "<p>No picture ! </p>\n";
  82.  
  83.     }
  84.  
  85.     function store_picture()
  86.  
  87.     {
  88.  
  89.         //$_FILE is a superglobal so you can get it from there
  90.  
  91.         foreach ($_FILES as $file)
  92.  
  93.         {
  94.  
  95.              print "<p>".$file['name']."<br />";
  96.  
  97.             print "temp :".$file['tmp_name']."<br />";  
  98.  
  99.             print "type :".$file['type'] ."<br />";  
  100.  
  101.             print "size :".$file['size'] ."<br />";
  102.  
  103.             print "error :".$file['error'] ."</p>";
  104.  
  105.             if($file['size'] >= $this->size_limit)
  106.  
  107.             {
  108.  
  109.                 print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";
  110.  
  111.                 return false;
  112.  
  113.             }
  114.  
  115.             if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))
  116.  
  117.             {
  118.  
  119.                 $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', ".$this->user_id.")";
  120.  
  121.                 mysql_query($q) or die(mysql_error()."<br />".$q);
  122.  
  123.             }
  124.  
  125.             else
  126.  
  127.             {
  128.  
  129.                 print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";
  130.  
  131.                 return false;
  132.  
  133.             }
  134.  
  135.             if(file_exists("pict/".$file['name']))
  136.  
  137.                 $file['name'] .= $this->user_id;
  138.  
  139.             copy($file['tmp_name'], "pict/".$file['name']);
  140.  
  141.         }                
  142.  
  143.     }
  144.  
  145.     function delete_picture()
  146.  
  147.     {
  148.  
  149.         $q = "SELECT name FROM picture WHERE picture_id=".$_GET["del_pict_id"];
  150.  
  151.         $r = mysql_query($q) or die(mysql_error()."<br />".$q);
  152.  
  153.         $d = mysql_fetch_row($r);
  154.  
  155.         $file = "pict/".$d[0];
  156.  
  157.         $q = "DELETE FROM Picture WHERE picture_id=".$_GET["del_pict_id"]." LIMIT 1";
  158.  
  159.         mysql_query($q) or die(mysql_error()."<br />".$q);
  160.  
  161.         if(file_exists($file))
  162.  
  163.             unlink($file);  
  164.  
  165.     }
  166.  
  167.     function display_upload_form($nb_file = 1)
  168.  
  169.     {
  170.  
  171.         if(!$this->nb_limit <= mysql_num_rows($this->stored_pictures))
  172.  
  173.         {
  174.  
  175.             print "<form method=\"post\" enctype=\"multipart/form-data\" action=\"".$_SERVER["PHP_SELF"]."?up=1\">\n";
  176.  
  177.             for($i = 0;$i < $nb_file;$i++)
  178.  
  179.                  print "<p>\nPicucture N°".($i + 1)." : <input type=\"file\" name=\"file".$i."\" size=\"30\"></p>";
  180.  
  181.              print "<input type=\"submit\" value=\"upload\" />\n";
  182.  
  183.         }
  184.  
  185.         else
  186.  
  187.             print "<p>no more upload allowed !</p>";
  188.  
  189.     }
  190.  
  191. } ?>
[/code]
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Ok I will work on a user search engine, when I've got a little time, right now I'm working at office :-).
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

basically i have the users firstname in the database and i want it like this

search by firstname of user
||||||||||||||||||| submit


<? header("Location: userinfo.php?user=username");
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

Hey man when do you think you can help me get the pics done?
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Hi man,

are you talking about the size problem?

Could you echo $this->limit at the same time when I show this report, and tell me.

Just like that (in store_picture() function) :

PHP Code: [ Select ]
//...
 
function store_picture()  
 
    {  
 
        //$_FILE is a superglobal so you can get it from there  
 
        foreach ($_FILES as $file)  
 
        {  
 
             print "<p>".$file['name']."<br />";  
 
            print "temp :".$file['tmp_name']."<br />";  
 
            print "type :".$file['type'] ."<br />";  
 
            print "size :".$file['size'] ."<br />";  
 
            print "error :".$file['error'] ."</p>";  
 
            if($file['size'] >= $this->size_limit)  
 
            {
 
               /* HERE I'M ALSO ECHOING THE MAX SIZE SET! $this->size_limit */
 
                  print "<p>max size set : ".$this->size_limit."</p>";
 
                print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";  
 
                return false;  
 
            }  
 
            if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))  
 
            {  
 
                $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', ".$this->user_id.")";  
 
                mysql_query($q) or die(mysql_error()."<br />".$q);  
 
            }  
 
            else  
 
            {  
 
                print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";  
 
                return false;  
 
            }  
 
            if(file_exists("pict/".$file['name']))  
 
                $file['name'] .= $this->user_id;  
 
            copy($file['tmp_name'], "pict/".$file['name']);  
 
        }                  
 
    }  
 
 
  1. //...
  2.  
  3. function store_picture()  
  4.  
  5.     {  
  6.  
  7.         //$_FILE is a superglobal so you can get it from there  
  8.  
  9.         foreach ($_FILES as $file)  
  10.  
  11.         {  
  12.  
  13.              print "<p>".$file['name']."<br />";  
  14.  
  15.             print "temp :".$file['tmp_name']."<br />";  
  16.  
  17.             print "type :".$file['type'] ."<br />";  
  18.  
  19.             print "size :".$file['size'] ."<br />";  
  20.  
  21.             print "error :".$file['error'] ."</p>";  
  22.  
  23.             if($file['size'] >= $this->size_limit)  
  24.  
  25.             {
  26.  
  27.                /* HERE I'M ALSO ECHOING THE MAX SIZE SET! $this->size_limit */
  28.  
  29.                   print "<p>max size set : ".$this->size_limit."</p>";
  30.  
  31.                 print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";  
  32.  
  33.                 return false;  
  34.  
  35.             }  
  36.  
  37.             if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))  
  38.  
  39.             {  
  40.  
  41.                 $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', ".$this->user_id.")";  
  42.  
  43.                 mysql_query($q) or die(mysql_error()."<br />".$q);  
  44.  
  45.             }  
  46.  
  47.             else  
  48.  
  49.             {  
  50.  
  51.                 print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";  
  52.  
  53.                 return false;  
  54.  
  55.             }  
  56.  
  57.             if(file_exists("pict/".$file['name']))  
  58.  
  59.                 $file['name'] .= $this->user_id;  
  60.  
  61.             copy($file['tmp_name'], "pict/".$file['name']);  
  62.  
  63.         }                  
  64.  
  65.     }  
  66.  
  67.  


Also, right now it's 17:38, I think until 2 hours (about 19/20h here at home), after the job, I will work on the user search engine.I think it won't be very long.
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

By the way, could you show all the precise fields names of the user table.

I will use this for my query.

Also do you want the user to switch on what research (firstname or lastname or etc.) or do you want the user to type something and that automatically searches on all?
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

av1.jpg
temp :/tmp/phpJ6MjpD
type :image/pjpeg
size :6890
error :0

max size set :

failed av1.jpg 6890 bytes : picture too heavy !

No picture !


that is what it does

and

the field names of the users tabel is

username
age
city
state
sex
sexuality
firstname
lastname
taken -> is like if they are single or what ever
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Ok man, I think I got the size problem :

I had f.... the size_limit set in the constructor (function album())


see I replaced
$this->size_limit = $size_limit;
by
$this->size_limit = 100000;

in fact 100000 for 100 kb max (bigger pictures won't be allowed), but if you want to allow less or more feel free to change the value right here.

So here's the correct constructor :

PHP Code: [ Select ]
 
function album($user_id, $nb_limit = 5)  
 
{  
 
        $this->user_id = $user_id;  
 
        $this->nb_limit = $nb_limit;  
 
        $this->size_limit = 100000;  
 
}
 
 
  1.  
  2. function album($user_id, $nb_limit = 5)  
  3.  
  4. {  
  5.  
  6.         $this->user_id = $user_id;  
  7.  
  8.         $this->nb_limit = $nb_limit;  
  9.  
  10.         $this->size_limit = 100000;  
  11.  
  12. }
  13.  
  14.  


Just change this function by the above and try and tell me.

right now 22:11 here , Ijust beginthe seach engine, I hope I finish before the bed:-)

I think I will just add a function called search_user($string) in one of the existing class.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

av1.jpg
temp :/tmp/phpt2Z04s
type :image/pjpeg
size :6890
error :0

Unknown column 'admin' in 'field list'
INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', 'av1.jpg', '6890', admin)

that is what i get
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Oh sorry it's my fault,

when I add the size echoing, I give you the old script, but we add corrected before the insert statment adding simple quote.

Replace this in store_picture() :

PHP Code: [ Select ]
 
$q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', '".$this->user_id."')";  
 
 
  1.  
  2. $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', '".$this->user_id."')";  
  3.  
  4.  

see I added again the simple quotes ;-)

Also what do you think about that :

the user fill a textbox for his search, in can be a town, a last name or what else, and I do an automatic search on all information about users.
That's it?

or witch fields exactly?

But if it is returning more than one rows what do you want?

shall i show al the resulats with links to userinfo?php so that the user pick the profile he was searching for , or should I directly redirect on userinfo.php for with the first row returned?

among thoses questions everything is possible and everything is easy.

maybe I'll give a little SQL script if I want to use a FULLTEXT index (don't worry you won't have to manage this kind of stuff).

I want to ask one more question,can you tell me if your table is typed MyIsam (or maybe it's innodb or whatelse)?

So I 'm afraid it's getting a little late for ending this night here but I I think here 's no much work on it on tomorow morning.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

Code: [ Select ]
av1.jpg
temp :/tmp/phpXD7jws
type :image/pjpeg
size :6890
error :0


Warning: copy(pict/av1.jpg) [function.copy]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 131

No picture !
  1. av1.jpg
  2. temp :/tmp/phpXD7jws
  3. type :image/pjpeg
  4. size :6890
  5. error :0
  6. Warning: copy(pict/av1.jpg) [function.copy]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 131
  7. No picture !


that is what i get on that and

can it be on the fields that i gave you and as far as in the person profile i want the profile to be userinfo.php?

the mysql engin is MyISAM


here is the phpinfo from my host if that helps any http://phpinfo.hostultra.com/
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

Hey gisele
I just wanted to tell you Thank you for all your help you have gaven me.
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Hi,

You're wellcome man !

Ok, I think your warning is a directory problem.

have you created the right directory? a folder named "pict" in the same directory as the script?
Or do whatever you want to store the pictures but think about, fit the right path for copy() in store_picture() function.
I mean either you create the right folder so that it works like that :
PHP Code: [ Select ]
//..
 
copy($file['tmp_name'], "pict/".$file['name']);
 
 
  1. //..
  2.  
  3. copy($file['tmp_name'], "pict/".$file['name']);
  4.  
  5.  

either you manage your own path and change it in something like that :
PHP Code: [ Select ]
//..
 
copy($file['tmp_name'], $your_path.$file['name']);
 
 
  1. //..
  2.  
  3. copy($file['tmp_name'], $your_path.$file['name']);
  4.  
  5.  


first I choose to add a fulltext index.


So anyway don't worry just do thisSQL statment in your db manager.

Code: [ Select ]
ALTER TABLE `users` ADD FULLTEXT `user_search` (
`username` ,
`city` ,
`state` ,
`sex` ,
`sexuality` ,
`firstname` ,
`lastname`
)
  1. ALTER TABLE `users` ADD FULLTEXT `user_search` (
  2. `username` ,
  3. `city` ,
  4. `state` ,
  5. `sex` ,
  6. `sexuality` ,
  7. `firstname` ,
  8. `lastname`
  9. )

in fact I assumed that age was a numeric field and I didn't keep it for the search.

Don't forget these points about fulltext research:

-this index will allow researches on all this field, and return rows depending on a relevance sorting.
-The more you'll have an occurence on a field, the less relevance will be given to it, because it works for an efficient and significative search and there's no need to return a big set of same responses (that's the fulltext philosophy).
-therefore, you have to know that all occurences whose count is over than half of all the rows in the tables will be ignored for the same reason, as useless for the research.
-little words 'the' 'a' 'an' and less than 4 characters lenght will be ignored
-FULLTEXT are only supported on Myisam tables

if you're curious about it, I think this link tell you in a better english than mine How does it work :-) :


http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

Then the function, you can put it in database class, for example next to getUserComments().
you just have to call it, putting is $string as parameter the result of a form for example with a textbox, that will be the string for the research.
It shows the username founded thanks the string, with links to userinfo.php
PHP Code: [ Select ]
 
function search_user($string)
 
{
 
   $q = "SELECT username FROM users WHERE MATCH (username , city, state, sex, sexuality, firstname, lastname) AGAINST ('".$string."');
 
   $r =  mysql_query($q) or die (mysql_error()."<br />".$q);
 
   if(mysql_num_rows($r))
 
   {
 
      print "<p><b>Results : </b></p>\n<p>";
 
      while($data = mysql_fetch_row($r))
 
         print "<a href=\"userinfo.php?username=".$data[0]."\">".$data[0]."</a>\n";//link for each username founded
 
      print "</p>\n";
 
   }
 
   else
 
      print "<p><b>no result found</b></p>\n";
 
}
 
 
  1.  
  2. function search_user($string)
  3.  
  4. {
  5.  
  6.    $q = "SELECT username FROM users WHERE MATCH (username , city, state, sex, sexuality, firstname, lastname) AGAINST ('".$string."');
  7.  
  8.    $r =  mysql_query($q) or die (mysql_error()."<br />".$q);
  9.  
  10.    if(mysql_num_rows($r))
  11.  
  12.    {
  13.  
  14.       print "<p><b>Results : </b></p>\n<p>";
  15.  
  16.       while($data = mysql_fetch_row($r))
  17.  
  18.          print "<a href=\"userinfo.php?username=".$data[0]."\">".$data[0]."</a>\n";//link for each username founded
  19.  
  20.       print "</p>\n";
  21.  
  22.    }
  23.  
  24.    else
  25.  
  26.       print "<p><b>no result found</b></p>\n";
  27.  
  28. }
  29.  
  30.  

well in fact I didn't really understand if you were willing to display the results with all info directly in userinfo.php, or just show the username founded , with built links so that we can pick the right user, and see his own information after in userinfo.php.

I didn't make up the research form, just the function that take the result of i ($string) and do the research.So once you have a result, anywhere in your site you just have to call search_user($string).
$string is the string typed for the research.

Tell what you exactly want, maybe you want put the whole stuff in userinfo.php (research form + user_search() call)?

feel free to ask question.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

hey i dont understand on what you mean for the picture thing
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

well,

you will have to stored the picture in a directory on the server won't you?

in the table, I just store informations on the pictures (name, etc.) but since a picture is a binary file, it has to be put somewhere on the server once it is uploaded.
(first they come to the server as a temporary file, and then copy() will put them in a directory so that you can use them later (show them, whatelse).
You will store all of them in the same directory on the web server that you have created.

Think about where you put the php scripts of all this stuff, at the same place just create a folder named "pict" for instance so that this (in store_picture() ) could work :
PHP Code: [ Select ]
//...
 
copy($file['tmp_name'], "pict/".$file['name']);
 
 
  1. //...
  2.  
  3. copy($file['tmp_name'], "pict/".$file['name']);
  4.  
  5.  


the first parameter $file['tmp_name'] is just the file like it is uploaded as a temporary file (for example :/tmp/phpXD7jws ).

and the second one

"pict/".$file['name'] is where you want to copy the picture on the server.(assuming you have created a folder named "pict" in the same directory of your PHP scripts.

Did you get it?
otherwise feel free to ask for the points that you can't understand ;-)
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

Code: [ Select ]
av1.jpg
temp :/tmp/phpOyGhtP
type :image/pjpeg
size :6890
error :0


Warning: copy(pict/av1.jpg) [function.copy]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 144

No picture !
  1. av1.jpg
  2. temp :/tmp/phpOyGhtP
  3. type :image/pjpeg
  4. size :6890
  5. error :0
  6. Warning: copy(pict/av1.jpg) [function.copy]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 144
  7. No picture !


that is what i get and here is the code if that helps any

PHP Code: [ Select ]
  <?php //...  
 
//include the class and connects to the DB  
 
$max_upload = 5;
 
$album = new album($username , $max_upload);  
 
//check if he user clicked for removing and call the delete function  
 
if($_GET["del_pict_id"])  
 
    $album->delete_picture();  
 
//check if user is uploading right now and   call the function that treat uploaded files  
 
if($_GET["up"])  
 
    $album->store_picture();  
 
//query and display the user files call ths function.  
 
$album->display_album();  
 
//this function will display the form for uploading the files  
 
$album->display_upload_form($nb_file = 1); ?>   <?php class album
 
{
 
    var $user_id;
 
    var $size_limit = 10000000;
 
    var $nb_limit;
 
    var $stored_pictures;
 
function album($user_id, $nb_limit = 5)  
 
{  
 
        $this->user_id = $user_id;  
 
        $this->nb_limit = $nb_limit;  
 
        $this->size_limit = 100000;  
 
}
 
    function display_album()
 
    {
 
        $q = "SELECT picture_id, name, size FROM picture WHERE user_id LIKE '".$this->user_id."'";
 
        $this->stored_pictures = mysql_query($q) or die(mysql_error()."<br />".$q);
 
        if(mysql_num_rows($this->stored_pictures))
 
        {
 
            print "<table border=\"1\">\n<tr><td align=\"center\"><b>Name</b></td><td align=\"center\"><b>Size</b></td><td align=\"center\"><b>Picture</b></td><td align=\"center\"><b>Action</b></td></tr>\n";
 
            while($d = mysql_fetch_row($this->stored_pictures))
 
            {
 
                print "<tr><td>".$d[1]."</td><td align=\"center\">".$d[2]."</td><td align=\"center\"><img src=\"pict/".$d[1]."\" /></td>";
 
                print "<td align=\"center\"><a href=\"".$_SERVER["PHP_SELF"]."?del_pict_id=".$d[0]."\">Delete</a></td></tr>\n";
 
            }
 
            print "</table>\n";
 
        }
 
        else
 
            print "<p>No picture ! </p>\n";
 
    }
 
   function store_picture()  
 
    {  
 
        //$_FILE is a superglobal so you can get it from there  
 
        foreach ($_FILES as $file)  
 
        {  
 
             print "<p>".$file['name']."<br />";  
 
            print "temp :".$file['tmp_name']."<br />";    
 
            print "type :".$file['type'] ."<br />";    
 
            print "size :".$file['size'] ."<br />";  
 
            print "error :".$file['error'] ."</p>";  
 
            if($file['size'] >= $this->size_limit)  
 
            {  
 
                /* HERE I'M ALSO ECHOING THE MAX SIZE SET! $this->size_limit */
 
                    print "<p>max size set : ".$this->size_limit."</p>";  
 
                print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";  
 
                return false;  
 
            }  
 
            if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))  
 
            {  
 
                $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', '".$this->user_id."')";
 
                mysql_query($q) or die(mysql_error()."<br />".$q);  
 
                        }  
 
            else  
 
            {  
 
                print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";  
 
                return false;  
 
            }  
 
            if(file_exists("pict/".$file['name']))  
 
                $file['name'] .= $this->user_id;  
 
            copy($file['tmp_name'], "pict/".$file['name']);  
 
        }                  
 
    }
 
    function delete_picture()
 
    {
 
        $q = "SELECT name FROM picture WHERE picture_id=".$_GET["del_pict_id"];
 
        $r = mysql_query($q) or die(mysql_error()."<br />".$q);
 
        $d = mysql_fetch_row($r);
 
        $file = "pict/".$d[0];
 
        $q = "DELETE FROM Picture WHERE picture_id=".$_GET["del_pict_id"]." LIMIT 1";
 
        mysql_query($q) or die(mysql_error()."<br />".$q);
 
        if(file_exists($file))
 
            unlink($file);  
 
    }
 
    function display_upload_form($nb_file = 1)
 
    {
 
        if(!$this->nb_limit <= mysql_num_rows($this->stored_pictures))
 
        {
 
            print "<form method=\"post\" enctype=\"multipart/form-data\" action=\"".$_SERVER["PHP_SELF"]."?up=1\">\n";
 
            for($i = 0;$i < $nb_file;$i++)
 
                 print "<p>\nPicucture N°".($i + 1)." : <input type=\"file\" name=\"file".$i."\" size=\"30\"></p>";
 
             print "<input type=\"submit\" value=\"upload\" />\n";
 
        }
 
        else
 
            print "<p>no more upload allowed !</p>";
 
    }
 
} ?>
  1.   <?php //...  
  2.  
  3. //include the class and connects to the DB  
  4.  
  5. $max_upload = 5;
  6.  
  7. $album = new album($username , $max_upload);  
  8.  
  9. //check if he user clicked for removing and call the delete function  
  10.  
  11. if($_GET["del_pict_id"])  
  12.  
  13.     $album->delete_picture();  
  14.  
  15. //check if user is uploading right now and   call the function that treat uploaded files  
  16.  
  17. if($_GET["up"])  
  18.  
  19.     $album->store_picture();  
  20.  
  21. //query and display the user files call ths function.  
  22.  
  23. $album->display_album();  
  24.  
  25. //this function will display the form for uploading the files  
  26.  
  27. $album->display_upload_form($nb_file = 1); ?>   <?php class album
  28.  
  29. {
  30.  
  31.     var $user_id;
  32.  
  33.     var $size_limit = 10000000;
  34.  
  35.     var $nb_limit;
  36.  
  37.     var $stored_pictures;
  38.  
  39. function album($user_id, $nb_limit = 5)  
  40.  
  41. {  
  42.  
  43.         $this->user_id = $user_id;  
  44.  
  45.         $this->nb_limit = $nb_limit;  
  46.  
  47.         $this->size_limit = 100000;  
  48.  
  49. }
  50.  
  51.     function display_album()
  52.  
  53.     {
  54.  
  55.         $q = "SELECT picture_id, name, size FROM picture WHERE user_id LIKE '".$this->user_id."'";
  56.  
  57.         $this->stored_pictures = mysql_query($q) or die(mysql_error()."<br />".$q);
  58.  
  59.         if(mysql_num_rows($this->stored_pictures))
  60.  
  61.         {
  62.  
  63.             print "<table border=\"1\">\n<tr><td align=\"center\"><b>Name</b></td><td align=\"center\"><b>Size</b></td><td align=\"center\"><b>Picture</b></td><td align=\"center\"><b>Action</b></td></tr>\n";
  64.  
  65.             while($d = mysql_fetch_row($this->stored_pictures))
  66.  
  67.             {
  68.  
  69.                 print "<tr><td>".$d[1]."</td><td align=\"center\">".$d[2]."</td><td align=\"center\"><img src=\"pict/".$d[1]."\" /></td>";
  70.  
  71.                 print "<td align=\"center\"><a href=\"".$_SERVER["PHP_SELF"]."?del_pict_id=".$d[0]."\">Delete</a></td></tr>\n";
  72.  
  73.             }
  74.  
  75.             print "</table>\n";
  76.  
  77.         }
  78.  
  79.         else
  80.  
  81.             print "<p>No picture ! </p>\n";
  82.  
  83.     }
  84.  
  85.    function store_picture()  
  86.  
  87.     {  
  88.  
  89.         //$_FILE is a superglobal so you can get it from there  
  90.  
  91.         foreach ($_FILES as $file)  
  92.  
  93.         {  
  94.  
  95.              print "<p>".$file['name']."<br />";  
  96.  
  97.             print "temp :".$file['tmp_name']."<br />";    
  98.  
  99.             print "type :".$file['type'] ."<br />";    
  100.  
  101.             print "size :".$file['size'] ."<br />";  
  102.  
  103.             print "error :".$file['error'] ."</p>";  
  104.  
  105.             if($file['size'] >= $this->size_limit)  
  106.  
  107.             {  
  108.  
  109.                 /* HERE I'M ALSO ECHOING THE MAX SIZE SET! $this->size_limit */
  110.  
  111.                     print "<p>max size set : ".$this->size_limit."</p>";  
  112.  
  113.                 print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";  
  114.  
  115.                 return false;  
  116.  
  117.             }  
  118.  
  119.             if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))  
  120.  
  121.             {  
  122.  
  123.                 $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', '".$this->user_id."')";
  124.  
  125.                 mysql_query($q) or die(mysql_error()."<br />".$q);  
  126.  
  127.                         }  
  128.  
  129.             else  
  130.  
  131.             {  
  132.  
  133.                 print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";  
  134.  
  135.                 return false;  
  136.  
  137.             }  
  138.  
  139.             if(file_exists("pict/".$file['name']))  
  140.  
  141.                 $file['name'] .= $this->user_id;  
  142.  
  143.             copy($file['tmp_name'], "pict/".$file['name']);  
  144.  
  145.         }                  
  146.  
  147.     }
  148.  
  149.     function delete_picture()
  150.  
  151.     {
  152.  
  153.         $q = "SELECT name FROM picture WHERE picture_id=".$_GET["del_pict_id"];
  154.  
  155.         $r = mysql_query($q) or die(mysql_error()."<br />".$q);
  156.  
  157.         $d = mysql_fetch_row($r);
  158.  
  159.         $file = "pict/".$d[0];
  160.  
  161.         $q = "DELETE FROM Picture WHERE picture_id=".$_GET["del_pict_id"]." LIMIT 1";
  162.  
  163.         mysql_query($q) or die(mysql_error()."<br />".$q);
  164.  
  165.         if(file_exists($file))
  166.  
  167.             unlink($file);  
  168.  
  169.     }
  170.  
  171.     function display_upload_form($nb_file = 1)
  172.  
  173.     {
  174.  
  175.         if(!$this->nb_limit <= mysql_num_rows($this->stored_pictures))
  176.  
  177.         {
  178.  
  179.             print "<form method=\"post\" enctype=\"multipart/form-data\" action=\"".$_SERVER["PHP_SELF"]."?up=1\">\n";
  180.  
  181.             for($i = 0;$i < $nb_file;$i++)
  182.  
  183.                  print "<p>\nPicucture N°".($i + 1)." : <input type=\"file\" name=\"file".$i."\" size=\"30\"></p>";
  184.  
  185.              print "<input type=\"submit\" value=\"upload\" />\n";
  186.  
  187.         }
  188.  
  189.         else
  190.  
  191.             print "<p>no more upload allowed !</p>";
  192.  
  193.     }
  194.  
  195. } ?>


Is it still posting it to a user id or username and you can post to a username by $username
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

HI,

OK , I added a little somthing that'll create by itself the folder if it doesn't exist:

PHP Code: [ Select ]
 
if(!is_dir("pict"))
 
               mkdir ("pict", 0700);  
 
 
  1.  
  2. if(!is_dir("pict"))
  3.  
  4.                mkdir ("pict", 0700);  
  5.  
  6.  




So all is left to do is replace the store_picture() function by this :

PHP Code: [ Select ]
 
   function store_picture()    
 
    {    
 
        //$_FILE is a superglobal so you can get it from there    
 
        foreach ($_FILES as $file)    
 
        {    
 
             print "<p>".$file['name']."<br />";    
 
            print "temp :".$file['tmp_name']."<br />";    
 
            print "type :".$file['type'] ."<br />";    
 
            print "size :".$file['size'] ."<br />";    
 
            print "error :".$file['error'] ."</p>";    
 
            if($file['size'] >= $this->size_limit)    
 
            {  
 
                /* HERE I'M ALSO ECHOING THE MAX SIZE SET! $this->size_limit */  
 
                    print "<p>max size set : ".$this->size_limit."</p>";  
 
                print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";    
 
                return false;    
 
            }    
 
            if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))    
 
            {    
 
                $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', '".$this->user_id."')";  
 
                //mysql_query($q) or die(mysql_error()."<br />".$q);    
 
                            }    
 
            else    
 
            {    
 
                print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";    
 
                return false;    
 
            }
 
            if(!is_dir("pict"))
 
               mkdir ("pict", 0700);    
 
            if(file_exists("pict/".$file['name']))    
 
                $file['name'] .= $this->user_id;    
 
            copy($file['tmp_name'], "pict/".$file['name']);    
 
        }                    
 
    }  
 
 
  1.  
  2.    function store_picture()    
  3.  
  4.     {    
  5.  
  6.         //$_FILE is a superglobal so you can get it from there    
  7.  
  8.         foreach ($_FILES as $file)    
  9.  
  10.         {    
  11.  
  12.              print "<p>".$file['name']."<br />";    
  13.  
  14.             print "temp :".$file['tmp_name']."<br />";    
  15.  
  16.             print "type :".$file['type'] ."<br />";    
  17.  
  18.             print "size :".$file['size'] ."<br />";    
  19.  
  20.             print "error :".$file['error'] ."</p>";    
  21.  
  22.             if($file['size'] >= $this->size_limit)    
  23.  
  24.             {  
  25.  
  26.                 /* HERE I'M ALSO ECHOING THE MAX SIZE SET! $this->size_limit */  
  27.  
  28.                     print "<p>max size set : ".$this->size_limit."</p>";  
  29.  
  30.                 print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";    
  31.  
  32.                 return false;    
  33.  
  34.             }    
  35.  
  36.             if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))    
  37.  
  38.             {    
  39.  
  40.                 $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', '".$this->user_id."')";  
  41.  
  42.                 //mysql_query($q) or die(mysql_error()."<br />".$q);    
  43.  
  44.                             }    
  45.  
  46.             else    
  47.  
  48.             {    
  49.  
  50.                 print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";    
  51.  
  52.                 return false;    
  53.  
  54.             }
  55.  
  56.             if(!is_dir("pict"))
  57.  
  58.                mkdir ("pict", 0700);    
  59.  
  60.             if(file_exists("pict/".$file['name']))    
  61.  
  62.                 $file['name'] .= $this->user_id;    
  63.  
  64.             copy($file['tmp_name'], "pict/".$file['name']);    
  65.  
  66.         }                    
  67.  
  68.     }  
  69.  
  70.  


And then tell me if you still have this warning.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

av1.jpg
temp :/tmp/phpUhajwV
type :image/pjpeg
size :6890
error :0


Warning: copy(pict/av1.jpg) [function.copy]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 146

No picture !


thats what i get
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Well,

it maybe because of the chmod of the parent folders but there's no reason if you can synchronize the files in.

please try without a dedicated folder.
replace you function by this (I remove the folder stuff and pictures will be copied in the same directory of the php script )(in fact i'm still searching for this damned trouble but try this :-) ):
PHP Code: [ Select ]
 
php function store_picture()    
 
    {    
 
        //$_FILE is a superglobal so you can get it from there    
 
        foreach ($_FILES as $file)    
 
        {    
 
             print "<p>".$file['name']."<br />";    
 
            print "temp :".$file['tmp_name']."<br />";      
 
            print "type :".$file['type'] ."<br />";      
 
            print "size :".$file['size'] ."<br />";    
 
            print "error :".$file['error'] ."</p>";    
 
            if($file['size'] >= $this->size_limit)    
 
            {    
 
                /* HERE I'M ALSO ECHOING THE MAX SIZE SET! $this->size_limit */  
 
                    print "<p>max size set : ".$this->size_limit."</p>";    
 
                print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";    
 
                return false;    
 
            }    
 
            if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))    
 
            {    
 
                $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', '".$this->user_id."')";  
 
                //mysql_query($q) or die(mysql_error()."<br />".$q);    
 
                            }    
 
            else    
 
            {    
 
                print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";    
 
                return false;    
 
            }
 
           
 
            if(file_exists($file['name']))    
 
                $file['name'] .= $this->user_id;    
 
            copy($file['tmp_name'], $file['name']);    
 
        }                    
 
    }
 
 
  1.  
  2. php function store_picture()    
  3.  
  4.     {    
  5.  
  6.         //$_FILE is a superglobal so you can get it from there    
  7.  
  8.         foreach ($_FILES as $file)    
  9.  
  10.         {    
  11.  
  12.              print "<p>".$file['name']."<br />";    
  13.  
  14.             print "temp :".$file['tmp_name']."<br />";      
  15.  
  16.             print "type :".$file['type'] ."<br />";      
  17.  
  18.             print "size :".$file['size'] ."<br />";    
  19.  
  20.             print "error :".$file['error'] ."</p>";    
  21.  
  22.             if($file['size'] >= $this->size_limit)    
  23.  
  24.             {    
  25.  
  26.                 /* HERE I'M ALSO ECHOING THE MAX SIZE SET! $this->size_limit */  
  27.  
  28.                     print "<p>max size set : ".$this->size_limit."</p>";    
  29.  
  30.                 print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";    
  31.  
  32.                 return false;    
  33.  
  34.             }    
  35.  
  36.             if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))    
  37.  
  38.             {    
  39.  
  40.                 $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', '".$this->user_id."')";  
  41.  
  42.                 //mysql_query($q) or die(mysql_error()."<br />".$q);    
  43.  
  44.                             }    
  45.  
  46.             else    
  47.  
  48.             {    
  49.  
  50.                 print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";    
  51.  
  52.                 return false;    
  53.  
  54.             }
  55.  
  56.            
  57.  
  58.             if(file_exists($file['name']))    
  59.  
  60.                 $file['name'] .= $this->user_id;    
  61.  
  62.             copy($file['tmp_name'], $file['name']);    
  63.  
  64.         }                    
  65.  
  66.     }
  67.  
  68.  
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

jarhead.jpg
temp :/tmp/phpTtXqxK
type :image/pjpeg
size :42413
error :0


Warning: copy(jarhead.jpg) [function.copy]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 145

No picture !
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

OK, I tried on my FTP
you can make tries on it
http://monsieurgisele.free.fr/photos/public/upload.php


And it worked like can see with this (contents the class definition + something below to make it run, I comments my db connexion :-) ) :

PHP Code: [ Select ]
 
class album
 
{
 
   var $user_id;
 
   var $size_limit = 100000;
 
   var $nb_limit;
 
   var $stored_pictures;
 
   function album($user_id, $size_limit, $nb_limit = 5)
 
   {
 
      $this->user_id = $user_id;
 
      $this->nb_limit = $nb_limit;
 
      $this->size_limit = $size_limit;
 
   }
 
   function display_album()
 
   {
 
      print $q = "SELECT picture_id, name, size FROM picture WHERE user_id=".$this->user_id;
 
      $this->stored_pictures = mysql_query($q) or die(mysql_error()."<br />".$q);
 
      if(mysql_num_rows($this->stored_pictures))
 
      {
 
         print "<table border=\"1\">\n<tr><td align=\"center\"><b>Name</b></td><td align=\"center\"><b>Size</b></td><td align=\"center\"><b>Picture</b></td><td align=\"center\"><b>Action</b></td></tr>\n";
 
         while($d = mysql_fetch_row($this->stored_pictures))
 
         {
 
            print "<tr><td>".$d[1]."</td><td align=\"center\">".$d[2]."</td><td align=\"center\"><img src=\"pict/".$d[1]."\" /></td>";
 
            print "<td align=\"center\"><a href=\"".$_SERVER["PHP_SELF"]."?del_pict_id=".$d[0]."\">Delete</a></td></tr>\n";
 
         }
 
         print "</table>\n";
 
      }
 
      else
 
         print "<p>No picture ! </p>\n";
 
   }
 
   function store_picture()
 
   {
 
      //$_FILE is a superglobal so you can get it from there
 
      foreach ($_FILES as $file)
 
      {
 
         print "<p>".$file['name']."<br />";
 
         print "temp :".$file['tmp_name']."<br />";
 
         print "type :".$file['type'] ."<br />";
 
         print "size :".$file['size'] ."<br />";
 
         print "error :".$file['error'] ."</p>";
 
         if($file['size'] >= $this->size_limit)
 
         {
 
            print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";
 
            return false;
 
         }
 
         if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))
 
         {
 
            if(file_exists("pict/".$file['name']))
 
               $file['name'] = $this->user_id.$file['name'];
 
            $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', ".$this->user_id.")";
 
            mysql_query($q) or die(mysql_error()."<br />".$q);
 
         }
 
         else
 
         {
 
            print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";
 
            return false;
 
         }
 
         if(!is_dir("pict"))
 
                mkdir ("pict", 0700);
 
         copy($file['tmp_name'], "pict/".$file['name']);
 
      }          
 
   }
 
   function delete_picture()
 
   {
 
      $q = "SELECT name FROM picture WHERE picture_id=".$_GET["del_pict_id"];
 
      $r = mysql_query($q) or die(mysql_error()."<br />".$q);
 
      $d = mysql_fetch_row($r);
 
      $file = "pict/".$d[0];
 
      $q = "DELETE FROM picture WHERE picture_id=".$_GET["del_pict_id"]." LIMIT 1";
 
      mysql_query($q) or die(mysql_error()."<br />".$q);
 
      if(file_exists($file))
 
         unlink($file);
 
   }
 
   function display_upload_form($nb_file = 1)
 
   {
 
      if(!$this->nb_limit <= mysql_num_rows($this->stored_pictures))
 
      {
 
         print "<form method=\"post\" enctype=\"multipart/form-data\" action=\"".$_SERVER["PHP_SELF"]."?up=1\">\n";
 
         for($i = 0;$i < $nb_file;$i++)
 
            print "<p>\nPicucture N°".($i + 1)." : <input type=\"file\" name=\"file".$i."\" size=\"30\"></p>";
 
         print "<input type=\"submit\" value=\"upload\" />\n";
 
      }
 
      else
 
         print "<p>no more upload allowed !</p>";
 
   }
 
}
 
/* MY OWN CONNEXION
 
$pass = '******';
 
$db = mysql_connect('*****', '*****', $pass) or die (mysql_error());
 
mysql_select_db("test") or die(mysql_error());  */
 
 
 
//I forced 1 in first argument for user id=1 for my test
 
$album = new album(1, 100000, 3);
 
if($_GET["del_pict_id"])
 
   $album->delete_picture();
 
if($_GET["up"])
 
   $album->store_picture();
 
$album->display_album();
 
$album->display_upload_form($nb_file = 1);
 
 
  1.  
  2. class album
  3.  
  4. {
  5.  
  6.    var $user_id;
  7.  
  8.    var $size_limit = 100000;
  9.  
  10.    var $nb_limit;
  11.  
  12.    var $stored_pictures;
  13.  
  14.    function album($user_id, $size_limit, $nb_limit = 5)
  15.  
  16.    {
  17.  
  18.       $this->user_id = $user_id;
  19.  
  20.       $this->nb_limit = $nb_limit;
  21.  
  22.       $this->size_limit = $size_limit;
  23.  
  24.    }
  25.  
  26.    function display_album()
  27.  
  28.    {
  29.  
  30.       print $q = "SELECT picture_id, name, size FROM picture WHERE user_id=".$this->user_id;
  31.  
  32.       $this->stored_pictures = mysql_query($q) or die(mysql_error()."<br />".$q);
  33.  
  34.       if(mysql_num_rows($this->stored_pictures))
  35.  
  36.       {
  37.  
  38.          print "<table border=\"1\">\n<tr><td align=\"center\"><b>Name</b></td><td align=\"center\"><b>Size</b></td><td align=\"center\"><b>Picture</b></td><td align=\"center\"><b>Action</b></td></tr>\n";
  39.  
  40.          while($d = mysql_fetch_row($this->stored_pictures))
  41.  
  42.          {
  43.  
  44.             print "<tr><td>".$d[1]."</td><td align=\"center\">".$d[2]."</td><td align=\"center\"><img src=\"pict/".$d[1]."\" /></td>";
  45.  
  46.             print "<td align=\"center\"><a href=\"".$_SERVER["PHP_SELF"]."?del_pict_id=".$d[0]."\">Delete</a></td></tr>\n";
  47.  
  48.          }
  49.  
  50.          print "</table>\n";
  51.  
  52.       }
  53.  
  54.       else
  55.  
  56.          print "<p>No picture ! </p>\n";
  57.  
  58.    }
  59.  
  60.    function store_picture()
  61.  
  62.    {
  63.  
  64.       //$_FILE is a superglobal so you can get it from there
  65.  
  66.       foreach ($_FILES as $file)
  67.  
  68.       {
  69.  
  70.          print "<p>".$file['name']."<br />";
  71.  
  72.          print "temp :".$file['tmp_name']."<br />";
  73.  
  74.          print "type :".$file['type'] ."<br />";
  75.  
  76.          print "size :".$file['size'] ."<br />";
  77.  
  78.          print "error :".$file['error'] ."</p>";
  79.  
  80.          if($file['size'] >= $this->size_limit)
  81.  
  82.          {
  83.  
  84.             print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";
  85.  
  86.             return false;
  87.  
  88.          }
  89.  
  90.          if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))
  91.  
  92.          {
  93.  
  94.             if(file_exists("pict/".$file['name']))
  95.  
  96.                $file['name'] = $this->user_id.$file['name'];
  97.  
  98.             $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', ".$this->user_id.")";
  99.  
  100.             mysql_query($q) or die(mysql_error()."<br />".$q);
  101.  
  102.          }
  103.  
  104.          else
  105.  
  106.          {
  107.  
  108.             print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";
  109.  
  110.             return false;
  111.  
  112.          }
  113.  
  114.          if(!is_dir("pict"))
  115.  
  116.                 mkdir ("pict", 0700);
  117.  
  118.          copy($file['tmp_name'], "pict/".$file['name']);
  119.  
  120.       }          
  121.  
  122.    }
  123.  
  124.    function delete_picture()
  125.  
  126.    {
  127.  
  128.       $q = "SELECT name FROM picture WHERE picture_id=".$_GET["del_pict_id"];
  129.  
  130.       $r = mysql_query($q) or die(mysql_error()."<br />".$q);
  131.  
  132.       $d = mysql_fetch_row($r);
  133.  
  134.       $file = "pict/".$d[0];
  135.  
  136.       $q = "DELETE FROM picture WHERE picture_id=".$_GET["del_pict_id"]." LIMIT 1";
  137.  
  138.       mysql_query($q) or die(mysql_error()."<br />".$q);
  139.  
  140.       if(file_exists($file))
  141.  
  142.          unlink($file);
  143.  
  144.    }
  145.  
  146.    function display_upload_form($nb_file = 1)
  147.  
  148.    {
  149.  
  150.       if(!$this->nb_limit <= mysql_num_rows($this->stored_pictures))
  151.  
  152.       {
  153.  
  154.          print "<form method=\"post\" enctype=\"multipart/form-data\" action=\"".$_SERVER["PHP_SELF"]."?up=1\">\n";
  155.  
  156.          for($i = 0;$i < $nb_file;$i++)
  157.  
  158.             print "<p>\nPicucture N°".($i + 1)." : <input type=\"file\" name=\"file".$i."\" size=\"30\"></p>";
  159.  
  160.          print "<input type=\"submit\" value=\"upload\" />\n";
  161.  
  162.       }
  163.  
  164.       else
  165.  
  166.          print "<p>no more upload allowed !</p>";
  167.  
  168.    }
  169.  
  170. }
  171.  
  172. /* MY OWN CONNEXION
  173.  
  174. $pass = '******';
  175.  
  176. $db = mysql_connect('*****', '*****', $pass) or die (mysql_error());
  177.  
  178. mysql_select_db("test") or die(mysql_error());  */
  179.  
  180.  
  181.  
  182. //I forced 1 in first argument for user id=1 for my test
  183.  
  184. $album = new album(1, 100000, 3);
  185.  
  186. if($_GET["del_pict_id"])
  187.  
  188.    $album->delete_picture();
  189.  
  190. if($_GET["up"])
  191.  
  192.    $album->store_picture();
  193.  
  194. $album->display_album();
  195.  
  196. $album->display_upload_form($nb_file = 1);
  197.  
  198.  
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Ok it's getting late here, see you tomorow morning. ;-)
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

jarhead.jpg
temp :/tmp/phpujPw2C
type :image/pjpeg
size :42413
error :0


Warning: copy(pict/jarhead.jpg) [function.copy]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 131
SELECT picture_id, name, size FROM picture WHERE user_id=1

Name Size Picture Action
jarhead.jpg 42413 Delete

if you want to you can sign up and see for yourself..
http://www.gothicgreenwire.com/ggwnew/
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Hi,
I believe you :-)
Well, what about trying move_uploaded_file()?

please try to replace :
PHP Code: [ Select ]
 
copy($file['tmp_name'], "pict/".$file['name']);
 
 
  1.  
  2. copy($file['tmp_name'], "pict/".$file['name']);
  3.  
  4.  


by
PHP Code: [ Select ]
 
move_uploaded_file($file['tmp_name'], "pict/".$file['name']);
 
 
  1.  
  2. move_uploaded_file($file['tmp_name'], "pict/".$file['name']);
  3.  
  4.  

in store_picture().

By the way, I realize I left a print, just in display_album() just before before the select query, that why it is showed when you rin it :-)
PHP Code: [ Select ]
 
print $q = "SELECT picture_id, name, size FROM picture WHERE user_id=".$this->user_id;
 
 
  1.  
  2. print $q = "SELECT picture_id, name, size FROM picture WHERE user_id=".$this->user_id;
  3.  
  4.  

you just have to remove the print ;-)

yeah and you can try to upload on my link if you want just to see how ot should work on yours :

http://monsieurgisele.free.fr/photos/public/upload.php
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

demon1.jpg
temp :/tmp/phpcKIgal
type :image/pjpeg
size :4279
error :0


Warning: move_uploaded_file(pict/demon1.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/happykj/public_html/ggwnew/userpictures.php on line 131

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpcKIgal' to 'pict/demon1.jpg' in /home/happykj/public_html/ggwnew/userpictures.php on line 131


still did not work
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

I'm sorry.

With your FTP client, Check your chmod, if know how.(properties of the parent folder)

both paths seem to be OK in the move_uploaded_file() anyway, I'm still searching.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

if you are meaning this

owner -> read, write, execute
group -> read, execute
public ->read, execute

if not that then i dont know what you mean.
  • lioness
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1615

Post 3+ Months Ago

Yeah that's it. I uploaded a file ok. I did get some mysql errors though.
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

but the file is not there...
  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 760
  • Loc: Conroe, Texas

Post 3+ Months Ago

PHP Code: [ Select ]
<?php class album
 
{
 
    var $user_id;
 
    var $size_limit = 100000;
 
    var $nb_limit;
 
    var $stored_pictures;
 
    function album($user_id, $size_limit, $nb_limit = 5)
 
    {
 
        $this->user_id = $user_id;
 
        $this->nb_limit = $nb_limit;
 
        $this->size_limit = $size_limit;
 
    }
 
    function display_album()
 
    {
 
         $q = "SELECT picture_id, name, size FROM picture WHERE user_id=".$this->user_id;
 
        $this->stored_pictures = mysql_query($q) or die(mysql_error()."<br />".$q);
 
        if(mysql_num_rows($this->stored_pictures))
 
        {
 
            print "<table border=\"1\">\n<tr><td align=\"center\"><b>Name</b></td><td align=\"center\"><b>Size</b></td><td align=\"center\"><b>Picture</b></td><td align=\"center\"><b>Action</b></td></tr>\n";
 
            while($d = mysql_fetch_row($this->stored_pictures))
 
            {
 
                print "<tr><td>".$d[1]."</td><td align=\"center\">".$d[2]."</td><td align=\"center\"><img src=\"pict/".$d[1]."\" /></td>";
 
                print "<td align=\"center\"><a href=\"".$_SERVER["PHP_SELF"]."?del_pict_id=".$d[0]."\">Delete</a></td></tr>\n";
 
            }
 
            print "</table>\n";
 
        }
 
        else
 
            print "<p>No picture ! </p>\n";
 
    }
 
    function store_picture()
 
    {
 
        //$_FILE is a superglobal so you can get it from there
 
        foreach ($_FILES as $file)
 
        {
 
             print "<p>".$file['name']."<br />";
 
            print "temp :".$file['tmp_name']."<br />";  
 
            print "type :".$file['type'] ."<br />";  
 
            print "size :".$file['size'] ."<br />";
 
            print "error :".$file['error'] ."</p>";
 
            if($file['size'] >= $this->size_limit)
 
            {
 
                print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";
 
                return false;
 
            }
 
            if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))
 
            {
 
                if(file_exists("pict/".$file['name']))
 
                    $file['name'] = $this->user_id.$file['name'];
 
                $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', ".$this->user_id.")";
 
                mysql_query($q) or die(mysql_error()."<br />".$q);
 
            }
 
            else
 
            {
 
                print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";
 
                return false;
 
            }
 
            if(!is_dir("pict"))  
 
                mkdir ("pict", 0700);  
 
           move_uploaded_file($file['tmp_name'], "pict/".$file['name']);
 
        }                
 
    }
 
    function delete_picture()
 
    {
 
        $q = "SELECT name FROM picture WHERE picture_id=".$_GET["del_pict_id"];
 
        $r = mysql_query($q) or die(mysql_error()."<br />".$q);
 
        $d = mysql_fetch_row($r);
 
        $file = "pict/".$d[0];
 
        $q = "DELETE FROM picture WHERE picture_id=".$_GET["del_pict_id"]." LIMIT 1";
 
        mysql_query($q) or die(mysql_error()."<br />".$q);
 
        if(file_exists($file))
 
            unlink($file);  
 
    }
 
    function display_upload_form($nb_file = 1)
 
    {
 
        if(!$this->nb_limit <= mysql_num_rows($this->stored_pictures))
 
        {
 
            print "<form method=\"post\" enctype=\"multipart/form-data\" action=\"".$_SERVER["PHP_SELF"]."?up=1\">\n";
 
            for($i = 0;$i < $nb_file;$i++)
 
                 print "<p>\nPicucture N°".($i + 1)." : <input type=\"file\" name=\"file".$i."\" size=\"30\"></p>";
 
             print "<input type=\"submit\" value=\"upload\" />\n";
 
        }
 
        else
 
            print "<p>no more upload allowed !</p>";
 
    }
 
}
 
/* MY OWN CONNEXION
 
$pass = '******';
 
$db = mysql_connect('*****', '*****', $pass) or die (mysql_error());
 
mysql_select_db("test") or die(mysql_error());  */
 
 
 
//I forced 1 in first argument for user id=1 for my test
 
$album = new album(1, 100000, 3);
 
if($_GET["del_pict_id"])
 
    $album->delete_picture();
 
if($_GET["up"])
 
    $album->store_picture();
 
$album->display_album();
 
$album->display_upload_form($nb_file = 1); ?>
  1. <?php class album
  2.  
  3. {
  4.  
  5.     var $user_id;
  6.  
  7.     var $size_limit = 100000;
  8.  
  9.     var $nb_limit;
  10.  
  11.     var $stored_pictures;
  12.  
  13.     function album($user_id, $size_limit, $nb_limit = 5)
  14.  
  15.     {
  16.  
  17.         $this->user_id = $user_id;
  18.  
  19.         $this->nb_limit = $nb_limit;
  20.  
  21.         $this->size_limit = $size_limit;
  22.  
  23.     }
  24.  
  25.     function display_album()
  26.  
  27.     {
  28.  
  29.          $q = "SELECT picture_id, name, size FROM picture WHERE user_id=".$this->user_id;
  30.  
  31.         $this->stored_pictures = mysql_query($q) or die(mysql_error()."<br />".$q);
  32.  
  33.         if(mysql_num_rows($this->stored_pictures))
  34.  
  35.         {
  36.  
  37.             print "<table border=\"1\">\n<tr><td align=\"center\"><b>Name</b></td><td align=\"center\"><b>Size</b></td><td align=\"center\"><b>Picture</b></td><td align=\"center\"><b>Action</b></td></tr>\n";
  38.  
  39.             while($d = mysql_fetch_row($this->stored_pictures))
  40.  
  41.             {
  42.  
  43.                 print "<tr><td>".$d[1]."</td><td align=\"center\">".$d[2]."</td><td align=\"center\"><img src=\"pict/".$d[1]."\" /></td>";
  44.  
  45.                 print "<td align=\"center\"><a href=\"".$_SERVER["PHP_SELF"]."?del_pict_id=".$d[0]."\">Delete</a></td></tr>\n";
  46.  
  47.             }
  48.  
  49.             print "</table>\n";
  50.  
  51.         }
  52.  
  53.         else
  54.  
  55.             print "<p>No picture ! </p>\n";
  56.  
  57.     }
  58.  
  59.     function store_picture()
  60.  
  61.     {
  62.  
  63.         //$_FILE is a superglobal so you can get it from there
  64.  
  65.         foreach ($_FILES as $file)
  66.  
  67.         {
  68.  
  69.              print "<p>".$file['name']."<br />";
  70.  
  71.             print "temp :".$file['tmp_name']."<br />";  
  72.  
  73.             print "type :".$file['type'] ."<br />";  
  74.  
  75.             print "size :".$file['size'] ."<br />";
  76.  
  77.             print "error :".$file['error'] ."</p>";
  78.  
  79.             if($file['size'] >= $this->size_limit)
  80.  
  81.             {
  82.  
  83.                 print "<p>failed ".$file['name']." ".$file['size']." bytes : picture too heavy !</p>";
  84.  
  85.                 return false;
  86.  
  87.             }
  88.  
  89.             if(preg_match("#^([a-z0-9_]+[.](jpg|gif))#i", $file['name']))
  90.  
  91.             {
  92.  
  93.                 if(file_exists("pict/".$file['name']))
  94.  
  95.                     $file['name'] = $this->user_id.$file['name'];
  96.  
  97.                 $q = "INSERT INTO picture (picture_id, name, size, user_id) VALUES ('', '".$file['name']."', '".$file['size']."', ".$this->user_id.")";
  98.  
  99.                 mysql_query($q) or die(mysql_error()."<br />".$q);
  100.  
  101.             }
  102.  
  103.             else
  104.  
  105.             {
  106.  
  107.                 print "<p>failed ".$file['name']." : Wrong picture name or extention !</p>";
  108.  
  109.                 return false;
  110.  
  111.             }
  112.  
  113.             if(!is_dir("pict"))  
  114.  
  115.                 mkdir ("pict", 0700);  
  116.  
  117.            move_uploaded_file($file['tmp_name'], "pict/".$file['name']);
  118.  
  119.         }                
  120.  
  121.     }
  122.  
  123.     function delete_picture()
  124.  
  125.     {
  126.  
  127.         $q = "SELECT name FROM picture WHERE picture_id=".$_GET["del_pict_id"];
  128.  
  129.         $r = mysql_query($q) or die(mysql_error()."<br />".$q);
  130.  
  131.         $d = mysql_fetch_row($r);
  132.  
  133.         $file = "pict/".$d[0];
  134.  
  135.         $q = "DELETE FROM picture WHERE picture_id=".$_GET["del_pict_id"]." LIMIT 1";
  136.  
  137.         mysql_query($q) or die(mysql_error()."<br />".$q);
  138.  
  139.         if(file_exists($file))
  140.  
  141.             unlink($file);  
  142.  
  143.     }
  144.  
  145.     function display_upload_form($nb_file = 1)
  146.  
  147.     {
  148.  
  149.         if(!$this->nb_limit <= mysql_num_rows($this->stored_pictures))
  150.  
  151.         {
  152.  
  153.             print "<form method=\"post\" enctype=\"multipart/form-data\" action=\"".$_SERVER["PHP_SELF"]."?up=1\">\n";
  154.  
  155.             for($i = 0;$i < $nb_file;$i++)
  156.  
  157.                  print "<p>\nPicucture N°".($i + 1)." : <input type=\"file\" name=\"file".$i."\" size=\"30\"></p>";
  158.  
  159.              print "<input type=\"submit\" value=\"upload\" />\n";
  160.  
  161.         }
  162.  
  163.         else
  164.  
  165.             print "<p>no more upload allowed !</p>";
  166.  
  167.     }
  168.  
  169. }
  170.  
  171. /* MY OWN CONNEXION
  172.  
  173. $pass = '******';
  174.  
  175. $db = mysql_connect('*****', '*****', $pass) or die (mysql_error());
  176.  
  177. mysql_select_db("test") or die(mysql_error());  */
  178.  
  179.  
  180.  
  181. //I forced 1 in first argument for user id=1 for my test
  182.  
  183. $album = new album(1, 100000, 3);
  184.  
  185. if($_GET["del_pict_id"])
  186.  
  187.     $album->delete_picture();
  188.  
  189. if($_GET["up"])
  190.  
  191.     $album->store_picture();
  192.  
  193. $album->display_album();
  194.  
  195. $album->display_upload_form($nb_file = 1); ?>


Ok problemmm It works. BUT everybody can see other pictures and things.
  • gisele
  • Expert
  • Expert
  • User avatar
  • Posts: 585
  • Loc: Nimes (France)

Post 3+ Months Ago

Hi, is it your own code above?

You should keep the class définiyion but change this part :

PHP Code: [ Select ]
 
/* MY OWN CONNEXION  
 
$pass = '******';  
 
$db = mysql_connect('*****', '*****', $pass) or die (mysql_error());  
 
mysql_select_db("test") or die(mysql_error());  */  
 
 
 
//I forced 1 in first argument for user id=1 for my test  
 
$album = new album(1, 100000, 3);  
 
if($_GET["del_pict_id"])  
 
    $album->delete_picture();  
 
if($_GET["up"])  
 
    $album->store_picture();  
 
$album->display_album();  
 
$album->display_upload_form($nb_file = 1);
 
 
  1.  
  2. /* MY OWN CONNEXION  
  3.  
  4. $pass = '******';  
  5.  
  6. $db = mysql_connect('*****', '*****', $pass) or die (mysql_error());  
  7.  
  8. mysql_select_db("test") or die(mysql_error());  */  
  9.  
  10.  
  11.  
  12. //I forced 1 in first argument for user id=1 for my test  
  13.  
  14. $album = new album(1, 100000, 3);  
  15.  
  16. if($_GET["del_pict_id"])  
  17.  
  18.     $album->delete_picture();  
  19.  
  20. if($_GET["up"])  
  21.  
  22.     $album->store_picture();  
  23.  
  24. $album->display_album();  
  25.  
  26. $album->display_upload_form($nb_file = 1);
  27.  
  28.  


it is the procedural part, that makes run the stuff.

like I said before,

PHP Code: [ Select ]
 
$album = new album(1, 100000, 3);  
 
 
  1.  
  2. $album = new album(1, 100000, 3);  
  3.  
  4.  

see the first argument '1" is an arbitrary value that makes works as an example, but you should put instead the variable $username , you the one you use for all the other stuff and that you pass in the links, so that logged user manages his own pictures.
Otherwise with my example, all os done depending on my pseudo username "1".
you should put right here the real current user , something like that :
PHP Code: [ Select ]
 
$album = new album($username, 100000, 3);  
 
 
  1.  
  2. $album = new album($username, 100000, 3);  
  3.  
  4.  


By the way the second argument is for the max allowed size of the pictures, and the third is for the max pictured allowed to store for the user.

Post Information

  • Total Posts in this topic: 97 posts
  • Users browsing this forum: No registered users and 38 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2016. Ozzu® is a registered trademark of Unmelted, LLC.