• Advertisement
Sign in to follow this  

[web] Problem with running a MySQL query in PHP

This topic is 3496 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright. I am trying to get a query to run on the website I am developing. THis is the last thing I need to do and I will be done. I have an update query in my page that will not run. Here is the code it belongs to:
chdir("../");
newName = getcwd()."/".$_FILES['downloadPolicy']['name'];
if(move_uploaded_file($_FILES['downloadPolicy']['tmp_name'],$newName))
{
	$fileName = $_FILES['downloadPolicy']['name'];
	$policy = mysql_real_escape_string($_POST['policy']);
	$deposit = mysql_real_escape_string($_POST['deposit']);
			
	require('includes.php');
	$db = mysql_pconnect($dbhost,$dbuser,$dbpass);
	mysql_select_db($dbname);
	$query = "update rentalPolicy set policy = '{$policy}', depositAmount = {$deposit}, downloadPolicy = '{$fileName}'";
	$result = mysql_query($query);
	if($result)
	{
		$message = "Rental Policy Updated";
	}
	else
	{
		$message = "Rental Policy failed to Update";
	}
includes.php has all the connection variables. They are all correct. I have checked the values of the three variables in the query. They all have a value. I have echoed out the final $query and ran that in the MySQL client and it works. Despite all that, every time I run the query through the page, it always errors out somehow and I get the "Rental Policy failed to Update" message. All the other update queries on my website work. It is only this one that is erroring out. Can anyone see what is wrong here?

Share this post


Link to post
Share on other sites
Advertisement
Never mind. I figured it out.

I was using the chdir() function to change the default directory so I could save the uploaded file. I forgot to change the default directory back. Without changing it back, I was using the wrong includes.php file and was not using the right user and permissions for the database.

I feel stupid, yet relieved.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement