Link to home
Start Free TrialLog in
Avatar of portal123
portal123

asked on

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
Avatar of geir_andersen
geir_andersen
Flag of Norway image

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
Avatar of Muuss
Muuss

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.

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
ASKER CERTIFIED SOLUTION
Avatar of jasco4617
jasco4617

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of portal123

ASKER

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
what is the difference in those two strings?

-Geir