Problem dropping a table from PHP code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidhopkins
Forum Commoner
Posts: 41
Joined: Thu Jun 10, 2010 7:52 am

Problem dropping a table from PHP code

Post by davidhopkins »

Hey all,

Im trying to drop a table from inside PHP so far im using this code

Code: Select all

	//Connect to mysql server
	$JobLink = mysql_connect(localhost ,$DBuser, $DBpass);
	if(!$JobLink) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db($DBname);
	if(!$db) {
		die("Unable to select database");
	}
	$id = $_POST['JobID'];
	$jobtable = 'job_'.$id.'_q';
	$rectable = 'job_'.$id.'_r';
	$cantable = 'job_'.$id.'_c';
	
	$qry = "DELETE FROM jobs WHERE id ='$id'";
	
	$result = @mysql_query($qry);
	
	if($result) {
		$sql = "DROP TABLE job_2_c";
		header("location: ../admin");
		exit();
	}else {   
		die("Query failed");
	}
I try to delete the table right at the bottom using $sql = "DROP TABLE job_2_c";

However the table dosent get dropped, the record from the jobs database gets deleted thou

ANy ideas ?

Thanks in advance
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: Problem dropping a table from PHP code

Post by oscardog »

Does the user you're using to DROP have DROP permissions?

Wait... All you do is set $sql, you never execute it with mysql_query!
Gopesh
Forum Contributor
Posts: 143
Joined: Fri Dec 24, 2010 12:48 am
Location: India

Re: Problem dropping a table from PHP code

Post by Gopesh »

U have to add mysql_query() after $sql.Otherwise the drop table query doesnot work in Mysql ...
davidhopkins
Forum Commoner
Posts: 41
Joined: Thu Jun 10, 2010 7:52 am

Re: Problem dropping a table from PHP code

Post by davidhopkins »

Thanks guys ! Works a treat now, Stupid me :D
Post Reply