Forum Moderators: coopster

Message Too Old, No Replies

Update Problem

Unable to update MYSQL

         

shruti

7:52 pm on Aug 15, 2008 (gmt 0)

10+ Year Member



I am having problems updating my data:
Here is the code with which I am trying to:
Apart from what I have echoed, I get

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]

MattAU

9:58 pm on Aug 15, 2008 (gmt 0)

10+ Year Member



If you don't put squiggly brackets after an if statement then only the very next line is part of the "if'd" code.

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.

shruti

6:38 pm on Aug 18, 2008 (gmt 0)

10+ Year Member



Even after putting the curly brackets, it gives me QUERY WAS EMPTY

wheelie34

8:01 pm on Aug 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try echoing out the query to see if it's getting that far

$query = "UPDATE comments SET problem=$problem, solution=$solution, comments=$comments, rf=$rf where c_id=$id" ;
echo "$query";
mysql_query($query) or die(mysql_error());

See what you get HTH

shruti

8:08 pm on Aug 18, 2008 (gmt 0)

10+ Year Member



I got it...........thanks
it was a name mistake