Jump to content


Photo

How to add column to existing table


  • Please log in to reply
1 reply to this topic

#1 briguy9872

briguy9872
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 05 April 2006 - 01:21 AM

[!--quoteo(post=361416:date=Apr 3 2006, 07:40 PM:name=khendar)--][div class=\'quotetop\']QUOTE(khendar @ Apr 3 2006, 07:40 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
The rest is simple:
Add a new column to your `pm` table which is called `trash`.
Set the default value of `trash` to false - or no - or 0
When someone deletes their message, dont ACTUALLY delete it, just change the value of the `trash` field to true - or yes - or 1.
[/quote]
I really don't know how to do that. PLEASE WALK me through that. Here is DELPM.php
<body bgcolor="green">
<? error_reporting(E_ERROR);?>
<?php

include 'dbconnect.php';
include 'styleb.css';
session_start();




if (isset($_SESSION['user'])) 
  {
    $user=$_SESSION['user'];
    $getuser="SELECT * from register where userid='$user'";
    $getuser2=mysql_query($getuser) or die("Could not get user info");
    $getuser3=mysql_fetch_array($getuser2);
    print "<center>";
    print "<table class='maintable'>";
    print "<tr class='linktable'><td><center>Delete PM</td></tr>";
    print "<tr class='posttable'><td>";
   $user2=$_SESSION['user'];
$ID = $_POST['id'];
    $getyourpms="SELECT * from pm as a,register as b where a.reciever='$user' and b.userid=a.sender and subject='$ID'";
    $getyourpms2=mysql_query($getyourpms) or die(mysql_error());
    while($getyourpms3=mysql_fetch_array($getyourpms2))
     $trash="INSERT into trash(sender,reciever,date,subject,message,status,time)
value('$getyourpms3[sender]','$getyourpms3[reciever]','$getyourpms3[date]','$getyourpms3[subject]','$getyourpms3[message]','$getyourpms3[status]','$getyourpms3[time]')";
       mysql_query($trash) or die("Could not put in trash can");
   
       $delpm="DELETE FROM pm where reciever='$user' and subject='$ID'";
       mysql_query($delpm) or die("Could not delete message");
       print "PM deleted, back to <A href='pmbox.php'>PM Main</a>"; 

 }
    else
    {
       print "Are you sure you want to delete this PM?<br>";
       print "<form action='delpm.php' method='post'>";
       print "<input type='submit' name='submit' value='delete'></form>";
    
}

  
  

print "</td></tr></table>";       
    print "<font size='1'>Script Produced by <A href='http://www.tfws.dynu.com'>TFWS Scripts</a></font>";
    
   
?>

Now.. What do I put in mysql database. I assume that in table pm i put a field trash. Ok.. so i did. what are the values I should put. what is the default. after that, what should i change in delpm.php??? PLEASE PLEASE HELP!!!!! PLEEAAAASE!

#2 khendar

khendar
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 05 April 2006 - 03:01 AM

[!--quoteo(post=361794:date=Apr 5 2006, 10:51 AM:name=briguy9872)--][div class=\'quotetop\']QUOTE(briguy9872 @ Apr 5 2006, 10:51 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
1. I assume that in table pm i put a field trash.
what are the values I should put.
2. what is the default.
3.after that, what should i change in delpm.php??
[/quote]
[!--quoteo(post=361416:date=Apr 3 2006, 07:40 PM:name=khendar)--][div class=\'quotetop\']QUOTE(khendar @ Apr 3 2006, 07:40 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
1. Add a new column to your `pm` table which is called `trash`.
2. Set the default value of `trash` to false - or no - or 0
3. When someone deletes their message, dont ACTUALLY delete it, just change the value of the `trash` field to true - or yes - or 1.
[/quote]

You should use whatever values you want. I'd suggest use an enum and have true/false but you could use yes/no, 0/1 whatever you want.

Instead of inserting the pm into the trash table, and then deleting the pm from the pm table, just do an update on the pm table:

$query = "UPDATE `pm` set `your_trash_field` = 'true' "

BTW there was really no need to post a new thread on this.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users