2 Replies - 294 Views - Last Post: 22 August 2012 - 06:47 AM Rate Topic: -----

#1 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 48
  • View blog
  • Posts: 221
  • Joined: 10-March 12

beginner problem in reading database values

Posted 22 August 2012 - 06:33 AM

hello everyone!
i started two weeks ago my first website in php and there are A LOT of things i dont understand yet. So please be patient with me, i know this is a very noob question.
i have two tables in a database, one storing the usernames, the other, email adresses. What i wanted to accomplish is get the current logged in username, check if his/her email adress is in the second table and if it is, display an image; if its not, display another image. As far as i developed the code, sometimes it works, sometimes it doesnt, and i dont understand why! This is my code:

$usr1 = $_SESSION['username'];
	         $dn1 = mysql_query('SELECT email FROM users WHERE username="'.$usr1.'"');
	         if(mysql_num_rows($dn1)>0)
	            {
		            $dnn1 = mysql_fetch_array($dn1);
				}	   
	         $subemail1 = $dnn1['email'];			 
	         $issub1 = mysql_query('SELECT subscriber FROM BRIDGE WHERE subscriber="'.$subemail1.'"');
	         if(mysql_num_rows($issub1)>0)
	            {
		            echo '<form action="unsubscribe.php?parent=1" method="post">';              
       	            echo '<br><br><div class="box"><center><input type="image" src=nonotif.png border=0 /><input type="hidden" name="submit" /></center></div>'; 
				}
             else
                {
                    echo '<form action="subscribe.php?parent=1" method="post">';              
       	            echo '<br><br><div class="box"><center><input type="image" src=notif.png border=0 /><input type="hidden" name="submit" /></center></div>'; 
                }				



i dont seem to figure out where im mistaking... any help would be appreciated.
thank you in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: beginner problem in reading database values

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: beginner problem in reading database values

Posted 22 August 2012 - 06:41 AM

STOP! Right now!

If you're just learning this, then STOP learning mysql_ functions, which are DEPRECATED. Move to PDO and Prepared Statements. Excellent tutorial by Dormilich here.
Was This Post Helpful? 2
  • +
  • -

#3 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 48
  • View blog
  • Posts: 221
  • Joined: 10-March 12

Re: beginner problem in reading database values

Posted 22 August 2012 - 06:47 AM

well, thank you, as i said, im very new to this and i have no ideea of many things.. i just wanted to make a php forum with a custom interface, so i took a tutorial and started to modify it according to my needs. the problem was that the tutorial was not including an email notiffication system for new topics and i wanted to include that.. thats how i got to this problem. thank you for pointing me in the right direction, i will read your tutorial and try to understand it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1