mndasari Posted March 19, 2009 Share Posted March 19, 2009 Hi, I am new to PHP and Mysql. Wrote a small php program which queries mysql db on local server based on inputs and displays results. Initially there was some error in the query I wrote, so got an error (since I used die as below ... $result = mysql_query( $qry ) or die(mysql_error()); But now that I corrected query, removed query altogether from php code, but still its showing the same last error message on the resulting webpage. I tried to clear browser cache, called flush status in mysql etc etc but no change. When I run the php program, webpage is still showing the old (last) query error. Could anybody help me please, as to, what could be done! Thanks in advance for the help! Quote Link to comment https://forums.phpfreaks.com/topic/150140-last-query-error-in-mysql-using-php/ Share on other sites More sharing options...
pkSML Posted March 19, 2009 Share Posted March 19, 2009 What exactly is that old query error? Could you show us the snippet of code that still gives you this error? Quote Link to comment https://forums.phpfreaks.com/topic/150140-last-query-error-in-mysql-using-php/#findComment-788448 Share on other sites More sharing options...
mndasari Posted March 20, 2009 Author Share Posted March 20, 2009 Thanks a lot for the reply! The error still displayed on webpage is: Unknown column 'jimmy' in 'field list' jimmy is user_id. This is due to my earlier (wrong) query ... $qry = "SELECT " . $user_id . " FROM user_tbl"; This is obviously wrong and I corrected it as follows ... function get_user_name_from_db($user_id) { $qry = "SELECT * FROM user_tbl where user_id = '". $user_id . "'"; $result = mysql_query( $qry ) or die(mysql_error()); $row = mysql_fetch_array($result); $user_name = $row['last_name'] . ", " . $row['first_name']; return $user_name; } This func get_user_name_from_db() is called from new_scr.php, which is action function for a form. File: new_scr.php is as below ... <?php // Collect inputs ... $user_id = $_POST['f_user_id']; $release_stream = $_POST['f_release_stream']; : : $cust_prio = $_POST['f_cust_prio']; $username="xxx"; $password="yyy"; $database="zzz"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); echo "Content-type: text/html"; echo ""; echo ""; echo ""; echo "<html>"; echo "<head>"; echo "<title>"; echo "</title>"; echo "</head>"; echo "<body>"; echo "<center>"; $user_name = get_user_name_from_db( $user_id ); : : I corrected query, lateron removed mysql stuff altogether from .php, just collecting inputs from form and displaying using php, but still it gives old (same) error. I tried to clear browser cache, restarted browser etc didnot help, may be its got to do with caching of mysql last qry result/error, not sure though! Could you please help! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/150140-last-query-error-in-mysql-using-php/#findComment-789157 Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 trie this and post the error please. <?php function get_user_name_from_db($user_id) { $qry = "SELECT * FROM user_tbl where user_id = '$user_id' "; $result = mysql_query( $qry ) or die(mysql_error()); $row = mysql_fetch_assoc($result)or die (mysql_error()); $user_name = $row['last_name'] . ", " . $row['first_name']; return $user_name; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/150140-last-query-error-in-mysql-using-php/#findComment-789170 Share on other sites More sharing options...
mndasari Posted March 20, 2009 Author Share Posted March 20, 2009 Its still showing the same error! trie this and post the error please. <?php function get_user_name_from_db($user_id) { $qry = "SELECT * FROM user_tbl where user_id = '$user_id' "; $result = mysql_query( $qry ) or die(mysql_error()); $row = mysql_fetch_assoc($result)or die (mysql_error()); $user_name = $row['last_name'] . ", " . $row['first_name']; return $user_name; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/150140-last-query-error-in-mysql-using-php/#findComment-789228 Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 post the error please. Quote Link to comment https://forums.phpfreaks.com/topic/150140-last-query-error-in-mysql-using-php/#findComment-789230 Share on other sites More sharing options...
mndasari Posted March 20, 2009 Author Share Posted March 20, 2009 Error is ... Unknown column 'jimmy' in 'field list' I guess, its picking up the last executed .php file from somewhere (from cache?), so even if I am changing .php file, its not executing new changes. Please help! post the error please. Quote Link to comment https://forums.phpfreaks.com/topic/150140-last-query-error-in-mysql-using-php/#findComment-789248 Share on other sites More sharing options...
MasterACE14 Posted March 20, 2009 Share Posted March 20, 2009 run the query in PHPMyAdmin or where ever and see if it works. SELECT * FROM user_tbl where user_id = 'jimmy' Quote Link to comment https://forums.phpfreaks.com/topic/150140-last-query-error-in-mysql-using-php/#findComment-789250 Share on other sites More sharing options...
mndasari Posted March 20, 2009 Author Share Posted March 20, 2009 Hi, Problem is not with the query itself. If I run the query in mysql directly it does work! Problem is, evenif I remove all mysql stuff from .php file, leaving only plain php stuff, somehow its still executing the old .php file (having errors!), not sure how? Do I need to clear cache somewhere? in browser? mysql? or in php itself? Thanks. run the query in PHPMyAdmin or where ever and see if it works. SELECT * FROM user_tbl where user_id = 'jimmy' Quote Link to comment https://forums.phpfreaks.com/topic/150140-last-query-error-in-mysql-using-php/#findComment-789306 Share on other sites More sharing options...
pkSML Posted March 20, 2009 Share Posted March 20, 2009 Maybe you could give us the URL to see if we get the same errors. What browser are you using? Try a different browser. Otherwise, make sure you've actually saved the php file on the server. Might as well check the basics! Hi, Problem is not with the query itself. If I run the query in mysql directly it does work! Problem is, evenif I remove all mysql stuff from .php file, leaving only plain php stuff, somehow its still executing the old .php file (having errors!), not sure how? Do I need to clear cache somewhere? in browser? mysql? or in php itself? Thanks. run the query in PHPMyAdmin or where ever and see if it works. SELECT * FROM user_tbl where user_id = 'jimmy' Quote Link to comment https://forums.phpfreaks.com/topic/150140-last-query-error-in-mysql-using-php/#findComment-789369 Share on other sites More sharing options...
irkevin Posted March 20, 2009 Share Posted March 20, 2009 not sure it will work but try to return the row variable <?php function get_user_name_from_db($user_id) { $qry = "SELECT * FROM user_tbl where user_id = '$user_id' "; $result = mysql_query( $qry ) or die(mysql_error()); $row = mysql_fetch_assoc($result)or die (mysql_error()); $user_name = $row['last_name'] . ", " . $row['first_name']; return $row; } ?> i dont guarantee this. it's been a while since i didnt touch php Quote Link to comment https://forums.phpfreaks.com/topic/150140-last-query-error-in-mysql-using-php/#findComment-789379 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.