0

I have downloaded this project somewhere from internet & tried to access the pages which is good. but after login in to the desire profile i am only getting this kind of lots of error which i am unable to solve. can anybody help me

Screenshots of error page. enter image description here

Pages which gives error

friends.php

<?php
if(!isset($_SESSION)){
    session_start();
}
include("profilesql.php");
$result = mysql_query("SELECT * FROM addfriends where meid='$_SESSION[stuid]' ");
while($row = mysql_fetch_array($result))
  {
$uid1[$i] = $row["friendid"];
$i++;
  }

 $acrec1 = mysql_query("SELECT * FROM addfriends WHERE userid='$uid1[1]'");

while($row = mysql_fetch_array($acrec2))
  {
    $img1[0]=  $row["image"];
  }

  $acrec2 = mysql_query("SELECT * FROM addfriends WHERE userid='$uid1[2]'");

while($row = mysql_fetch_array($acrec2))
  {
    $img1[1]=  $row["image"];
  }

  $acrec3 = mysql_query("SELECT * FROM profile WHERE userid='$uid1[3]' ");

while($row = mysql_fetch_array($acrec3))
  {
    $img1[2]=  $row["image"];
  }

  $acrec4 = mysql_query("SELECT * FROM profile WHERE userid='$uid1[4]' ");
while($row = mysql_fetch_array($acrec4))
  {
    $img1[3]=  $row["image"];
  }
  ?>

profile.php enter image description here

<?php
include("header.php");
include("profilesql.php");
include("friends.php"); 
?>
<center>
<div class=container>
<div class=container>

<!-- head --><!-- navigation menu -->
<?php include("head.php"); ?>
<?php
include("menu.php"); 
$result = mysql_query("SELECT * FROM profile ORDER BY RAND()");
$i=0;
while($row = mysql_fetch_array($result))
  {
      if($row["userid"] != $_SESSION["stuid"] )
{ 
$img[$i] = $row["image"];
$uid[$i] = $row["userid"];
$i++;
  }
  }
  $result = mysql_query("SELECT * FROM stuacc where id");  

$strec = mysql_query("SELECT * FROM stuacc WHERE email='$_SESSION[logid]' ");

while($row = mysql_fetch_array($strec))
  {
$_SESSION["stuid"] =  $row["id"];

  }

$colrec = mysql_query("SELECT * FROM profile WHERE userid='$_SESSION[stuid]' ");

while($row = mysql_fetch_array($colrec))
  {
$cname = $row["coluni"];
  }

$acrec1 = mysql_query("SELECT * FROM stuacc WHERE id='$uid[0]' ");

while($row = mysql_fetch_array($acrec1))
  {
      $stid1 = $row["id"];
$name1 = $row["firstname"];
$gen1= $row["iam"];
  }

  $acrec2 = mysql_query("SELECT * FROM stuacc WHERE id='$uid[1]' ");

while($row = mysql_fetch_array($acrec2))
  {
          $stid2 = $row["id"];
$name2 = $row["firstname"];
$gen2= $row["iam"];
  }

  $acrec3 = mysql_query("SELECT * FROM stuacc WHERE id='$uid[2]' ");

while($row = mysql_fetch_array($acrec3))
  {
          $stid3 = $row["id"];
$name3 = $row["firstname"];
$gen3= $row["iam"];
  }

  $acrec4 = mysql_query("SELECT * FROM stuacc WHERE id='$uid[3]' ");

while($row = mysql_fetch_array($acrec4))
  {
          $stid4 = $row["id"];
$name4 = $row["firstname"];
$gen4= $row["iam"];
  }
?>


<div style="padding: 10px; text-align: left;">
<!-- body  content -->

    <table width="100%" height="382" border="0" >
  <tr>
    <td width="16%" rowspan="9" align="left" valign="top" bgcolor="#CCCCCC"><?php include("profileleft.php"); ?></td>
    <td width="55%" rowspan="9" valign="top"><table width="100%" border="1">
        <tr>
          <th scope="col"><strong>Welcome, <?php echo $_SESSION["logid"]; ?></strong></th>
          </tr>
        <tr>
          <td><strong>Number of visitors:
              <?php
if(isset($_SESSION['views']))
 $_SESSION['views']=$_SESSION['views']+1;
   else
 $_SESSION['views']=1;
 echo $_SESSION['views']; 
 ?>
          </strong></td>
          </tr>
        <tr>
          <td><strong>College Name : </strong><b><?php echo $cname ; ?></b></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
      <table width=100%>

        <tr valign=top align=center>
          <td colspan="4" align="left"><strong>Request Friends</strong></td>
          </tr>
        <tr valign=top align=center>
            <td><a href="friendsprofile.php?fid=<?php echo $stid1 ; ?>"><img src="<?php echo $img[0] ; ?>" width="100" height="150" border="0" alt=""><br />
             <?php echo $name1 ; ?><br />

            </a><br></td>
            <td><a href="friendsprofile.php?fid=<?php echo $stid2 ; ?>""><img src="<?php echo $img[1] ; ?>" width="100" height="150" border="0" alt=""><br />
              <?php echo $name2 ; ?>
            </a><br></td>
            <td><a href="friendsprofile.php?fid=<?php echo $stid3 ; ?>""><img src="<?php echo $img[2] ; ?>" width="100" height="150" border="0" alt=""><br />
             <?php echo $name3 ; ?>
            </a><br></td>
            <td><a href="friendsprofile.php?fid=<?php echo $stid4 ; ?>""><img src="<?php echo $img[3] ; ?>" width="100" height="150" border="0" alt=""><br />
              <?php echo $name4 ; ?>
            </a><br></td>

        </tr>
        </table>
      <table width="100%" border="1">
      <tr>
        <th colspan="2" scope="col"><br />            &nbsp;     <?php echo $fname. " " . $lname; ?></th>
      </tr>
      <tr>
        <td colspan="2"><strong>College Name : </strong><b><?php echo $cname ; ?></b></td>
      </tr>
      <tr>
        <td width="51%"><strong>City :<?php echo $_GET["fmes"]; ?></strong></td>
        <td width="49%"><?php echo $city; ?></td>
        </tr>
      <tr>
        <td height="23"><strong>State:</strong></td>
        <td><?php echo $state; ?></td>
        </tr>
      <tr>
        <td height="23"><strong>Pincode:</strong></td>
        <td><?php echo $pincode; ?></td>
        </tr>
      <tr>
        <td height="23"><strong>Country:</strong></td>
        <td><?php echo $country; ?></td>
        </tr>
      </table></td>
      <td height="23" colspan="2" background="" bgcolor="#CCCCCC"><strong><u>My friends</u></strong></td>
  </tr>
  <tr>
    <td width="14%" height="23" bgcolor="#CCCCCC" align="center" valign="top"><img src="<?php echo $img[0] ; ?>" alt="" width="71" height="53" /></td>
    <td width="15%" height="23" bgcolor="#CCCCCC" align="center" valign="top"><img src="<?php echo $img[1] ; ?>" alt="" width="71" height="53" /></td>
  </tr>
  <tr>
    <td height="4" align="center" valign="top" bgcolor="#CCCCCC"><img src="<?php echo $img[2] ; ?>" alt="" width="71" height="53" /><br />      
      <br /></td>
    <td height="4" bgcolor="#CCCCCC" align="center" valign="top"><img src="<?php echo $img[3] ; ?>" alt="" width="71" height="53" /></td>
  </tr>
  <tr>
    <td height="21" colspan="2" align="center" valign="top" bgcolor="#CCCCCC"><strong><a href="viewall.php">View all</a></strong></td>
  </tr>
  <tr>
    <td height="36" bgcolor="#CCCCCC" align="center"><img src="images/alosious.jpg" alt="" width="77" height="75" /></td>
    <td height="36" bgcolor="#CCCCCC" align="center"><img src="images/alvas.jpg" alt="" width="96" height="96" /></td>
  </tr>
  <tr>
    <td height="36" bgcolor="#CCCCCC" align="center"><img src="images/canara.jpg" alt="" width="78" height="78" /></td>
    <td height="36" bgcolor="#CCCCCC"><img src="images/dhavala.jpg" alt="" width="96" height="74" /></td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#CCCCCC" align="center"><strong>View all</strong></td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#CCCCCC"><strong><u>Advertisement</u></strong></td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#CCCCCC" align="center"  ><a href="http://www.admissionopen.com/" ><img src="images/advt.jpg" width="173" height="185" /></a></td>
  </tr>
  </table>


</div>
<center>
<?php include("footer.php"); ?>
SuRaj Creator
  • 945
  • 1
  • 9
  • 25
  • clearly your error shows that `$_SESSION[stuid]` is not set. try to make it as `$_SESSION['stuid']` – Satish Sharma Feb 19 '14 at 04:51
  • 1
    Even though you are checking if session is not set, `session_start();` must go on top. You would then set your condition thereafter, and not the way you're doing it now. Plus, it must be inside ALL your files. – Funk Forty Niner Feb 19 '14 at 04:52
  • Check this tips http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index – Vijayakumar Selvaraj Feb 19 '14 at 04:56
  • Are you sure that project doesn't have a newer version? They use mysql_query among other crappy coding practices (`ORDER BY RAND()`, using `SELECT *` and only using one column, not escaping anything that goes into the queries, the first `while($row = mysql_fetch_array($acrec2))` should be `while($row = mysql_fetch_array($acrec1))`, etc). – Mike Feb 19 '14 at 04:57

2 Answers2

1

These are strict errors - errors that are not fatal, but are signs of unsafe code. Many are for missing array keys, meaning the array keys you are accessing are not defined. To stop the errors, before you access array keys that might not exist, you need to check if they are set. For example:

if($row["userid"] != $_SESSION["stuid"] )

becomes

if(!isset($_SESSION["stuid"] || $row["userid"] != $_SESSION["stuid"])

As for the undefined variable warnings, you need to either define the variables beforehand, or check whether they are set when accessing them. For your use, you can probably just define the unset one:

$uid1 = array();

Finally, you look to be accidentally using the wrong variable. The first while($row = mysql_fetch_array($acrec2)) should be while($row = mysql_fetch_array($acrec1)).

A lot of the code here is very inefficient though. For example, you are running multiple queries for what can be done in one. Consider using a WHERE ... IN query for getting all "friends", rather than doing one query per user.

Adam
  • 2,851
  • 1
  • 20
  • 20
0

Enclose you script in the if statement:

friends.php

<?php
if(!isset($_SESSION)){
    session_start();

    include("profilesql.php");
    $result = mysql_query("SELECT * FROM addfriends where meid='$_SESSION[stuid]' ");
    while($row = mysql_fetch_array($result))
    {
        $uid1[$i] = $row["friendid"];
        $i++;
    }

    $acrec1 = mysql_query("SELECT * FROM addfriends WHERE userid='$uid1[1]'");

    while($row = mysql_fetch_array($acrec2))
    {
        $img1[0]=  $row["image"];
    }

    $acrec2 = mysql_query("SELECT * FROM addfriends WHERE userid='$uid1[2]'");

    while($row = mysql_fetch_array($acrec2))
    {
        $img1[1]=  $row["image"];
    }

    $acrec3 = mysql_query("SELECT * FROM profile WHERE userid='$uid1[3]' ");

    while($row = mysql_fetch_array($acrec3))
    {
        $img1[2]=  $row["image"];
    }

    $acrec4 = mysql_query("SELECT * FROM profile WHERE userid='$uid1[4]' ");
    while($row = mysql_fetch_array($acrec4))
    {
        $img1[3]=  $row["image"];
    }
}
?>
Vainglory07
  • 5,073
  • 10
  • 43
  • 77
  • it sorted in friends.php as your code i put. but still has error in profile.php. see my updated screen shot which i am uploading – SuRaj Creator Feb 19 '14 at 05:20