Page 1 of 1

Problem dropping a table from PHP code

Posted: Thu May 19, 2011 3:08 pm
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

Re: Problem dropping a table from PHP code

Posted: Thu May 19, 2011 3:45 pm
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!

Re: Problem dropping a table from PHP code

Posted: Fri May 20, 2011 8:39 am
by Gopesh
U have to add mysql_query() after $sql.Otherwise the drop table query doesnot work in Mysql ...

Re: Problem dropping a table from PHP code

Posted: Fri May 20, 2011 10:16 am
by davidhopkins
Thanks guys ! Works a treat now, Stupid me :D