Problem, How to get a value from MySQL table

I have a question to get one value from a table called tblenzo_meladmin in MySQL and then I would like to pack this value into Email function. I used my_fetch_assoc() function to grab a  value from a record in a table.

To send Email is O.K, but I've got error message like follows
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/users/13and12/public_html/store_based_newsletters/transact_malma.php on line 93

And my code is as follows:
             
$sql_sel = "select emailaddress from tblenzo_client where uid2=$_SESSION[uid2]";
$rst_sel = mysql_query($sql_sel,$con);

 
              $sql_admin_email = "select s_email from tblenzo_meladmin where uid=$_SESSION[uid2]";
              $rst_admin_email = mysql_query($sql_admin_email,$con);
line93     $col_admin_email = mysql_fetch_assoc($rst_admin_email);
            
            
            $subject = $_POST['subject'];
            $msg = $_POST['news'];
                        

            while($col=mysql_fetch_array($rst_sel)){
            
            $mailform="From:" .mb_encode_mimeheader("exe123") ."<".$col_admin_email.">";
            mb_send_mail($col['emailaddress'], $subject,$msg,$mailform);
            }

If you help me out, I really appreciate it.

Thanks and Best Wish, portal123
portal123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

geir_andersenSystems engineerCommented:
Try to change this:
$sql_admin_email = "select s_email from tblenzo_meladmin where uid=$_SESSION[uid2]";
$rst_admin_email = mysql_query($sql_admin_email,$con);
$col_admin_email = mysql_fetch_assoc($rst_admin_email);

to this:

$sql_admin_email = "select s_email from tblenzo_meladmin where uid={$_SESSION['uid2']}";
$rst_admin_email = mysql_query($sql_admin_email,$con);
$col_admin_email = mysql_fetch_assoc($rst_admin_email);

That should fix your  query error.
You could also change:
$rst_admin_email = mysql_query($sql_admin_email,$con);
to:
$rst_admin_email = mysql_query($sql_admin_email,$con) or die("Query error: " . mysql_error());

-Geir
MuussCommented:
You connected to the mysql server before releasing the query, right?
(with mysql_connect();).

Change : $sql_sel = "select emailaddress from tblenzo_client where uid2=$_SESSION[uid2]";
To : $sql_sel = "select emailaddress from tblenzo_client where uid2=".$_SESSION["uid2"];

and, if it still doesn't work, change : $rst_sel = mysql_query($sql_sel,$con);
to : $rst_sel = mysql_query($sql_sel,$con) OR print mysql_error()."<p>$sql_sel";

You ll see the error message returned by mysql and also your sql query.

geir_andersenSystems engineerCommented:
also:
$sql_sel = "select emailaddress from tblenzo_client where uid2=$_SESSION[uid2]";
$rst_sel = mysql_query($sql_sel,$con);

should be:
$sql_sel = "select emailaddress from tblenzo_client where uid2={$_SESSION['uid2']}";
$rst_sel = mysql_query($sql_sel,$con);

-Geir
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

jasco4617Commented:
portal,

From my experience you get this error when there is a problem with the mysql_query function.  

Make sure your everything is correct in your SQL statement.  You will want to look to make sure that the spelling of your tables and variables are all correct.  Also, make sure your database connection, $con, is connecting correctly and and make sure you are selecting the correct database by using the mysql_select_db function.


Also, mysql_query will return one of two things: 1) the results of the query or 2) false.  It returns falses when ever there was a error of some kind.  Because of this there is not error message associated with mysql_query.  An If statement here is very useful to handle errors while running this function.
---------

if ( $rst_admin_email ) {

          $col_admin_email = mysql_fetch_assoc($rst_admin_email);
         
          $subject = $_POST['subject'];
          $msg = $_POST['news'];
                   

          while($col=mysql_fetch_array($rst_sel)){
         
          $mailform="From:" .mb_encode_mimeheader("exe123") ."<".$col_admin_email.">";
          mb_send_mail($col['emailaddress'], $subject,$msg,$mailform);
          }

} else {
         echo "there was error performing this query: " . $sql_admin_email;
}

---------


That if statement makes sure that the query ran error free and if it did not it will return that error message along with the query so you can see exactly what it tried to run.


I hope this helps.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
portal123Author Commented:
Thanks all guys and jasco4617 .

it was my simple miss spelling:
$sql_admin_email = "select s_email from tblenzo_meladmin where uid=$_SESSION[uid2]";

Should be - $sql_admin_email = "select s_email from tblenzo_meladmin where uid=$_SESSION[uid2]";

b.w, portal123
geir_andersenSystems engineerCommented:
what is the difference in those two strings?

-Geir
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.