Jump to content

No clue


daveygz
Go to solution Solved by daveygz,

Recommended Posts

Hi All, This is my first post and I am not super good at coding with php so if this seems a bit "simple or "stupid" my apologies.
I have this code (which works and will upload a photo and add info to the database) that I had finally gotten to work well. I edited it to upload a photo, a title and paypal button code. I have tried everything I can think of to make this code work and it's just not. It gives errors like this.

Warning: move_uploaded_file(uploads/Decal.jpg): failed to open stream: No such file or directory in /home/website/public_html/paypal/paypal-add.php on line 15

Warning: move_uploaded_file(): Unable to move '/tmp/phpjVp2F8' to 'uploads/Decal.jpg' in /home/website/public_html/paypal/paypal-add.php on line 15

I am not sure why this exact code works to upload a file in another section of the site, but the code below always bombs. I did get it to work once, when I placed a php script at the top to display all the php settings of the web server. (No clue why) I am hoping someone out there will see that I have done wrong here and why this won't function. There is an uploads folder in the same folder as this code. The setting on the database are accurate to the variable in the code. The settings are also accurate. Any thoughts would be appreciated.

The code.
 

<?php 
include 'settings.php'; 
 // Initialize DBase
			$con = mysqli_connect("$dbHost","$dbUsername","$dbPassword")or die('Could not connect: ' . mysqli_connect_error());
			mysqli_select_db($con,"$dbName")or die("Cannot select the database.");	
// Set Variables
				$fileName = $_FILES['fileName']['name']; $statusMsg = '';
                $product_name = $_POST['product_name'];
                $paypal_code = $_POST['paypal_code'];
				$PathName = "uploads/"; 		
// Copy Image File To Directory And Write the information to the database
            $Success = move_uploaded_file($_FILES['fileName']
            ['tmp_name'],$PathName.$fileName);
			if($Success)
				{
				$sql="INSERT INTO $table (fileName, product_name, paypal_code) VALUES ('$fileName','$product_name','$paypal_code')";
					
                if(!mysqli_query($con,$sql)) {$statusMsg = 'There was an error saving the sample.';} 
					else {header("Location: paypal-list.php");}
				}
			else {$statusMsg = 'There was an error saving the sample.';}
			mysqli_close($con); echo $statusMsg; exit;
?>

Thanks

Edited by daveygz
Link to comment
Share on other sites

Have you echoed out the contents of the move command to see what you are trying to do?  And as I haven't done one of these in a bit, aren't you supposed to be moving a 'tmpname'?

Oops - upon re-reading the broken display of the move line I see tmpname is being referenced.  So I would want to see the contents of that move line to be sure the names you expect to be there are truly there.

Edited by ginerjm
Correction
Link to comment
Share on other sites

  • 2 weeks later...
  • Solution

Hi Guys,

 

Thanks for the suggestions! Totally appreciated.  The solution was the oddest thing. I am not sure if the page itself needed to be designated as a php or something, but when I added this bit of code to the very top of the code to check errors, it submitted perfectly; added the image and wrote all the info to the database.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>

As I just wanted to see what errors I was getting this was a total surprise. I appreciate all the help however! Thanks Guys!!

Edited by daveygz
Link to comment
Share on other sites

On 5/25/2023 at 8:41 AM, ginerjm said:

you did something else as well.  Enabling error checking didn't solve your problems.  It would only tell you what coding mistakes you had.  And stop using the ?> line. You don't need to do that all the time.

@ginerjm makes a good point here.  Omit the ending tag in all your scripts, unless you are going in and out of php mode.   Even if you are doing that, you still never need a php end tag "?>" at the bottom of your script.  Having one can lead to hard to debug errors, particularly when you are include/require scripts which you did in your code with your "settings.php" script.  

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.