User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion

Reply
Thread Tools Display Modes
Unread 6 Jul 2005, 20:22   #1
Ragnarak
Registered User
 
Ragnarak's Avatar
 
Join Date: Oct 2000
Posts: 4,944
Ragnarak is a splendid one to beholdRagnarak is a splendid one to beholdRagnarak is a splendid one to beholdRagnarak is a splendid one to beholdRagnarak is a splendid one to beholdRagnarak is a splendid one to beholdRagnarak is a splendid one to behold
Simple PHP Help - Emptying table

I'm working on something at the minute but I need it to let people empty the database table without having any access to phpmyadmin or anything. I was thinking something along the lines of the following in a emptytable.php file should work but it doesn't seem to.


PHP Code:
<?php
    $usr 
"username";
    
$pwd "password";
    
$db "database_name";
    
$host "localhost";

    
# connect to database
    
$cid mysql_connect($host,$usr,$pwd);
    
mysql_select_db($db);
    if (
mysql_error()) { print "Database ERROR: " mysql_error(); }


{

    
# setup SQL statement
    
$sql 'TRUNCATE TABLE `tablename`';

    
# execute SQL statement
    
$rs mysql_query($sql$cid);
    if (
mysql_error()) { print "Database Error: $sql " mysql_error(); }

print 
"Table Emptied";

}


?>
This doesn't seem to actually do anything and even if it did I don't know how secure it'd be so I was hoping someone could help out.

Thanks.
__________________
I find it kind of funny
I find it kind of sad
The dreams in which i'm dying
Are the best i've ever had
Ragnarak is offline   Reply With Quote
Unread 6 Jul 2005, 21:02   #2
Dante Hicks
Clerk
 
Join Date: Jun 2001
Posts: 13,940
Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.Dante Hicks has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: Simple PHP Help - Emptying table

I haven't got PHP installed on this machine, but does the latter part in curly brackets actually get executed? i.e. the # Setup SQL Statement stuff.

You've got if....{ } and then nothing else...? I'm probably missing something though.

Who will have access to this script? And what sort of table is it? Best to have the "empty database" stuff in a function which you can then call when certain conditions are met (e.g. they have permission to run it, the table isn't already empty, etc)
Dante Hicks is offline   Reply With Quote
Unread 6 Jul 2005, 21:58   #3
Ragnarak
Registered User
 
Ragnarak's Avatar
 
Join Date: Oct 2000
Posts: 4,944
Ragnarak is a splendid one to beholdRagnarak is a splendid one to beholdRagnarak is a splendid one to beholdRagnarak is a splendid one to beholdRagnarak is a splendid one to beholdRagnarak is a splendid one to beholdRagnarak is a splendid one to behold
Re: Simple PHP Help - Emptying table

I think it should work, the print "Tale Emptied" is displayed so the {'s are being executed.
The IF statement is just to print an error message if the database info is incorrect.

What I have is a page that people can use to input data into a mysql table and this part is meant to be just the "reset" page to wipe the table empty but it doesn't seem to be working as I thought it would.

The pages will be protected by a .htaccess file and password which'll do the job even though I could probably do it a lot more elegantly if need be.
__________________
I find it kind of funny
I find it kind of sad
The dreams in which i'm dying
Are the best i've ever had
Ragnarak is offline   Reply With Quote
Unread 7 Jul 2005, 09:40   #4
wu_trax
Registered User
 
Join Date: Jan 2003
Posts: 4,290
wu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet societywu_trax is a pillar of this Internet society
Re: Simple PHP Help - Emptying table

whats the reason for those extra {'s? i seee nothing else wrog with the script (given that your DB-user has the necessary rights to execute that statement).
__________________
im not tolerant, i just dont care.
wu_trax is offline   Reply With Quote
Unread 7 Jul 2005, 12:47   #5
Ragnarak
Registered User
 
Ragnarak's Avatar
 
Join Date: Oct 2000
Posts: 4,944
Ragnarak is a splendid one to beholdRagnarak is a splendid one to beholdRagnarak is a splendid one to beholdRagnarak is a splendid one to beholdRagnarak is a splendid one to beholdRagnarak is a splendid one to beholdRagnarak is a splendid one to behold
Re: Simple PHP Help - Emptying table

Quote:
Originally Posted by wu_trax
whats the reason for those extra {'s? i seee nothing else wrog with the script (given that your DB-user has the necessary rights to execute that statement).
They were remnants from something else that got altered. I removed them and now it works fine. Thanks
__________________
I find it kind of funny
I find it kind of sad
The dreams in which i'm dying
Are the best i've ever had
Ragnarak is offline   Reply With Quote
Unread 2 Aug 2005, 09:30   #6
Remy
Ex-Head Multihunter
 
Remy's Avatar
 
Join Date: Sep 2003
Location: At home
Posts: 900
Remy has much to be proud ofRemy has much to be proud ofRemy has much to be proud ofRemy has much to be proud ofRemy has much to be proud ofRemy has much to be proud ofRemy has much to be proud ofRemy has much to be proud of
Re: Simple PHP Help - Emptying table

$sql = 'TRUNCATE TABLE `tablename`';
use: delete * from tablename
__________________
R02.0-R4.0: [noob]
R05.0: [Wrath]/[Fury]
R06.0: Quit after 1 week
R7-9: Had an account, but didnt play seriously
R09.5: []LCH[] Officer
R10.0: []LCH[] HC (Rank #9, #1 Gal)
R10.5-R18.0: []LCH[] HC Scanner!
R18.0-R33 : Multihunter, Head MH
R34-.. : [CT] HC
Remy is offline   Reply With Quote
Unread 23 Aug 2005, 16:32   #7
MrLobster
Commander in Briefs!
 
MrLobster's Avatar
 
Join Date: Dec 2000
Location: UK
Posts: 783
MrLobster has much to be proud ofMrLobster has much to be proud ofMrLobster has much to be proud ofMrLobster has much to be proud ofMrLobster has much to be proud ofMrLobster has much to be proud ofMrLobster has much to be proud ofMrLobster has much to be proud ofMrLobster has much to be proud of
Re: Simple PHP Help - Emptying table

Code:
  $database_location = 'localhost'; 
  $database_name     = 'mydatabase';
  $database_username = 'myusername'; 
  $database_password = 'mypassword';

  $dbtables['members']   = 'table_members';
  $dbtables['news']      = 'table_news';
  $dbtables['downloads'] = 'table_downloads';

  function connectDB()
  {
    include('config.php');
	
    @ $conn = new mysqli($database_location, $database_username, $database_password,$database_name);

    if (mysqli_connect_errno())
      die( '<h1>Error: Could not connect to database, please contact the system admin</h1>');

    return $conn;
  }

  $db = connectDB(); 
  
  echo "<b>Dropping all tables </b><BR>"; 

  foreach ($dbtables as $table => $tablename)
  {
    echo "Dropping $table ";
    $query = $db->query("DROP TABLE $tablename"); // Delete all tables in the database
    echo "- table dropped successfully.<br>";
  }

  echo "<b>All tables have been successfully dropped.</b><p>";
this does use the mysqli.dll (notice the i) not mysql.dll you have to make sure you have it running, and it will also delete all tables that you have list in the $dbtables array, i'm sure you can modify it to empty the tables instead.
__________________
<Kila> WHAT HAVE YOU DONE WITH MY PRECIOUS FORUMS
<Zeyi> 24h forum closure
<Zeyi> all posts recalled

"he's got a proven track record when it comes to showy art composition" - Tommy

<Sigi> Light: can I ask u how many open internet-windows u always have?
<MrLobster|PM> i have 2, the pa page, and the website for naked light pictures
<Ave> both has bad gfx
MrLobster is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Forum Jump


All times are GMT +1. The time now is 09:15.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018