Page 2 of 2

Re: Update MySQL DB from a form

Posted: Wed Jun 04, 2008 12:08 pm
by Cooperman
Hmmm,

It still doesn't work and if I take out the header page it just goes blank and says Done at the bottom in ie

Re: Update MySQL DB from a form

Posted: Wed Jun 04, 2008 12:10 pm
by comando
add one more line to it to see what the errors are

$myrow = $_POST['L_ID'];
mysql_query("UPDATE login SET level = 2 WHERE L_ID = $myrow ");

echo mysql_error();

Re: Update MySQL DB from a form

Posted: Wed Jun 04, 2008 12:15 pm
by Cooperman
Unknown column 'level' in 'field list'

Re: Update MySQL DB from a form

Posted: Wed Jun 04, 2008 12:17 pm
by comando
are you sure there is a level field in your database? as the error indicates that you don't have level field in your database..Check you database field again to see what the field name for level is

Re: Update MySQL DB from a form

Posted: Wed Jun 04, 2008 12:19 pm
by Cooperman
forget that last error, it should be "access" and not "level"

BUT, the page is still blank



$myrow = $_POST['L_ID'];
mysql_query("UPDATE login SET access = 2 WHERE L_ID = $myrow ");

echo mysql_error();

Re: Update MySQL DB from a form

Posted: Wed Jun 04, 2008 12:29 pm
by comando
man, thats stranged..lets try this .

$myrow = $_POST['L_ID'];
mysql_query("UPDATE login SET access = '2' WHERE L_ID = '".$myrow."'");

echo mysql_error();

Re: Update MySQL DB from a form

Posted: Wed Jun 04, 2008 12:32 pm
by Cooperman
HOLD THE PHONE,

I have found one thing out.

When I uploaded I was in the DB. I refreshed the DB and nothing happened. If I was out of the DB and used the code you provided and then went back into the DB, it had worked.

Why is that? I have made changes before and then refreshed and it normally works??? :?

Re: Update MySQL DB from a form

Posted: Wed Jun 04, 2008 12:37 pm
by comando
I think its because of the browser cache..but is it working now ?

Re: Update MySQL DB from a form

Posted: Wed Jun 04, 2008 12:38 pm
by Cooperman
Sure is :)

Many thanks for your support mate, it's appreciated.

I am an ASP guy and this php stuff is very different lol.

Cheers again.

Re: Update MySQL DB from a form

Posted: Wed Jun 04, 2008 12:59 pm
by RobertGonzalez
Is L_ID an integer type? Is access? If they are leave off the quotes around them. Also, make sure you check for a value and type in the posted item so you can save yourself a trip to the database if it is not what you expected.

Code: Select all

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  if (!empty($_POST['L_ID']) && is_numeric($_POST['L_ID'])) {
    // If you are only using this var once, don't assign it, just use the post var
    $myrow = $_POST['L_ID'];
    if (!mysql_query("UPDATE login SET access = 2 WHERE L_ID = $myrow")) {
      die('There was an error: ' . mysql_error()); // Do NOT use this in production
    }
  }
}
?>