This topic is locked
[SOLVED]

 Check whether sql record exists based on 2 parameters

8/11/2011 1:56:57 PM
PHPRunner General questions
B
bobdansei author

i am trying Check whether sql record exists based on 2 parameters well anyone can give me a hand with this?
my code... but is not working... <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=17537&image=1&table=forumtopics' class='bbc_emoticon' alt=':(' />
global $conn;
$strSQLExists = "select * from dbo.tb_Ramal where Ramal='".$values["Ramal"]." and IdEquipamento = ".$values["IdEquipamento"]."'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);
if($data)

{

echo "<font color=red> Ramal ja existe no sistema.</font>";

return false;

}

else

{

return true;

}

return true;

C
cgphp 8/11/2011

Try this:

global $conn;
$strSQLExists = "select * from dbo.tb_Ramal where Ramal='".$values["Ramal"]."' and IdEquipamento = ".$values["IdEquipamento"];

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);
if($data)

{

$message = "<font color=red> Ramal ja existe no sistema.</font>";

return false;

}

else

{

return true;

}
B
bobdansei author 8/11/2011



Try this:

global $conn;
$strSQLExists = "select * from dbo.tb_Ramal where Ramal='".$values["Ramal"]."' and IdEquipamento = ".$values["IdEquipamento"];

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);
if($data)

{

$message = "<font color=red> Ramal ja existe no sistema.</font>";

return false;

}

else

{

return true;

}



i tested your code and It did not worked .. ... : P well taking one or another parameter works well .. but I have to check the two conditions

Sergey Kornilov admin 8/11/2011

Instead of executing select query print it on the webpage and then execute it against your database manually. This may give you more info on what is not right with the query.

B
bobdansei author 8/15/2011



Instead of executing select query print it on the webpage and then execute it against your database manually. This may give you more info on what is not right with the query.


well..finaly i have a solution <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=60167&image=1&table=forumreplies' class='bbc_emoticon' alt=':P' />
tnk all for help
global $conn;

global $bob;

global $eq;
$bob = $values["DataInicio"];

$eq = $values["idequipamento"];

$strSQLExists = "select * from dbo.tb_RamalHist where idequipamento = $eq and ('$bob' between [DataInicio] and [DataFim]) and Ramal='".$values["Ramal"]."'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

echo "<font color=red> a Data dete Ramal é Invalidada.</font>";

return false;

}

else

{

return true;

}