Re: [PHP] Re: Don't ejecute a sentence if a field is empty

2005-07-24 Thread Burhan Khalid

Jasper Bryant-Greene wrote:

Jesús Alain Rodríguez Santos wrote:


Hello I'm new:
I need to know how can I stop a php sentence if my db is empty, for 
example

I have writed a php sentence, if every fields from mmy db are full, there
is no problem, but I delete every values from the all fields in my db 
when

I ejecute my script mysql give me an error, Ej:

$fecha = mysql_query(SELECT event_day, event_month, event_year FROM
$db_table WHERE event_title = $dia_maximo);
$fecha_max = mysql_fetch_array($fecha);
$fecha_maxima = $fecha_max['event_day'];
$diames_maximo = $fecha_max['event_month'];

wehen I ejecute the script the error message is it:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in /home/www/cfg/prueba/calendar_este2/index.php on line
277




$fecha = mysql_query(SELECT event_day, event_month, event_year FROM 
$db_table WHERE event_title = $dia_maximo);

if($fecha) {
$fecha_max = mysql_fetch_array($fecha);

$fecha_maxima = $fecha_max['event_day'];
$diames_maximo = $fecha_max['event_month'];
} else {
// No row returned...
}


This is very wrong. If $fecha is false, then it means that the query 
didn't execute properly, not that there were no rows returned.


You should do this instead:

$query  = SELECT event_day, event_month, event_year FROM $db_table ;
$query .= WHERE event_title = '.$dia_maximo;

$fecha = mysql_query($query);
if (!is_resource($fecha))
{
   die($query.br /.mysql_error());
}

// -- continue with the rest

Also, make sure you have a valid connection to the database, 
mysql_error() will help you with sorting out what is the problem.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Don't ejecute a sentence if a field is empty

2005-07-23 Thread Jasper Bryant-Greene

Jesús Alain Rodríguez Santos wrote:

Hello I'm new:
I need to know how can I stop a php sentence if my db is empty, for example
I have writed a php sentence, if every fields from mmy db are full, there
is no problem, but I delete every values from the all fields in my db when
I ejecute my script mysql give me an error, Ej:

$fecha = mysql_query(SELECT event_day, event_month, event_year FROM
$db_table WHERE event_title = $dia_maximo);
$fecha_max = mysql_fetch_array($fecha);
$fecha_maxima = $fecha_max['event_day'];
$diames_maximo = $fecha_max['event_month'];

wehen I ejecute the script the error message is it:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in /home/www/cfg/prueba/calendar_este2/index.php on line
277



$fecha = mysql_query(SELECT event_day, event_month, event_year FROM 
$db_table WHERE event_title = $dia_maximo);

if($fecha) {
$fecha_max = mysql_fetch_array($fecha);

$fecha_maxima = $fecha_max['event_day'];
$diames_maximo = $fecha_max['event_month'];
} else {
// No row returned...
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php