php - How to check if two fields have same value using msql? -


i having problem using mysql statement in want check whether fan followed , fan following having same value user , username, here code :

<? $selectfan = mysql_query("select * amityfans"); $fanrow = mysql_fetch_assoc($selectfan); $fan_following = $fanrow['fan_following']; $fan_followed = $fanrow['fan_followed']; if ($fan_following == "$user" && $fan_followed=="$username") {  $addasfan = '<input type="submit" class="button" name="removefriend" value="remove fan">'; } else {  $addasfan = '<input type="submit" class="button" name="addfriend" value="add me fan">'; } echo $addasfan; ?> 

but if 'user' , 'username' have same values not displaying remove fan button. fyi $user username of logged in user , $username username of profile seeing.

edit :

i having problem in deleting particular row of fan having user , username here code :

<?php //$user = logged in user //$username = user owns profile if (isset($_post['removefriend'])) { $removefan = mysql_query("delete amityusers fan_following='$user' && fan_followed='$username'"); } ?> 

having fred in fan_following column , bob in fan_followed produced add me fan button.

having bob in fan_following column , bob in fan_followed produced remove fan button.

by changing:

if ($fan_following == "$user" && $fan_followed=="$username") 

to:

if ($fan_following == $fan_followed) 

^--« (which believe should take care of deletion problem, tested using code inside function setup inside same script.

this have done setting quick db.

using following:

<?php  $db_host = "xxx"; $db_name = "xxx"; $db_pass = "xxx"; $db_user = "xxx";   $db = new mysqli($db_host, $db_user, $db_pass, $db_name); if($db->connect_errno > 0) {   die('connection failed [' . $db->connect_error . ']'); }  $user = "fred"; $username = "bob";   $selectfan = mysqli_query($db,"select * amityfans");  $fanrow = mysqli_fetch_assoc($selectfan); $fan_following = $fanrow['fan_following']; $fan_followed = $fanrow['fan_followed'];   if ($fan_following == $fan_followed) {   $addasfan = '<input type="submit" class="button" name="removefriend" value="remove fan">';  } else {  $addasfan = '<input type="submit" class="button" name="addfriend" value="add me fan">'; } echo $addasfan; ?> 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -