PHP code help with existing script

I have an existing script that doesn’t seem to work any longer and could use some help debugging it.

The script allows us to use a web browser to add/edit/ files from a web page. The web page is database driven and shows the available files that have been uploaded. Next to each file is a ‘delete’ icon which should allow us to delete that file from the list, and I assume from the database as well.

When I click the delete icon the appropriate ‘are you sure you want to delete this file’ prompt comes up but it doesn’t actually delete the file and gives a response that the file has not been deleted. I think this is a code issue but could it be a server/db permission issue?

Below is what I think is the relevant code.

[php]

//edit-delete switch
if ( isset($_GET['mode']) && isset($_GET['id']) ) {
	$showform = false;
	$material_exists = $db->get_row("SELECT * FROM Materials WHERE id='$_GET[id]'");

	if ($material_exists) {
		$curr_File = $material_exists;
		$curr_cat = $db->get_row("SELECT * FROM Categories WHERE id='$curr_material->category_id'");
		$material_dir .= $curr_cat->folder;
		$large_material_dir .= $curr_cat->folder;
		$material_view_dir .= $curr_cat->folder;

		$max_order = $db->get_var("SELECT MAX(ordering) FROM Materials WHERE category_id='$curr_cat->id'");

		switch ($_GET['mode']) {

			case 'edit':
				$edit = true;
				$showform = true;
				break;

			case 'del':
				$response_msg = '';

				$curr_material = $db->get_row("SELECT * FROM Materials WHERE id='$_GET[id]'");
				$curr_cat = $db->get_row("SELECT * FROM Categories WHERE id='$_GET[cid]'");
		        $material_dir .= $curr_cat->folder;

				if ( unlink($material_dir . $curr_material->filename) ) {

					$db->query("DELETE FROM Materials WHERE id='$_GET[id]'");
					$db->query("UPDATE Materials SET ordering=ordering-1 WHERE category_id='$curr_cat->id' AND ordering > '$curr_material->ordering'");
					$response_title = 'File Deleted';

					$response_msg .= $add_msg;
					} //if()

				else {
					$response_title = 'Error';
					$response_msg = 'File not deleted.<br/>';
					$response_msg .= 'Please try again.<br/>';
					$response_msg .= $return_msg;
					} //else

				break;

[/php]

I can provide the full php page/code if needed.

Thanks for any help or insights you might have.

R.

R,
Please verify recent folder permission changes and possible PHP version changes. If nothing has changed there then lets dig into the code. Most of the time I find in these cases it is an update/upgrade that changed something simple rather than a code changing spontaneously and breaking the system. You may also want to look at recent database permission changes that could effect this code.

Thank you so much Andrew. Any insights are much appreciated.

I did wonder about the permissions on the folder that the pages/script is in and did try to set them. What chmod settings should I use? read/write/execute for all?

It is on a shared server (at GoDaddy) so they could have upgraded to a newer php version. I believe it was written for php4. How do I check for this, on my end or theirs, and what adjustments might be needed?

As for the database, I doubt there have been any permissions changes made to it but what do I need to check for there?

I can send or post the actual pages if needed and provide details on db settings, etc. Whatever you need…

Thanks again for your help,

Russell

if you have access to shell prompt which godaddy will allow just type php -v at the shell command other wise create a php info file and it should tell you you could always look in your webhosting account settings for the answer as well I am sure it says somewhere in there.

My best guess at this point is GoDaddy upgraded your php to version 5 which broke your scripts.

Sounds possible and likely.

However, all other aspects of the script work such as ‘add/upload a file’, ‘re-order files’, etc. Is it possible that just the ability to delete a record/file from the DB is affected?

Thanks,

R.

Yes that is possible however a version change in PHP should not effect your query wording. That is why I suggested a check of your database permissions.

My favorite syntax checker did not find any issue with your code for 4 or 5

what should the db permissions be set to?

Your php version is PHP Version 5.2.17 for the user that accesses that file they will need drop permissions on the database I will have to look into the command line interface but if you use godaddy’s phpmyadmin tool you should just see a drop check box in the edit privileges section of the database

I am logged into phpmyadmin and I see the database which has two tables… I see an ‘x’ icon that says ‘drop’ on each table’s row. Is this what I should select for each table, or does that drop that table from the DB?

If I select one of the tables a ‘Drop’ tab/icon appears at the top.

Please excuse my limited knowledge of where the privileges function is.

Thanks,

R.

OK first, It is not necessary to send me a message every time you post here just reply to the post so everyone can benefit from our conversation. Second this image should help you find he privileges tab for your database http://www.infosolutionsgoa.com/tutor/img3/mysql-privileges.gif

Understood.

I think the issue is that I don’t see, or can’t seem to get to, an overall ‘localhost’ screen.

From my hosting control panel, I have the option to choose which database I want to work with (of 4 that have been created). When I click on the relevant DB name that link opens phpMyadmin for that DB. In that interface of phpMyAdmin there isn’t a tab called ‘privliages’ to the right of the ‘Engines’ tab.

Is it possible to access just the overall localhost interface directly?

No, Let me login to my godaddy account and I will find the correct setting page.

After looking at godaddy’s phpmyadmin tool and their database options I cannot find a privileges section to edit individual user privileges. except in the actual table which is not very user friendly. it may be time to call godaddy and ask if there were any changes to your server recently. which may point us in the right direction. ask them about php updates or mysql updates.

Ok. Since we only have two tables can I just edit privileges for those, even if it isn’t user friendly?

We’ve had this issue for some time so any changes they might have made would have been long ago.

Thanks,

Russ

The issue is I am not sure if your user will have privileges to grant privileges thats just it. but you can try it here are the instructions via command line http://www.ntchosting.com/mysql/grant.html you will also want to remember what they were before hand so you can put them back.

Since we just have two tables, can we set those privileges directly, even if it’s not user friendly?

Thanks

please excuse the double-post about the two tables. I’ll look into the link you sent in more detail. I’m not familiar with SSH and command line stuff so I’m not sure how that will work out but I’ll give it a shot. Is there any way to do it via phpMyAdmin. I assume the chmod settings aren’t an issue?

Thanks again for the great help and insights.

Russ

in the structure table there is a user_privileges table and you may be able to edit those fields to grant you privileges i am not sure how to do this I do not edit privileges this way.

Sponsor our Newsletter | Privacy Policy | Terms of Service