Author Topic: MySQL Error  (Read 146 times)

0 Members and 1 Guest are viewing this topic.

Offline pudge1Topic starter

  • Irregular
    • View Profile
MySQL Error
« on: February 08, 2010, 09:14:17 PM »
Code: [Select]
$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.

Online thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
    • View Profile
Re: MySQL Error
« Reply #1 on: February 09, 2010, 01:53:19 AM »
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";
  }
}

Offline pudge1Topic starter

  • Irregular
    • View Profile
Re: MySQL Error
« Reply #2 on: February 09, 2010, 09:22:31 AM »
Code: [Select]
$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.

Online thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
    • View Profile
Re: MySQL Error
« Reply #3 on: February 09, 2010, 08:28:47 PM »
What does your open_vault() function look like?

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.