Hi
I tried placing the six lines bellow where they are in the code posted with this reply.
The redirect worked but not data was added to the database.
I tried placing the six line after the line $stmt->close();
now the data is added to the database but the redirect no longer works.
Six lines -
$def_soft_id = 1;
$def_id = 9876;
$soft_id = isset($GET['software_id']) ? $GET['software_id'] : $def_soft_id;
$id = isset($GET['id']) ? $GET['id'] : $def_id;
$id . '&software_id=' . $soft_id);
$action = 'comment_confirm.php?id=' . $id . '&software_id=' . $_soft_id;
try {
$pdo = new PDO("mysql:host=$hostname;dbname=abonline_tutor", $username, $password);
}catch (PDOExeption $e){
echo $e->getMessage();
}
$_def_soft_id = 1;
$_def_id = 9876;
$_soft_id = isset($_GET['software_id']) ? $_GET['software_id'] : $_def_soft_id;
$_id = isset($_GET['id']) ? $_GET['id'] : $_def_id;
$_id . '&software_id=' . $_soft_id);
$_action = 'comment_confirm.php?id=' . $_id . '&software_id=' . $_soft_id;
if(isset($_POST['submit'])) {
$mysql = new mysqli('localhost','abonline_aetutor','g}[m(8l+bq26','abonline_tutor') or die('There was a problem connecting to the database');
if($stmt = $mysql->prepare('INSERT INTO guest(name, email, comment, software_id) VALUES (?,?,?,?)')) {
$stmt->bind_param('sssi',$_POST['name'],$_POST['email'],$_POST['comment'],$_POST['software_id']);
$stmt->execute();
$stmt->close();
} else {
echo 'error: ' . $mysql->error;
}
}
$dbh = $pdo->prepare("SELECT `date`, `name`, `email`, `comment`, `software_id` FROM `guest` WHERE `software_id` = ? ORDER BY `date` DESC");
$dbh->bindValue(1, $_GET['software_id'], PDO::PARAM_INT); // assuming it's an integer
$dbh->execute();
$dbh->setFetchMode(PDO::FETCH_ASSOC);
while($row = $dbh->fetch()) {echo '<table width="100%" cellspacing="0" cellpadding="3" class="tablebg">
<tr class="formlabels">
<td align="left" class="tl" width="40%">Author: '.$row['name'].'</td>
<td width="45%" align="left">Date: '.$row['date'].'</td>
<td width="15%" align="center" class="tr"><a href="mailto:'.$row['email'].'">Email Author</a></td>
</tr>
<tr class="formlabels">
<td colspan="4" class="bl">'.$row['comment'].'</td>
</tr>
</table>';
}
?>
<html>
<head>
<link rel="stylesheet" href="styles.css" type="text/css" media="screen" />
</head>
<body>
<?php //echo $_action; ?>
<hr />
<form method="POST" action="<?php echo $_action; ?>">
<table>
<input type="hidden" name="id" value="<?php echo $_GET['id'];?>"/>
<br/>
<input type="hidden" name="software_id" value="<?php echo $_GET['software_id'];?>"/>
<tr><td>Name:</td></tr>
<tr>
<td> <input name="name" type="text" value="" size="45" /></td></tr>
<tr><td>Email:</td></tr>
<tr><td><input type="text" name="email" value="" size="45" /></td></tr>
<tr><td>Comment:</td></tr>
<tr><td><textarea cols="80" rows="6" name="comment" value="" ></textarea></td></tr>
<tr><td><input type="submit" name="submit" value="Add Comment" /></td><td> </td></tr>
</table>
</form>
<br />
<br />
<?php //var_dump($_GET); exit; ?>
</body>
</html>
comment_confirm.php code
if(isset($_POST['submit'])){
$url = 'fulltitle.php?' . http_build_query($_POST) ;
header('Location: ' . $url);
//exit;
}