Jump to content

Last query error in Mysql using PHP


mndasari

Recommended Posts

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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;
}

?>

Link to comment
Share on other sites

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;
}

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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'

Link to comment
Share on other sites

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'

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.