0

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.

4
Contributors
3
Replies
28
Views
2 Years
Discussion Span
Last Post by diafol
-2

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>

Edited by diafol: reformatted code

Votes + Comments
Do not hijack somebody else's thread
0

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?

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.