Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Tenho uma página de pesquisa a um BD utilizando php+mysql. Nessa página configurei uma mensagem que devia aparecer se não existir o valor que se coloca no campo do formulário. Acontece que sempre que a página é aberta e sem preencher o campo do formulário, aparece logo a msn de erro. Eu queria que ela aparecesse só depois de preencher o campo do formulário. Como posso contornar essa questão?
Obrigado
<?php require_once('../Connections/chq.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
// Logout the current user.
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
$logoutGoTo = "../login_bd.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "admin,utilizador";
$MM_donotCheckaccess = "false";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && false) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "../erro.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_rsartigo = "-1";
if (isset($_POST['referencia'])) {
$colname_rsartigo = $_POST['referencia'];
}
mysql_select_db($database_chq, $chq);
$query_rsartigo = sprintf("SELECT * FROM artigos WHERE referencia = %s ORDER BY referencia ASC", GetSQLValueString($colname_rsartigo, "text"));
$rsartigo = mysql_query($query_rsartigo, $chq) or die(mysql_error());
$row_rsartigo = mysql_fetch_assoc($rsartigo);
$totalRows_rsartigo = mysql_num_rows($rsartigo);
$queryString_rsclientes = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsclientes") == false &&
stristr($param, "totalRows_rsclientes") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsclientes = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsclientes = sprintf("&totalRows_rsclientes=%d%s", $totalRows_rsclientes, $queryString_rsclientes);
$currentPage = $_SERVER["PHP_SELF"];
$queryString_rslistagem = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rslistagem") == false &&
stristr($param, "totalRows_rslistagem") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rslistagem = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rslistagem = sprintf("&totalRows_rslistagem=%d%s", $totalRows_rslistagem, $queryString_rslistagem);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml%22)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="../cheques/css.css" rel="stylesheet" type="text/css" />
<link href="../css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
color: #CCCCCC;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #CCCCCC;
}
a:hover {
text-decoration: underline;
color: #0095C3;
}
a:active {
text-decoration: none;
color: #CCCCCC;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_callJS(jsStr) { //v2.0
return eval(jsStr)
}
//-->
</script>
</head>
<body class="texto">
<table width="70%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><p> </p>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><span class="style4"><img src="../img/artigos.jpg" width="47" height="45" /> </span><span class="Titulocinza">Gestão de Cheques</span></td>
<td align="right"><img src="../img/logo_rgb.png" width="98" height="66" /></td>
</tr>
</table>
<hr /> <p> </p></td>
</tr>
<tr class="Titulobebe">
<td> <span class="Titulobebe">Pesquisar artigo por referência</span></td>
</tr>
<tr>
<td><p> </p>
<form id="cliente" name="cliente" method="post" action="">
<input name="referencia" type="text" class="Textarea" id="referencia" />
<label>
<input name="button" type="submit" class="Texto" id="button" value="Pesquisar" />
</label>
</form>
<label></label>
<?php if ($totalRows_rsartigo > 0) { // Show if recordset not empty ?>
<p class="Titulocinza">Resultado da Pesquisa pela referência <strong><?php echo $_POST['referencia']; ?></strong>:</p>
<blockquote>
<p class="Titulo"><a href="detalhe_artigo.php?recordID=<?php echo $row_rsartigo['id_artigo']; ?>"><?php echo $row_rsartigo['referencia']; ?></a></p>
</blockquote>
<p><a href="<?php echo $row_rsartigo['referencia']; ?>" class="Texto"></a></p>
<?php } // Show if recordset not empty ?></td>
</tr>
<?php if ($totalRows_rsartigo == 0) { // Show if recordset empty ?>
<tr>
<td align="center"><span class="dados">Não existem artigo com a referência indicada!</span></td>
</tr>
<?php } // Show if recordset empty ?>
</table>
<p> </p>
<table width="70%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><hr /></td>
</tr>
<tr>
<td><p> </p>
</td>
</tr>
</table>
<table width="70%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><p class="Texto"> </p></td>
<td align="right">[<a href="#" onclick="MM_callJS('history.go(-1)')">Voltar</a>] [<a href="<?php echo $logoutAction ?>">Sair</a>]</span></td>
</tr>
</table>
<p> </p>
<p> </p>
</body>
</html>
<?php
mysql_free_result($rsartigo);
?>
>
>
Tenho uma página de pesquisa a um BD utilizando php+mysql. Nessa página configurei uma mensagem que devia aparecer se não existir o valor que se coloca no campo do formulário. Acontece que sempre que a página é aberta e sem preencher o campo do formulário, aparece logo a msn de erro. Eu queria que ela aparecesse só depois de preencher o campo do formulário. Como posso contornar essa questão?
Obrigado
Se você posta-se o código seria mais facil de te auxiliar, as vezes pode ser uma condição errada!
De qualquer forma posta o codigo ae, pro pessoal poder dar uma olhda!
Abraços!
>
Tenho uma página de pesquisa a um BD utilizando php+mysql. Nessa página configurei uma mensagem que devia aparecer se não existir o valor que se coloca no campo do formulário. Acontece que sempre que a página é aberta e sem preencher o campo do formulário, aparece logo a msn de erro. Eu queria que ela aparecesse só depois de preencher o campo do formulário. Como posso contornar essa questão?
Obrigado
Se você posta-se o código seria mais facil de te auxiliar, as vezes pode ser uma condição errada!
De qualquer forma posta o codigo ae, pro pessoal poder dar uma olhda!
Abraços!