Warning: mysql_num_rows() expects parameter 1 to be resource

slim211 Messages postés 1 Statut Membre -  
tryan44 Messages postés 1289 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

j'ai un probleme :
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\test.php on line 18

Voila le code:

<?php
include_once("configr.php");

mysql_connect($host,$user,$pwd);
mysql_select_db($nbd);

if (isset($_POST['cot']) and !empty($_POST['cot']))
{
$cot=$_POST['cot'];
$art=$_POST['art'];
$aut=$_POST['aut'];
$an=$_POST['an'];
$num=$_POST['num'];
$rub=$_POST['rub'];
$pag=$_POST['pag'];
$req=mysql_query("select * from revue where cot=$cot");

}
if(mysql_num_rows($req)==0)
{
mysql_query("insert into revue values('$cot','$art','$aut','$an','$num','$rub','$pag')");

}
else

{
echo "<script>alert(\"Ce numéro existe déja\")</script>";

}

//header("location:index.php");
?>

Merci de m'aider a réparer mon erreur.

1 réponse

  1. tryan44 Messages postés 1289 Date d'inscription   Statut Membre Dernière intervention   220
     
    Salut,

    Non testé ...
    <?php 
    include_once("configr.php"); 
    
    mysql_connect($host,$user,$pwd); 
    mysql_select_db($nbd); 
    
    //si la variable existe et qu'elle est différente de vide
    if(isset($_POST['cot']) && !empty($_POST['cot'])) 
    { 
    	//on prépare les variables
    	$cot=$_POST['cot']; 
    	$art=$_POST['art']; 
    	$aut=$_POST['aut']; 
    	$an=$_POST['an']; 
    	$num=$_POST['num']; 
    	$rub=$_POST['rub']; 
    	$pag=$_POST['pag']; 
    	
    	//on regarde si celle-ci existe déjà
    	$req=mysql_query("SELECT cot FROM revue WHERE cot=$cot"); 
    	//si elle n'existe pas
    	if(mysql_num_rows($req)==0){
    		//on l'insère	
    		$result = mysql_query("INSERT INTO revue VALUES(
    		'".mysql_real_escape_string($cot)."',
    		'".mysql_real_escape_string($art)."',
    		'".mysql_real_escape_string($aut)."',
    		'".mysql_real_escape_string($an)."',
    		'".mysql_real_escape_string($num)."',
    		'".mysql_real_escape_string($rub)."',
    		'".mysql_real_escape_string($pag)."'
    		)"); 
    		
    		//Si il y a une erreur
    		if (!$result){
    			die('Requête invalide : ' . mysql_error());
    		}
    		//tout va bien
    		else{ 
    			echo '<script>alert("Insertion OK!")</script>'; 
    		}		
    	} 
    	//si elle existe
    	else{
    		echo '<script>alert("La variable existe déjà!")</script>'; 
    	}
    }
    //la variable n'existe pas ou est vide
    else{
    	echo '<script>alert("La variable n\'existe pas ou est vide!")</script>'; 
    } 
    //header("location:index.php"); 
    ?> 
    

    0