User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,481 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,797 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2462 | Replies: 5
Reply
Join Date: May 2005
Posts: 229
Reputation: nathanpacker is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

mysql UPDATE not working! Why?

  #1  
Sep 27th, 2006
Very simple code, I even echo the variables to make sure they are comming through:
[PHP]<?
include 'config.php';

$recordid = $_POST['recordid'];
$im=$_POST['im'];
$bm=$_POST['bm'];
$peachtree=$_POST['peachtree'];
$canapprove=$_POST['canapprove'];
$cancomment=$_POST['cancomment'];
$canclose=$_POST['canclose'];
$administrator=$_POST['administrator'];

echo $im;
echo $bm;
echo $peachtree;
echo $canapprove;
echo $cancommnet;
echo $canclose;
echo $administrator;
echo "<p>";


$result = mysql_query("UPDATE employees SET im='$im', bm='$bm', peachtree='$peachtree', canapprove='$canapprove', cancomment='$cancomment', canclose='$canclose', administrator='$administrator' WHERE RECORDID='$recordid'")
or die('sorry, no query');


echo "Success";

?>[/PHP]

It executes the code, and I get a success, with no query errors. But the database is not being updated. Any idea to what I'm doing wrong? Oh, and the variables are echoing out the correct values.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2006
Location: New Jersey
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Rep Power: 5
Solved Threads: 34
Moderator
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: mysql UPDATE not working! Why?

  #2  
Sep 27th, 2006
Do you have access to phpmyadmin or the command line for mysql? If so, echo out your query and paste it directly into mysql. It should tell you the reason why the update isn't working. mysql_error() should tell you this also even if die() isn't working.
Last edited by stymiee : Sep 27th, 2006 at 11:32 am.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Reply With Quote  
Join Date: Jul 2004
Location: North East Indiana
Posts: 491
Reputation: Puckdropper is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 20
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

Re: mysql UPDATE not working! Why?

  #3  
Sep 27th, 2006
You can set your query in a variable and then echo that out. I don't think that will help, but it's another option.
www.uncreativelabs.net

Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Reply With Quote  
Join Date: May 2005
Posts: 229
Reputation: nathanpacker is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: mysql UPDATE not working! Why?

  #4  
Sep 27th, 2006
Originally Posted by stymiee View Post
Do you have access to phpmyadmin or the command line for mysql? If so, echo out your query and paste it directly into mysql. It should tell you the reason why the update isn't working. mysql_error() should tell you this also even if die() isn't working.

Thanks. Yes, I do have access to the mysql database, and I have tried running the query directly in the command line, and didn't get any errors. That's why this is so boggling!
Reply With Quote  
Join Date: May 2006
Location: New Jersey
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Rep Power: 5
Solved Threads: 34
Moderator
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: mysql UPDATE not working! Why?

  #5  
Sep 27th, 2006
That is mind boggling. I guess at this point I can only wish you luck.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Reply With Quote  
Join Date: May 2005
Posts: 229
Reputation: nathanpacker is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: mysql UPDATE not working! Why?

  #6  
Sep 28th, 2006
Thanks for all your ideas. I figured it out. First, the reason my tests were working when I would paste the code into the mysql command line was because I knew I couldn't use the variables in there, so I replaced them all with numbers, so of course it would work.

And I was echoing out all the variables except for one. I was echoing all the variables that I was updating on the row, but not the one that defines WHICH row to update. The one after the WHERE! Anyway, I tried echoing that out, and realized that it wasn't getting passed from the form. Then I realized, it's not actually part of the form, I needed to pass it on using a hidden input field, and forgot to do that.

So, long story short, I wasn't echoing all my variables. Problem solved!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 2:52 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC