Hey,
This is a form I use to add information to a database, and upload an image to images/ ... Im trying to get the INSERT statement to get the name of the newly uploaded picture and save it as 'picture' field in the table...

At the moment I fill in all the fields, click "Submit" and it doesnt show any errors or a success display, it just shows the form again, blank.

Thanks alot, will be so thankful if someone can help me out here

<?
	} elseif( $_GET["action"] == "add2" ){

echo"<form name=\"newad\" method=\"post\" enctype=\"multipart/form-data\"  action=\"?action=add2\">
<table width=\"\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
      <td width=\"11%\">Name:</td>
    <td width=\"89%\"><INPUT TYPE=\"TEXT\" NAME=\"name\" SIZE=36></td>
  </tr>
  <tr>
      <td>Beach Image:</td>
    <td><input type=\"file\" name=\"image\" SIZE=\"36\"></td>
  </tr>
  <tr>
      <td>Rating:</td>
    <td><INPUT TYPE=\"TEXT\" NAME=\"rating\" SIZE=36></td>
  </tr>
  <tr>
      <td>Short Desc:</td>
    <td><TEXTAREA NAME=\"sdesc\" ROWS=10 COLS=30></TEXTAREA></td>
  </tr>
  <tr>
      <td>Long Desc:</td>
    <td><TEXTAREA NAME=\"ldesc\" ROWS=10 COLS=30></TEXTAREA></td>
  </tr>
    <tr>
      <td>Ocean:</td>
    <td><INPUT TYPE=\"TEXT\" NAME=\"ocean\" SIZE=36></td>
  </tr>
    <tr>
      <td>Surfing Info:</td>
    <td><INPUT TYPE=\"TEXT\" NAME=\"surfing\" SIZE=36></td>
  </tr>
    <tr>
      <td>Directions:</td>
    <td><INPUT TYPE=\"TEXT\" NAME=\"directions\" SIZE=36></td>
  </tr>
</table>
      <input type=\"submit\" value=\"Add Beach\" />
 </form>";

  define ("MAX_SIZE","10000"); 

 function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
 }
 $errors=0;

 if(isset($_POST['Submit'])) 
 {
 	$image=$_FILES['image']['name'];
 	if ($image) 
 	{
 		$filename = stripslashes($_FILES['image']['name']);
  		$extension = getExtension($filename);
 		$extension = strtolower($extension);
 if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
 		{
 			echo '<h1>Unknown extension!</h1>';
 			$errors=1;
 		}
 		else
 		{
 $size=filesize($_FILES['image']['tmp_name']);


if ($size > MAX_SIZE*1024)
{
	echo 'You have exceeded the size limit!';
	$errors=1;
}


$image_name=time().'.'.$extension;

$newname="images/".$image_name;

$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied) 
{
	echo 'Copy unsuccessfull!';
	$errors=1;
}}}}

 if(isset($_POST['Submit']) && !$errors) 
 {
$picins = "$newname";
	$sql="INSERT INTO beaches (picture, rating, name, sdesc, ldesc, ocean, surfing, directions) VALUES ('$picins','$_GET[rating]','$_GET[name]', '$_GET[sdesc]', '$_GET[ldesc]', '$_GET[ocean]', '$_GET[surfing]', '$_GET[directions]')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "Beach Added - Check to see if it is valid!";
 	echo "Beach Image Uploaded Successfully!";
echo "$picins";
 }


?>

    I skimmed through your code and noticed this right away. You are using $_POST['Submit'] in an if statement, but your submit button doesn't have a name. You need to name your submit button "Submit" in order for this to check out.

    A method I sometimes use to debug if statements is to print something within them, then when the page loads I can see which statements are evaluating.

    Also, check your SQL by printing the $sql variable holding the query string if the other suggestions don't resolve the issue for you.

      cgraz wrote:

      I skimmed through your code and noticed this right away. You are using $_POST['Submit'] in an if statement, but your submit button doesn't have a name. You need to name your submit button "Submit" in order for this to check out.

      Some browser doesn't pass the name on if you use enter instead of clicking the button. A way to get the same result is to include a hidden field and check against that instead.

        Piranha wrote:

        A way to get the same result is to include a hidden field and check against that instead.

        Or check for the existence of the field that you're actually wanting to use.

          thanks so much for the response, but it still wont work..

          Tried clicking instead of enter, and tried changing from GET to POST and it doesnt bring up an error/confirmation...

            You don't appear to have included the triggering variable 'Submit' within the content of the form.

            Where is this line?
            <input type=hidden name=Submit value=true>

              Write a Reply...