Currently I have form with couple of fields and field for image. I have done with the part of field storing but don't know exactly how to store image path with PDO and can't find good tutorial. All I found was how to store image into DB instead of path. This is my code so far.

ini_set('display_errors', 1);
$pdo = Database::connect();
$id = null;
if ( !empty($_GET['id'])) 
     $id = $_REQUEST['id'];
if ( null==$id ) 
     echo "null==$id";

// keep track post values
     $name = $_POST['name'];
     $image = $_POST['image'];
     $image_big = $_POST['image_big'];
     $description = $_POST['description'];

     // update data
     $pdo = Database::connect();
     $sql = "UPDATE meals set name = ?, image = ?, image_big = ?, description = ? WHERE id = ?";
     $q = $pdo->prepare($sql);
     echo "<code>Saved!</code>";

There is no problems with saving 'name' and 'description' fields.

Recommended Answers

All 3 Replies

I can't redirect to admin/user page, help me ?

mysql_select_db("airline")or die("Db error");


$query = mysql_query("select * from user where password='$password' AND name='$username'");
if($username=="" && $password=="")header('location:admin.php');
else if($username=="hijran" && $password=="khan")header('refresh:5; user.php');
else header('location:error.php');
commented: Do not hijack somebody else's thread -3

Hijran, you can't send the redirect header when you've already outputted text to the page. And create a new thread next time instead of hijacking someone elses.

Jason, I'm uncertain what you're having trouble with. Store the image path as a string in the database. Are you having trouble getting the path of the image?

Member Avatar

Never use $_REQUEST. WHy didn't you just stick to $_GET?

You're creating the pdo object twice in this code. Why?

Assuming that the Database object has the correct connection details to hand.

Be a part of the DaniWeb community

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