I am having two problems dealing with images.
I am trying to make an uploader for the user to post picture of a meal or food item. I have the uploader to show and the browser open but it does not go to my databasebase name "recipe" to the table "recipes" into the column "picture". This is how I know the uploader is not working. But if I put pictures into the database in the "picture" column it will display on the correct webpage associate with the "recipeid".

Can someone help me with this problem. I have place the file that is associate with it.

filename: newrecipe

<?php
if (!isset($_SESSION['valid_recipe_user']))
{
   echo "<h2>Sorry, you do not have permission to post recipes</h2>\n";
   echo "<a href=\"index.php?content=login.inc.php\">Please login to post recipes</a>\n";
} else
{
   $userid = $_SESSION['valid_recipe_user'];
   echo "<form enctype=\"multipart/form-data\" action=\"index.php\" method=\"post\">\n";
   echo "<h2>Enter your new recipe</h2><br>\n";
   echo "<h3>Title:</h3><input type=\"text\" size=\"40\" name=\"title\"><br>\n";
   echo "<h3>Short Description:</h3><textarea rows=\"5\" cols=\"50\" name=\"shortdesc\"></textarea>\n";
   echo "<h3>Ingredients (one item per line)</h3>\n";
   echo "<textarea rows=\"10\" cols=\"50\" name=\"ingredients\"></textarea><br>\n";
   echo "<h3>Directions</h3>\n";
   echo "<textarea rows=\"10\" cols=\"50\" name=\"directions\"></textarea><br>\n";
   echo "<h3>Calories</h3>\n";
   echo "<input type=\"text\" size=\"10\" name=\"calories\"><br>\n";
   echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"100000\" /><br>\n";
   echo "If you took a picture upload it here: <input name=\"picture\" type=\"file\" /><br>\n";

   echo "<p></p>";
   
   echo "<input type=\"submit\" value=\"Submit\">\n";

   echo "<input type=\"hidden\" name=\"poster\" value=\"$userid\"><br>\n";
   echo "<input type=\"hidden\" name=\"content\" value=\"addrecipe\">\n";
   echo "</form>\n";
}

filename: addrecipe.inc.php

//in this file it say that thumbnail is undefined and continue giving me error. I know I need this code so that the image can show, atleast that is what I think. Other than the thumbnail problem everything else work when I remove all the thumbnail codes//

<?php
$title = $_POST['title'];
$poster = $_POST['poster'];
$shortdesc = $_POST['shortdesc'];
$ingredients = htmlspecialchars($_POST['ingredients']);
$directions = htmlspecialchars($_POST['directions']);
$calories= htmlspecialchars($_POST['calories']);
$picture= $_POST['thumbnail'];

if (trim($poster == ''))
{
    echo "<h2>Sorry, each recipe must have a poster</h2>\n";
}else
{
    $con = mysql_connect("localhost", "test", "test") or die('Could not connect to server');
    mysql_select_db("recipe", $con) or die('Could not connect to database');
$thumbnail = getThumb($_FILES['picture']);
   $thumbnail = mysql_real_escape_string($thumbnail);
	
    $query = "INSERT INTO recipes (title, shortdesc, poster, ingredients, directions, calories, picture) " .
          " VALUES ('$title', '$shortdesc', '$poster', '$ingredients', '$directions', '$calories', '$thumbnail')";

    $result = mysql_query($query) or die('Sorry, we could not post your recipe to the database at this time');

    if ($result)
       echo "<h2>Recipe posted</h2>\n";
    else
       echo "<h2>Sorry, there was a problem posting your recipe</h2>\n";
}
?>

Hi,
I changed your coding something like this. It is now easy to verify. Dont mingle html in echo. Also when you are getting anything from session means, you have start the session at the top of the page, in both the page, where you are setting sessions and in retrieving that sessions.

<?php
	session_start();
if (!isset($_SESSION['valid_recipe_user']))
{
	?>
	<h2>Sorry, you do not have permission to post recipes</h2>
	<a href="index.php?content=login.inc.php">Please login to post recipes</a>
	<?PHP
}
else
{
	$userid = $_SESSION['valid_recipe_user'];
	?>
	<form enctype="multipart/form-data" action="index.php" method="post">
	<h2>Enter your new recipe</h2><br>
	<h3>Title:</h3><input type="text" size="40" name="title"><br>
	<h3>Short Description:</h3><textarea rows="5" cols="50" name="shortdesc"></textarea>
	<h3>Ingredients (one item per line)</h3>
	<textarea rows="10" cols="50" name="ingredients"></textarea><br>
	<h3>Directions</h3>
	<textarea rows="10" cols="50" name="directions"></textarea><br>
	<h3>Calories</h3>
	<input type="text" size="10" name="calories"><br>
	<input type="hidden" name="MAX_FILE_SIZE" value="100000" /><br>
	If you took a picture upload it here: <input name="picture" type="file" /><br>
	<p></p>
	<input type="submit" value="Submit">
	<input type="hidden" name="poster" value="<?PHP echo($userid); ?>"><br>
	<input type="hidden" name="content" value="addrecipe">
	</form>
<?PHP
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.