pudge1 Posted February 9, 2010 Share Posted February 9, 2010 $connection = mysql_connect('localhost',$user,$pass); mysql_select_db($dbname, $connection); $vault_id = mysql_real_escape_string( $vault_id ); $combo = mysql_real_escape_string( $combo ); $var = "SELECT * FROM Vaults WHERE Vault_ID='". $vault_id . "'"; $result = mysql_query($var , $connection); while($row = mysql_fetch_array($result)) { if($row['Vault_ID'] == $vault_id && $row['Combo'] == $combo) { $var = "SELECT Contents FROM Vaults WHERE Vault_ID='". $vault_id . "'"; $return = mysql_query($var , $connection); return $return; } else { return 'FALSE'; } } What I am trying to do is find out if the variable $vault_id and $combo correspondingly match up with two columns Vault_ID and Combo both in the same row. If not it returns false. Otherwise it gets the value of the contents column in that same row. For example: Vault_ID | Combo | Contents ---------------------------------- 01234 01-01-01 Vault Contents 12345 02-02-02 More Contents If my $vault_id == '01234' and $combo == '01-01-01' then it would return "Vault Contents" or if $vault_id == '12345' and $combo == '02-02-02' it would return "More Contents" otherwise it returns false. However it doesn't do this at all. It doesn't return a MySQL error but my host is weird about PHP/MySQL errors so there may be one I am not sure. Do you guys see an error or a mistake I made in syntax. Thanks for at least reading this and attempting to help me. Link to comment https://forums.phpfreaks.com/topic/191442-mysql-error/ Share on other sites More sharing options...
trq Posted February 9, 2010 Share Posted February 9, 2010 Your way over complicating things. $connection = mysql_connect('localhost',$user,$pass); mysql_select_db($dbname, $connection); $vault_id = mysql_real_escape_string( $vault_id ); $combo = mysql_real_escape_string( $combo ); $sql = "SELECT Contents FROM Vaults WHERE Vault_ID = '$vault_id' && Combo = '$combo'"; if ($result = mysql_query($var , $connection)) { if (mysql_num_rows($result)) { $row = mysql_fetch_array($result); echo $row['Contents']; } else { echo "Query did not find a match"; } } Link to comment https://forums.phpfreaks.com/topic/191442-mysql-error/#findComment-1009284 Share on other sites More sharing options...
pudge1 Posted February 9, 2010 Author Share Posted February 9, 2010 $vault_id = $_POST['id']; $vault_combo = $_POST['c1'] . '-' . $_POST['c2'] . '-' . $_POST['c3']; $open_vault = open_vault($vault_id,$vault_combo); if($open_vault == 'FALSE') { echo '<font color="red">Invalid Vault ID/Combo</font>'; } else { echo $open_vault; } So I set that as a function and used it in the code above. However it doesn't ECHO anything. Which is weird because in all the ifelse statements either ECHOS FALSE or something else. So I am guessing there is some kind of script error somewhere. Thanks a lot though for writing that up for me. Link to comment https://forums.phpfreaks.com/topic/191442-mysql-error/#findComment-1009401 Share on other sites More sharing options...
trq Posted February 10, 2010 Share Posted February 10, 2010 What does your open_vault() function look like? Link to comment https://forums.phpfreaks.com/topic/191442-mysql-error/#findComment-1009815 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.