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.

error_reporting(E_ALL); 
ini_set('display_errors', 1);
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$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();
     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $sql = "UPDATE meals set name = ?, image = ?, image_big = ?, description = ? WHERE id = ?";
     $q = $pdo->prepare($sql);
     $q->execute(array($name,$image,$image_big,$description,$id));
     Database::disconnect();
     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 ?

<!DOCTYPE HTML>
<html>
<body>
<p>Redirecting...</p>
<?php
session_start();
$user=$_POST['uname'];
$_SESSION['username']=$user;
$con=mysql_connect("localhost","root","nano");
mysql_select_db("airline")or die("Db error");

$username=$_POST['uname'];
$password=$_POST['ptxt'];

$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');
?>
</body>
</html>
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 for diafol

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, networking, learning, and sharing knowledge.