Question

i have these three files: index.php:

<div class="tweet_bx">
     <form method="post" name="m_gigs" id="m_gigs" enctype="multipart/form-data"  action="index.php">
       <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="17%"><strong>Filter gigs by</strong></td>
        <td class="<?php echo $class1;  ?>" width="8%" align="center" ><a class="cuuuent" href="index.php?gigs=latest" >Latest</a></td>
        <td class="<?php echo $class2;  ?>" width="15%" align="center"><a href="index.php?gigs=popular">Most Popular</a></td>
        <td class="<?php echo $class3;  ?>" width="15%" align="center"><a href="index.php?gigs=rating" >Best Ratings</a></td>

      </tr>
    </table>
    <table>
    <?php
    include('Sql.php');
    $c = new connexion();
    $videos= $c->getVideos();
    for($i=0;$i<sizeof($videos); $i++)
    {
    ?>
    <tr><td colspan = "2"><img src="<?php echo $videos[$i]['image']; ?> " /></td>
         <td><label color="blue"><?php echo $videos[$i]['titre']; ?></label></td>

    </tr>
    <tr>
    <td><label color="blue"><?php echo $videos[$i]['description']; ?></label></td>
    </tr>


    <?php
    }
    ?>

    </table>

    </form>
    </div>

    <div class="tweet_bx">
    <?php





    ?>

    </div>
    </div>
    <?php include('right.php'); ?>
    </div>

the file right.php:

<div class="right_box">
<div class="right_box_center">
<ul>
<?php
include('Sql.php');

$c = new connexion();
$categories = $c->getCategories();
for($i=0;$i<sizeof($categories) ; $i++){


?>
<li><a href="index.php?categorie=<?php  echo $categories[$i]['categorie'];?>"><?php  echo $categories[$i]['categorie'];?></a> </li>

  <?php
  }
  ?>
   </ul>
   </div>
<img align="middle" src="images/img.jpg" />
<a href="javascript:popup()"> <img align="middle" src="images/invite.jpg" style="padding-left:32px;" /></a>

</div>

and finally the file sql.php:

<?php
class connexion {
    function __construct(){
    $HOST_DB ="mysql11.000webhost.com";
    $NAME_DB="a1638637_fiverr";
    $USER_DB ="a1638637_afif";
    $PWD_DB="azerty2012";
     $connect = mysql_connect($HOST_DB,$USER_DB,$PWD_DB) or die();
      $db=mysql_select_db($NAME_DB);
      }
    //Registration part  
 function register($email,$login,$pass){
 $verif_email= $this->exists($email,0);
 $verif_user = $this->exists($user,1);
 if(!$verif_email && !$verif_user){
                               $requete_insert_tem  ="INSERT INTO member (`email`,`user`,`password`) VALUES ('".$email."', '".$login."','".$pass."'); ";
                               mysql_query($requete_insert_tem) or die();
                               return true;
                                }
else return false;                              



 }

function exists($attribut,$number){
if($number==0){
$Log_query=mysql_query("SELECT * FROM  member WHERE email ='$attribut'") or die(mysql_error());
if ($Log_query == true && mysql_num_rows($Log_query) >0)return true;
else return false;                  
}
if($number==1){
$Log_query=mysql_query("SELECT * FROM  member WHERE user ='$attribut'") or die(mysql_error());
if ($Log_query == true && mysql_num_rows($Log_query) >0)return true;
else return false;  
}
}

//login part
function login($attr, $pass){
 $verif_email= $this->exists($attr,0);
 $verif_user = $this->exists($attr,1);
 if($verif_email){
 $Log_query=mysql_query("SELECT * FROM  member WHERE email ='$attr' AND password = '$pass'") or die(mysql_error());
 if ($Log_query == true && mysql_num_rows($Log_query) >0) {
                        $p=0;
                          while ($Res_user = mysql_fetch_array($Log_query) ) {
                        $marques[$p] = $Res_user;
                        $p++;
                        }
                        }
                return $marques;
 }
 if($verif_user){
 $Log_query=mysql_query("SELECT * FROM  member WHERE user ='$attr' AND password = '$pass'") or die(mysql_error());
 if ($Log_query == true && mysql_num_rows($Log_query) >0) {
                        $p=0;
                          while ($Res_user = mysql_fetch_array($Log_query) ) {
                        $marques[$p] = $Res_user;
                        $p++;
                        }
                        }
                return $marques;
 }
 return null;


}

function getCategories(){
$Log_query=mysql_query("SELECT distinct(categorie) FROM  video ") ;
if ($Log_query == true && mysql_num_rows($Log_query) >0) {
                        $p=0;
                          while ($Res_user = mysql_fetch_array($Log_query) ) {
                        $marques[$p] = $Res_user;
                        $p++;
                        }
                        }
                return $marques;
}

function getVideos(){
$Log_query=mysql_query("SELECT * FROM  video ") ;
if ($Log_query == true && mysql_num_rows($Log_query) >0) {
                        $p=0;
                          while ($Res_user = mysql_fetch_array($Log_query) ) {
                        $marques[$p] = $Res_user;
                        $p++;
                        }
                        }
                return $marques;




}

}
?>

i have this error : Fatal error: Cannot redeclare class connexion in /home/a1638637/public_html/Sql.php on line 2 . but i didn't redeclare the class connexion!!
i think that the problem is in the right.php file because:

  • the right part doesn't work
  • the error appears there
    to fix this error i need to know
  • what is the error?
  • how can i fix it?
Was it helpful?

Solution

You need to use require_once instead of include. The SQl.php file is read and parsed twice and therefore it tries to redeclare an already declared class. With require_once this won't happen.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top