2014-02-19 5 views
0

나는이 프로젝트를 인터넷 어딘가에서 다운로드 했으니 &은 좋은 페이지에 액세스하려고 시도했다. 하지만 욕망 프로파일에 로그인 한 후에는 내가 해결할 수없는 오류가 많이 발생합니다. 아무도 나를 도울 수로그인 후 PHP 정의되지 않은 색인 오류

오류 페이지의 스크린 샷. 오류를

friends.php을 제공 enter image description here

페이지

<?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"); ?> 
+0

는 분명 오류가'$ _SESSION은 [stuid]'설정되지 않았 음을 보여줍니다. '$ _SESSION [ 'stuid']' –

+1

으로 설정하려고 시도한다. 세션이 설정되지 않았는지 검사 중이지만'session_start();'가 맨 위에 있어야한다. 당신은 그때 당신이 지금하고있는 방식이 아니라 그 이후에 당신의 상태를 설정할 것입니다. 또한 모든 파일에 있어야합니다. –

+0

이 도움말을 확인하십시오. http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index –

답변

0

둘러싸 당신에게 스크립트를

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"]; 
    } 
} 
?> 
+0

그러면 profile.php에서 누락 된 내용은 무엇입니까 ?? –

+0

시도해 본 후에도 오류가 있습니까? – Vainglory07

+0

friends.php에서 코드로 정렬했습니다. 여전히 profile.php에 오류가 있습니다. 내가 업로드 한 내 업데이트 된 스크린 샷보기 –

1

이 엄격한 오류입니다 - 치명적인 아니지만, 징후 오류 안전하지 않은 코드 많은 것은 누락 된 배열 키에 대한 것으로, 액세스중인 배열 키가 정의되지 않았 음을 의미합니다. 오류를 중지하려면 존재하지 않을 수도있는 배열 키에 액세스하기 전에 설정되어 있는지 확인해야합니다. 예를 들어 :

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

가 정의되지 않은 변수 경고에 관해서는

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

이되고, 당신은 사전에 변수를 정의하거나 액세스 할 때이 설정되어 있는지 확인 중 하나가 필요합니다. 사용하기 위해 설정하지 않은 것을 정의 할 수 있습니다.

$uid1 = array(); 

마지막으로 실수로 잘못된 변수가 사용 된 것 같습니다. 첫 번째 while($row = mysql_fetch_array($acrec2))while($row = mysql_fetch_array($acrec1))이어야합니다.

여기 코드가 많이 비효율적입니다. 예를 들어, 하나에서 수행 할 수있는 작업에 대해 여러 개의 쿼리를 실행 중입니다. 사용자 당 하나의 쿼리를 수행하는 대신 모든 "친구"를 얻으려면 WHERE ... IN query을 사용하는 것이 좋습니다. if 문에서

관련 문제