Multiple rows in mysql

  • demonmaestro
  • Gold Member
  • Gold Member
  • User avatar
  • Posts: 677
  • 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?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • 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: 677
  • 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: 677
  • 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: 677
  • 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: 677
  • 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: 677
  • 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: 677
  • 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: 677
  • 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: 677
  • 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: 677
  • 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: 677
  • 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: 677
  • 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: 677
  • 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: 677
  • 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: 677
  • 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.            ?>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 97 posts
  • Users browsing this forum: No registered users and 137 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-2014. Ozzu® is a registered trademark of Unmelted, LLC.