How to update data in the database when deleting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hannoudw
    New Member
    • Aug 2010
    • 115

    How to update data in the database when deleting

    Hi i'm working on a tourism site . and i am working in the admin page . exactly in the delete_reservat ion.php .
    first i have this page view_reservatio n.php :
    This page allow the admin to see all the reservation made by the customers , he can edit or delete any reservation made.
    I want when he delete the reservation made by the customer to modify the table tours, depending on what he had delete.
    her is the tables tours and orders (represents the reservations made by the customers): tours(tour_id,t itle,descriptio n,date,price,im age,max_place)
    orders(order_id ,user_id,tour_i d,date_order,cu st_num)
    the tours.max_place represents the maximum number of customers that can reserve in a trip, and the orders.cust_num represent the number of persons that have reserved in a tour.
    i want to when the admin click on delete , to delete a reservation made by the customer . to update tours.max_place ...
    therefore i wrote this function :
    Code:
    <?php
    class Reservation{
    	require("../../include/database.php");
    function delete_res($orderid){
    	$query="SELECT t.tour_id,t.max_place,o.cust_num,o.order_id
    	        FROM tours t, orders o
    			WHERE t.tour_id=o.tour_id
    			AND o.order_id=" .$orderid;
    	
    	$res=mysql_query($query);
    	echo $res;
    	while($array = mysql_fetch_array($res)){
    	$toPut=($array[cust_num] + $array['max_place']);
    	//echo $toPut;
    	$query="UPDATE tours SET max_place= '$toPut' WHERE  t.tour_id=" .$array[tour_id];
    	mysql_query($query) or die ("not done");
        mysql_query("DELETE FROM `orders` WHERE order_id = $orderid");}
    }
    }
    ?>
    and this is the delete_reservat ion.php
    Code:
    <?php
    session_start();
    require_once("../../include/database.php");
    require_once("../../functions.php");
    $id = $_GET[id];
    Reservation::delete_res($id);   
    
      //get download files of the specific category
    
    ?>
    <script language="javascript">
    alert('Data Deleted Successfully');
    location = 'view_res.php';
    </script>
    and this is the page view_reservatio n.php
    Code:
    <html>...<body>
    
            <?php
    		require("../../include/database.php");
      //get download files of the specific category
      $Get_Query = "SELECT t.title,t.description,t.price,t.date,t.image,t.tour_id,o.order_id,o.date_order,o.cust_num,u.user_id,u.full_name
                    FROM `tours` t,`orders` o, `users` u
    				WHERE o.tour_id=t.tour_id
    				and o.user_id=u.user_id
    				ORDER BY order_id";
      
      $result    =  mysql_query($Get_Query);
      
      while($row = mysql_fetch_array($result))
      {
      	
    ?>
            <tr>
              <td align="center" valign="top"><div align="center"><?php echo $row[title] ?></div></td>
              <td align="center" valign="top"><div align="center"><?php echo $row[full_name] ?> </div></td>
              <td align="center" valign="top"><div align="center"><?php echo $row[price] ?></a></div></td>
              <td align="center" valign="top"><div align="center"><?php echo $row[date] ?></a></div></td>
              <td align="center" valign="top"><div align="center"><?php echo $row[cust_num] ?></a></div></td>         
            
             <td align="center" valign="top"><div align="center"><a href="edit_res.php?id=<?php echo $row[order_id] ?>">Edit</a></div></td>
             
             <td align="center" valign="top"><div align="center"><a href="delete_res.php?id=<?php echo $row[order_id] ?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a></div></td>
            </tr>
            <?php }//while ?>
          </table>
        </div></td>
      </tr>
      </table>
    </form>
    <p>&nbsp;</p>
    </body>
    </html>
    but it's not working it keep giving me this error
    Fatal error: Class 'Reservation' not found in C:\wamp\www\tou rs mazbouta\Admin\ reservation\del ete_res.php on line 6
    could any one know why ? Help please .... Thanks for advance
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Is your page named delete_reservat ion.php or delete_res.php?

    Also have you added your class Reservation to your functions.php?

    Comment

    • hannoudw
      New Member
      • Aug 2010
      • 115

      #3
      the name of the page delete_res.php (but i said delete_reservat ion.php for more explanation)
      this is the code of delete_res.php
      and yes i added my class to the function by including the function.php on line 3
      Code:
      <?php
      session_start();
      require_once("../../functions.php");
      $id = $_GET[id];
      Reservation::delete_res($id);   
      
        //get download files of the specific category
      
      ?>
      <script language="javascript">
      alert('Data Deleted Successfully');
      location = 'view_res.php';
      </script>

      Comment

      • JKing
        Recognized Expert Top Contributor
        • Jun 2007
        • 1206

        #4
        Yes you have included the file functions.php on line 3 but is the code for your class Reservations in your functions.php file?

        Comment

        • hannoudw
          New Member
          • Aug 2010
          • 115

          #5
          Yes the code of the class Reservation is in the functions.php file !

          Comment

          Working...