Jump to content

Wierd Problem


error123

Recommended Posts

Im trying to make a sorta thing where you do lic?=12-12-12-12

 

and i need it to return "Invalid" if you submit a rong licence and Correct if you have a good licence this is the code i have it seems to either always Return Invalid or always Correct

 

<?php

$con = mysql_connect("localhost","","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("", $con);


$lic = $_GET['lic'];
$result = mysql_query("SELECT lic FROM info");
if (!$result){
    // the query failed to execute, get debugging information - 
   die('The SELECT query failed' . mysql_error());
} else {
    // the query executed, check if there are any rows in the result set
    if(mysql_num_rows($result) <1){
        echo "Correct";
	// code to execute when there are any row(s) in the result set
    } else {
        echo "Invalid";
        // code to execute when there are no row(s) in the result set
    }
}  



?>

 

Any help would be really appreciated.

Link to comment
https://forums.phpfreaks.com/topic/199576-wierd-problem/
Share on other sites

mysql_num_rows($result) < 1

 

This says if less than one row was returned from the database, then output correct. I rather suspect you want that to be a greater than sign not a less than sign. Also you are currently selecting all rows from the database you will want to add a WHERE lic = '$lic' clause to your SQL if you wish to check if the value entered is actually in the database.

 

 

Link to comment
https://forums.phpfreaks.com/topic/199576-wierd-problem/#findComment-1047557
Share on other sites

$lic = $_GET['lic'];
$result = mysql_query("SELECT lic FROM info WHERE lic = '$lic'");
if (!$result){
    // the query failed to execute, get debugging information - 
   die('The SELECT query failed' . mysql_error());
} else {
    // the query executed, check if there are any rows in the result set
    if(mysql_num_rows($result)>1 ){
        echo "Correct";
	// code to execute when there are any row(s) in the result set
    } else {
        echo "Invalid";
        // code to execute when there are no row(s) in the result set
    }
}  

 

Still not working this time its just Invalid for everything :/

Link to comment
https://forums.phpfreaks.com/topic/199576-wierd-problem/#findComment-1047561
Share on other sites

$lic = $_GET['lic'];
$result = mysql_query("SELECT lic FROM info WHERE lic = '$lic'");
if (!$result){
    // the query failed to execute, get debugging information - 
   die('The SELECT query failed' . mysql_error());
} else {
    // the query executed, check if there are any rows in the result set
    if(mysql_num_rows($result)==1 ){
        echo "Correct";
	// code to execute when there are any row(s) in the result set
    } else {
        echo "Invalid";
        // code to execute when there are no row(s) in the result set
    }
}  

Link to comment
https://forums.phpfreaks.com/topic/199576-wierd-problem/#findComment-1047567
Share on other sites

Edit the SQL query to fetch that field, then fetch the fields from the result set and echo it.

 

$lic = $_GET['lic'];
$result = mysql_query("SELECT lic, name FROM info WHERE lic = '$lic'");
if (!$result){
    // the query failed to execute, get debugging information - 
   die('The SELECT query failed' . mysql_error());
} else {
    // the query executed, check if there are any rows in the result set
    if(mysql_num_rows($result)==1 ){
        $row = mysql_fetch_assoc($result);
        echo $row['name'];
	// code to execute when there are any row(s) in the result set
    } else {
        echo "Invalid";
        // code to execute when there are no row(s) in the result set
    }
}  

Link to comment
https://forums.phpfreaks.com/topic/199576-wierd-problem/#findComment-1047914
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.