0

I have 2 pages. One with my results from the msql database on one which has a update from and sql query on. i have made a button so that it gets the ID of that field when trying to update but when i enter information and submit nothing happens it just seems to refresh the page.

<?php

$db_host = '';
$db_user = '';
$db_pass = '';
$db_name = '';


$con = new mysqli($db_host, $db_user, $db_pass, $db_name);
  ?>
<html>
<form method="post" >
<input type="hidden" name="id" value="<?php echo $row['ID']?>">
<tr>        
  <td>Title</td>
<td>
<input type="text" name="title" size="20" value="<?php echo $row[title]?>">
</td>
</tr>
<tr>
  <td>Description</td>
<td>
<input type="text" name="description" size="40" value="<?php echo $row[description]?>">
</td></tr>
<tr>
<td align="right">
<input type="submit" name="submit" value="submit">
</td>
</tr>
</form>
</html>
<?php

if(isset($_POST["submit"])) {
$id = $_POST['id'];
$sql = "SELECT * FROM diary";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
if (isset($_POST[title])){
$title = mysql_real_escape_string(trim($_POST['title']));
}else{
$title = NULL;
}

if (isset($_POST[description])){
$description = mysql_real_escape_string(trim($_POST['description']));
}else{
$description = NULL;
}




$query = "UPDATE diary SET title='$title', post='$description' WHERE id= ?";           
 mysql_query($query);
if ($conn->query($sql) === TRUE) {
header("location: results.php");
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
?>

Any help would be greatly appriciated

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
  • 1
    You are having more than one error in your code. Add `error_reporting(E_ALL);ini_set('display_errors',1);` just after ` – Alive to die - Anant Mar 26 '16 at 15:54
  • You cannot mix `mysqli_*` functions with `mysql_*` functions. Use `mysqli_*` for all instead as `mysql_*` is already deprecated – Panda Mar 26 '16 at 15:55

0 Answers0