Jump to content

Recommended Posts

Okay the people that come here have been amazing. I have another issue though. I think I've learned a lot and got this almost working, but I"m getting the "500 Internal Server Error" with it.

I'm trying to add an image upload directory and etc etc. I have the field added "photo" in the database at the end. Everything was working till I added the image upload. Here is what I have...

*Note* I have the folder to store the image permissions set to 777

 

My HTML page with the form is:

<html>
<head>
<title>Band Review Entry</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<b><font face="Verdana, Arial, Helvetica, sans-serif">BAND REVIEW </font></b> 
<form action="connectionband.php" method="post" enctype="multipart/form-data" />
  <p><font face="Verdana, Arial, Helvetica, sans-serif"><b>Name</b></font>: <br>
    <input type="text" name="Name" />
  </p>
  <p><font face="Verdana, Arial, Helvetica, sans-serif"><b>Link</b></font>: <br>
    <input type="text" name="website" />
  </p>
  <p><b><font face="Verdana, Arial, Helvetica, sans-serif">Description</font></b>: 
    <br>
    <textarea name="Description" cols="100" rows="25"></textarea>
  </p>
  <p><font face="Verdana, Arial, Helvetica, sans-serif"><b>Photo:</b></font> 
    <input type="hidden" name="size" value="350000">
            <input type="file" name="photo"> 
  </p>
  <p>
    <input type="submit" value="SEND IT" />
  </p>
</form>




</body>
</html>





And my PHP page to get the info and send etc, is:

<?php

// Connects to your Database info here


//This is the directory where images will be saved
$target = "http://www.inthisreview.com/bandsreview/bandimages/";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form
$Name=$_POST['Name'];
$website=$_POST['website'];
$Description=$_POST['Description'];
$timestamp=$_POST['timestamp'];
$photo = mysql_real_escape_string(htmlspecialchars($_FILES['photo']['name']));



//Writes the information to the database
mysql_query("INSERT INTO band (Name,website,Description,timestamp,photo)
VALUES ('$Name', '$website', '$Description', '$timestamp','$photo') ;

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
Link to comment
https://forums.phpfreaks.com/topic/285481-php-mysql-form-with-upload-issue/
Share on other sites

I'm not sure if it's just a problem with copying and pasting your code here, but can you see in your PHP, the highlighting isn't working correctly.. That is because you've missed a closing double quote and ending bracket..

 

Look at your mysql_query(...... line, and find where you're missing the required characters.

 

Denno

Edited by denno020

the 500 server errors you have been getting (this and the last thread) are due to php fatal parse or runtime errors (there's no complete response back from the server.)

 

you can get php to help you find what is causing the error by setting php's error_reporting setting to E_ALL and display_errors to ON in your php,ini file.

I updated but still getting the same error... here is the update.

Mac_Gyver... thanks for the tip, but I don't know how to do that or where the php.ini file is?

<?php

// Connects to your Database
 mysql_connect("website", "user", "pass") or die(mysql_error()) ; 
 mysql_select_db("bands") or die(mysql_error()) ; 


//This is the directory where images will be saved
$target = "http://www.inthisreview.com/bandsreview/bandimages/";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form
$Name=$_POST['Name'];
$website=$_POST['website'];
$Description=$_POST['Description'];
$timestamp=$_POST['timestamp'];
$photo = mysql_real_escape_string(htmlspecialchars($_FILES['photo']['name']));



//Writes the information to the database
mysql_query("INSERT INTO band (Name,website,Description,timestamp,photo)");
VALUES ('$Name', '$website', '$Description', '$timestamp','$photo') ;

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file " . basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
Edited by daniel28138

This is wrong

//Writes the information to the database
mysql_query("INSERT INTO band (Name,website,Description,timestamp,photo)")
VALUES ('$Name', '$website', '$Description', '$timestamp','$photo') ;

This is right

//Writes the information to the database
mysql_query("INSERT INTO band (Name,website,Description,timestamp,photo)
VALUES ('$Name', '$website', '$Description', '$timestamp','$photo')") ;

You'll notice that you put the double quote and bracket in the wrong place...

Edited by denno020

Hmmm Thanks for the correction. Yes I see what you meant. But I'm still getting the error. Here is the whole thing I have now...
 

<?php

// Connects to your Database
 mysql_connect("site", "user", "pass") or die(mysql_error()) ; 
 mysql_select_db("bands") or die(mysql_error()) ; 


//This is the directory where images will be saved
$target = "http://www.inthisreview.com/bandsreview/bandimages/";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form
$Name=$_POST['Name'];
$website=$_POST['website'];
$Description=$_POST['Description'];
$timestamp=$_POST['timestamp'];
$photo = mysql_real_escape_string(htmlspecialchars($_FILES['photo']['name']));



//Writes the information to the database
mysql_query("INSERT INTO band (Name,website,Description,timestamp,photo)
VALUES ('$Name', '$website', '$Description', '$timestamp','$photo')") ;



//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file " . basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>

Wow I really suck at this. I must have put that line all over my page and I'm just getting the 500 error. I think maybe it's time to admit defeat :/ I suppose not everyone is cut out to understand this. Does anyone know where there is this same thing that I have that actually works, that I can use? I've already been at this one page for a week every day and night.

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.