Update MySQL DB from a form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Cooperman
Forum Commoner
Posts: 27
Joined: Mon Jun 02, 2008 4:44 am

Re: Update MySQL DB from a form

Post 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
comando
Forum Newbie
Posts: 11
Joined: Wed Jun 04, 2008 11:18 am

Re: Update MySQL DB from a form

Post 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();
Cooperman
Forum Commoner
Posts: 27
Joined: Mon Jun 02, 2008 4:44 am

Re: Update MySQL DB from a form

Post by Cooperman »

Unknown column 'level' in 'field list'
comando
Forum Newbie
Posts: 11
Joined: Wed Jun 04, 2008 11:18 am

Re: Update MySQL DB from a form

Post 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
Cooperman
Forum Commoner
Posts: 27
Joined: Mon Jun 02, 2008 4:44 am

Re: Update MySQL DB from a form

Post 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();
comando
Forum Newbie
Posts: 11
Joined: Wed Jun 04, 2008 11:18 am

Re: Update MySQL DB from a form

Post 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();
Cooperman
Forum Commoner
Posts: 27
Joined: Mon Jun 02, 2008 4:44 am

Re: Update MySQL DB from a form

Post 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??? :?
comando
Forum Newbie
Posts: 11
Joined: Wed Jun 04, 2008 11:18 am

Re: Update MySQL DB from a form

Post by comando »

I think its because of the browser cache..but is it working now ?
Cooperman
Forum Commoner
Posts: 27
Joined: Mon Jun 02, 2008 4:44 am

Re: Update MySQL DB from a form

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Update MySQL DB from a form

Post 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
    }
  }
}
?>
Post Reply