2

I am redirecting from here

<a href="update_post.php?updid=<?php echo $_SESSION['id']; ?>">Update</a>

and code which shows error is

<?php include('../includes/connections.php'); ?>
<?php
try{
if(isset($_POST['submit'])){
$title = $_POST['title'];
$post = $_POST['post'];
$dates = $_POST['date'];
$sql = 'UPDATE `blog`.`contents` SET `titles` = :title, `posts` = :post, `dates` = :date    WHERE `contents`.`id` = :idendity';
$result = $pdo->prepare($sql);
$result->bindValue(':title',$title);
$result->bindValue(':post',$post);
$result->bindValue(':date',$dates);
$result->bindValue(':idendity',$_GET['updid']);
$result->execute();
$count = $result->rowCount();
    if($count == 1){
        header('location: index.php');
    }else{
        echo 'Problem Occoured';
    }
}
}
catch(PDOException $e){
echo "Problem: " .$e->getMessage();
}
?>

error which is shown:-Notice: Undefined index: updid in C:\xampp\htdocs\myblog\admin\update_post.php on line 13 Problem Occoured

<form action="update_post.php" method="post">
    Title:<br/>
    <input style="height:40px;" size="110" type="text" name="title" /><br />
    Post:<br />
    <textarea rows="30" cols="85"  name="post" ></textarea><br />
    Date:<br />
    <input type="text" name="date" /><br/ >
    <input type="submit" name="submit" />
</form>
Shashi
  • 474
  • 6
  • 21

1 Answers1

1

yes by form submission and that is the reason i am checking for if submit isset or not.

You should include $_SESSION['id'] in a hidden field in the form:

<input type="hidden" name="updid" value="<?php echo $_SESSION['id']; ?>" />

... and change:

$result->bindValue(':idendity',$_GET['updid']);

... into:

$result->bindValue(':idendity',$_POST['updid']);

Edit

First of all, your question above has error. As mentioned in the comment, it's not possible that isset($_POST['submit']) will return true if you click on a link.

$_POST will have values when you access the page by submitting a form that has post in the method part.

As for $_GET, its values are taken from the query string of a URL:

http://yourpage.php?foo=bar&bar=foo

bar is the value of $_GET['foo']

foo is the value of $_GET['bar']

I've searched for basic $_POST/$_GET explanation but unable to find one :-D

rlatief
  • 715
  • 5
  • 14
  • Thanks alot this worked, can you please explain them why it is so , i am fairly new to PHP just practicing from 2 months. – Shashi Feb 03 '13 at 18:21
  • any links or material will be helpful – Shashi Feb 03 '13 at 18:23
  • Although isset($_POST['submit']) was not intended for link , it was for submit button in form. anyways i understood rest of the things you explained ,thanks – Shashi Feb 03 '13 at 18:42
  • @Shashi that would never happen unless you had a hidden element with `name=submit` – Amelia Feb 03 '13 at 18:45