I dont know to much about php and mysql, but is their a way to check if theirs something in a secific colum and if so then do one thing if not then do something else?

like

if(check=true)
echo 'it existsed';
else
echo 'it didnt exist';

    I think we need a bit more information. Are you trying to see if ANY row in the database has a given value for a certain column? Or, do you have some ID identifying a unique row and you want to know if that specific row has the given value for the specified column?

      i have a database and then a table the table has three colums they areauth,user, ip

      now what i want to know is their a way to say like:

      $auth=$_GET['auth'];
      if(in column auth we find the auth value)
      do this
      else
      do this

      im using this with a java application sorry i know more ava then php.

      I have the connections and the select data base and all. I know tha much i know how to insert data but i have no clue how to ceck if somthing exists.

        Okay, well here's the basic SQL query:

        SELECT user, ip FROM myTable WHERE auth='auth_code_here'

        If you're only expecting 1 row to be returned, you can add a "LIMIT 1" onto the end of that query.

        After that, it's simply a matter of using [man]mysql_query/man to execute the query and something like [man]mysql_fetch_assoc/man to retrieve the row (or use this function in a while() loop to retrieve all rows matched) and use the data.

          see thatsnot what i want i just wanna see if the auth vale is found in a colum if so just return tru like a boolean dont return user or ip or anything thats just for my reffrence.

            Ah, okay. Try something like this:

            $query = "SELECT 1 FROM myTable WHERE auth='auth_code_here' LIMIT 1";
            $exec = mysql_query($query);
            
            $exists = (mysql_num_rows($exec) == 1 ? TRUE : FALSE);

              hey sry to add, can u do something like:

              $query = "SELECT 1 FROM myTable WHERE auth='auth_code_here' && state='active' LIMIT 1";

              like also check one it finds the auth if it says active? yeah i just changed the degsin of my system lol. SRY

                Of course you can... except you need to use 'AND' instead of '&&'.

                  i recivie:
                  Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in blah/print_auths.php on line 17
                  false

                  the code:

                  <?php
                  
                  $username="";
                  $password="";
                  $database="";
                  
                  $auth=$_GET["auth"];
                  $ip=@$REMOTE_ADDR;
                  date_default_timezone_set('EST');
                  $date=date('l dS \of F Y h:i:s A');
                  
                  mysql_connect(localhost,$username,$password) or die( "Unable to connect to server");
                  @mysql_select_db($database) or die( "Unable to select database");
                  
                  $query = "SELECT 1 FROM auths WHERE auth=".$auth." AND state=active LIMIT 1";
                  $exec = mysql_query($query);
                  [line 17]$exists = (mysql_num_rows($exec) == 1 ? TRUE : FALSE);
                  if($exists){
                  	$sql = "INSERT INTO connections (auth,ip,time) VALUES ('$auth','$ip','$date')";
                  	mysql_query($sql);
                  	echo 'active';
                  }else{
                  	echo 'false';
                  }
                  mysql_close();
                  

                    i have the clsing tag lol didnt copy it, amy clue?

                      You're missing the single quotes around the string values in your query (your post above, #9, has these quotes).

                        Write a Reply...