Forum Moderators: coopster
Query was empty
Any suggestion?
<?php
session_start();
if(!isset($_SESSION['loggedin'])) {
// If the session 'loggedin' is NOT set forward the user back to the login form with the error set
header('Location: login.php');
exit(); // Otherwise show the rest of the page (admin section)
}
$connection = mysql_connect("localhost", "root", "") or die("Cannot connect to MySQL server: " . mysql_error());
$db_selected = mysql_select_db('tmetrix', $connection);
$problem = $_POST['problem'];
$solution = $_POST['solution'];
$comments = ($_POST['comments']);
//$user = $_COOKIE['Joe2Torials']['username'];
$rf = ($_POST['rfass']);
$id = $_GET['commentid'];
echo "$problem";
echo "$solution";
echo "$comments";
echo "$rf";
echo "$id";
//This code runs if the form has been submitted
if (isset($_POST['Submit']))
$query = "UPDATE comments SET problem=$problem, solution=$solution, comments=$comments, rf=$rf where c_id=$id" ;
mysql_query($query) or die(mysql_error());
mysql_close();
echo nl2br("Your comments have been sucessfully updated. Thank you\n You can close this window now.");
?> [/php]
Eg.
if (isset($_POST['Submit']))
$query = "UPDATE comments SET problem=$problem, solution=$solution, comments=$comments, rf=$rf where c_id=$id" ;
mysql_query($query) or die(mysql_error());
mysql_close();
Is the same as
if (isset($_POST['Submit']))
{
$query = "UPDATE comments SET problem=$problem, solution=$solution, comments=$comments, rf=$rf where c_id=$id" ;
}
mysql_query($query) or die(mysql_error());
mysql_close();
So the way you have it mysql_query will always be run, even if $_POST['submit'] isn't set.