Update page not working
Budget: €8 – €30 EUR
My update page seems not to be working. Note that some of the fields are left blank (not all records need all fields completed).
Current code:
<?php
include $_SERVER['DOCUMENT_ROOT']."/connecttodb.php";
session_start();
// If the user is not logged in redirect to the login page...
if (!isset($_SESSION['loggedin'])) {
header('Location: index.php');
exit;
}
if ($_SESSION['role'] == 'Admin'):
?>
// here comes header ///
<?php
echo '<pre>'; print_r($_POST); echo '</pre>';
if(isset($_POST['update']))
{
$hf_id = $_POST['hf_id'];
$hf_value1 = $_POST['hf_value1'];
$hf_value2 = $_POST['hf_value2'];
etc...
$sql = "UPDATE table SET
hf_value1 = :hf_value1,
hf_value2 = :hf_value2,
WHERE hf_id = :hf_id" ;
$stmt_result = $dbh->prepare($sql);
$stmt_result->bindparam(':hf_id',$hf_id);
$stmt_result->bindparam(':hf_value1',$hf_value1);
$stmt_result->bindparam(':hf_value2',$hf_value2);
$stmt_result->execute();
//OR this statement: $stmt_exec = $stmt_result->execute(array(':hf_id' => $hf_id,':hf_value1' => $hf_value1, ':hf_value2' => $hf_value2 ) );
if($stmt_result->execute())
{echo "Succes!"; } else {echo "\nPDO::errorInfo():\n";
print_r($dbh->errorInfo());}
}
else {echo 'Geen record met dit id';}
?>
<?php
$hf_id = $_GET['hf_id'];
$sql = "SELECT * FROM table WHERE hf_id = :hf_id";
$stmt = $dbh->prepare($sql);
$stmt->execute(array(':hf_id' => $hf_id));
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$hf_value1 = $row['hf_value1'];
$hf_value2 = $row['hf_value2'];
etc....
}
?>
<form method="post" action="">
<table style="margin:0;" class="table artikel-wijzigen">
<tbody>
<tr>
<td style="width:28%;">Nr:</td>
<td style="width:18%;" class="artikel-wijzigen-deel">
<input name="hf_value1" type="text" id="hf_value1" style="margin-right:70px;" value="<?php echo $hf_value1; ?>"></td>
<td style="width:28%;">  Public: </td>
<td style="width:18%;">
<input name="hf_value2" type="text" style="width:80px;" id="hf_value2" value="<?php echo $hf_value2; ?>">
</td>
</tr>
etc...
</tbody>
</table>
<input type="hidden" name="hf_id" value="<?php echo $hf_id;?>">
<input type="submit" name="update" class="extra_icon_save" value="Opslaan">
</form>
...some footer information...
<?php endif;
// end of admin rights
?>
NOTE: one field is an textarea, where I use TinyMCE for text editing.
As far as I'm concerned, the database user has the correct rights (because the INSERT is working perfectly).
Whenever I try to update, I get this error:
Array ( [0] => 00000 [1] => [2] => )
Current code:
<?php
include $_SERVER['DOCUMENT_ROOT']."/connecttodb.php";
session_start();
// If the user is not logged in redirect to the login page...
if (!isset($_SESSION['loggedin'])) {
header('Location: index.php');
exit;
}
if ($_SESSION['role'] == 'Admin'):
?>
// here comes header ///
<?php
echo '<pre>'; print_r($_POST); echo '</pre>';
if(isset($_POST['update']))
{
$hf_id = $_POST['hf_id'];
$hf_value1 = $_POST['hf_value1'];
$hf_value2 = $_POST['hf_value2'];
etc...
$sql = "UPDATE table SET
hf_value1 = :hf_value1,
hf_value2 = :hf_value2,
WHERE hf_id = :hf_id" ;
$stmt_result = $dbh->prepare($sql);
$stmt_result->bindparam(':hf_id',$hf_id);
$stmt_result->bindparam(':hf_value1',$hf_value1);
$stmt_result->bindparam(':hf_value2',$hf_value2);
$stmt_result->execute();
//OR this statement: $stmt_exec = $stmt_result->execute(array(':hf_id' => $hf_id,':hf_value1' => $hf_value1, ':hf_value2' => $hf_value2 ) );
if($stmt_result->execute())
{echo "Succes!"; } else {echo "\nPDO::errorInfo():\n";
print_r($dbh->errorInfo());}
}
else {echo 'Geen record met dit id';}
?>
<?php
$hf_id = $_GET['hf_id'];
$sql = "SELECT * FROM table WHERE hf_id = :hf_id";
$stmt = $dbh->prepare($sql);
$stmt->execute(array(':hf_id' => $hf_id));
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$hf_value1 = $row['hf_value1'];
$hf_value2 = $row['hf_value2'];
etc....
}
?>
<form method="post" action="">
<table style="margin:0;" class="table artikel-wijzigen">
<tbody>
<tr>
<td style="width:28%;">Nr:</td>
<td style="width:18%;" class="artikel-wijzigen-deel">
<input name="hf_value1" type="text" id="hf_value1" style="margin-right:70px;" value="<?php echo $hf_value1; ?>"></td>
<td style="width:28%;">  Public: </td>
<td style="width:18%;">
<input name="hf_value2" type="text" style="width:80px;" id="hf_value2" value="<?php echo $hf_value2; ?>">
</td>
</tr>
etc...
</tbody>
</table>
<input type="hidden" name="hf_id" value="<?php echo $hf_id;?>">
<input type="submit" name="update" class="extra_icon_save" value="Opslaan">
</form>
...some footer information...
<?php endif;
// end of admin rights
?>
NOTE: one field is an textarea, where I use TinyMCE for text editing.
As far as I'm concerned, the database user has the correct rights (because the INSERT is working perfectly).
Whenever I try to update, I get this error:
Array ( [0] => 00000 [1] => [2] => )