2014-02-22 32 views
0

我正在做社交網絡類型項目,我也在重申一些項目。在這裏我得到第15行,我並不能解決不確定的指數錯誤.. &php未定義的索引錯誤的配置文件

profileleft.php

<SCRIPT language="JavaScript1.2"> 
function openwindow() 
{ 
    window.open("chat/mychat.php","mywindow","menubar=1,resizable=1,width=350,height=750"); 
} 
</script> 
<br /><center> 
<a href="profile.php"> 
<?php if(isset($usimg)) { ?> 
    <img src="<?php echo $usimg;?>" alt="" width="90" height="106" /> 
    <?php } ?> 
</a><br> 
     <font color="#000099"><strong><?php echo $fname ." ".$lname; ?></strong><br /> 
    <a href="changepic.php">Change Picture</a> 
</center> 
    <hr /> 
    <img src="images/icon/profile.gif" width="23" height="22" align="absmiddle" /> <a href="editprof.php" >Edit Profile</a><br /> 
<a href="msg.php"><img src="images/icon/messages.gif" width="27" height="24" align="absmiddle" /> Scrap</a><br /> 
     <a href="answer.php"><img src="images/icon/answers.png" width="25" height="24" align="absmiddle" /> Answers </a><br /> 
<a href="viewuploads.php"><img src="images/uploads.png" alt="" width="27" height="26" align="absmiddle" /></a><a href="viewuploads.php">View Uploads</a><br /> 

     <a href="javascript: openwindow()" ><img src="images/chat.png" width="25" height="24" align="absmiddle" /> Chat </a> 
<p>&nbsp;</p> 

profile.php 在本節我沒有得到我的照片

<?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(isset($row["userid"]) && $row["userid"] != $_SESSION["stuid"]) 
{ 
$img[$i] = $row["image"]; 
$uid[$i] = $row["userid"]; 
$city[$i] = $row['city']; 
$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"><?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> 
     <?php if(isset($cname)) { ?> <td><strong>College Name : </strong><b><?php echo $cname ; ?></b></td><?php } ?> 
     </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> 
     <?php if(isset($cname)) { ?><td colspan="2"><strong>College Name : </strong><b><?php echo $cname ; ?></b></td> <?php } ?> 
     </tr> 
     <tr> 
     <?php if(isset($fmes)) { ?><td width="51%"><strong>City :<?php echo $_GET["fmes"]; ?></strong></td><?php } ?> 

     </tr> 
     <tr> 
     <td height="23"><strong>State:</strong></td> 
     <?php if(isset($state)) { ?><td><?php echo $state; ?></td><?php } ?> 
     </tr> 
     <tr> 
     <td height="23"><strong>Pincode:</strong></td> 
     <?php if(isset($pincode)) { ?><td><?php echo $pincode; ?></td><?php } ?> 
     </tr> 
     <tr> 
     <td height="23"><strong>Country:</strong></td> 
     <?php if(isset($country)) { ?><td><?php echo $country; ?></td><?php } ?> 
     </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"); ?> 

profile

friendsprofile.php

<?php 
session_start(); 
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"); 
if($_GET["addf"]=="t") 
    { 
     $sql="INSERT INTO addfriends(meid,friendid) VALUES 
    ('$_SESSION[stuid]','$_GET[fid]')"; 
     if (!mysql_query($sql,$con)) 
      { 
       die('Error: ' . mysql_error()); 
      } 
    } 
$result = mysql_query("SELECT * FROM stuacc where id=$_GET[fid]"); 
while($row = mysql_fetch_array($result)) 
    { 
     $fname = $row["firstname"]; 
     $lname = $row["lastname"]; 
    } 

$result1 = mysql_query("SELECT * FROM profile where userid=$_GET[fid]"); 

while($row = mysql_fetch_array($result1)) 
    { 
     $usimg = $row["image"]; 
     $city = $row["city"]; 
     $state = $row["state"]; 
     $pincode = $row["pincode"]; 
     $country= $row["country"]; 
     $hschoool= $row["hschool"]; 
     $coluni= $row["coluni"]; 
     $course= $row["course"]; 
    } 

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

while($row = mysql_fetch_array($colrec)) 
    { 
     $cname = $row["coluni"]; 
    } 
$result = mysql_query("SELECT * FROM profile ORDER BY RAND()"); 
$i=0; 
while($row = mysql_fetch_array($result)) 
    { 

     $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="19%" rowspan="10" align="left" valign="top" bgcolor="#CCCCCC"> 

    <br /><center> 
    <a href="profile.php"><img src="<?php echo $usimg;?>" alt="" width="90" height="106" /></a><br> 
    <font color="#000099"><strong> 
    </strong></center> 
    <hr /> <a href="friendsprofile.php?fid=<?php echo $_GET["fid"]; ?>&fmes=Added as friend&addf=t"> 
    <img src="images/icon/profile.gif" width="23" height="22" align="absmiddle" /> Add As Friend</a><br /> 
    <p>&nbsp;</p> 


</td> 
<td width="50%" rowspan="10" valign="top"><table width="100%" border="1"> 
    <tr> 
    <th colspan="2" scope="col"><br />   &nbsp;  <?php echo $fname. " " . $lname; ?></th> 
</tr> 
<tr> 
<td colspan="2"><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> 
<?php if(isset($cname)) { ?><td colspan="2"><strong>College Name : </strong><b><?php echo $cname ; ?></b></td><?php } ?> 
</tr> 
<tr> 
<?php if(isset($fmes)) { ?><td width="51%"><strong>City :<?php echo $_GET["fmes"]; ?></strong></td><?php } ?> 
<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> 
<tr> 
<td height="23"><strong>High Shcool:</strong></td> 
    <td><?php echo $hschoool; ?></td> 
</tr> 
<tr> 
<td height="23"><p><strong>College/Univesity:</strong></p></td> 
    <td><?php echo $coluni; ?></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>View all</strong></td> 
    </tr> 
    <tr> 
    <td height="21" colspan="2" align="left" valign="top" bgcolor="#CCCCCC"><strong><u>Colleges</strong></td> 
    </tr> 
    <tr> 
    <td height="36" bgcolor="#CCCCCC" align="center" ><img src="imagesCALAZIBU.jpg" alt="" width="71" height="53" /></td> 
    <td height="36" bgcolor="#CCCCCC" align="center" ><img src="imagesCALAZIBU.jpg" alt="" width="71" height="53" /></td> 
    </tr> 
    <tr> 
    <td height="36" bgcolor="#CCCCCC" align="center" ><img src="imagesCALAZIBU.jpg" alt="" width="71" height="53" /></td> 
    <td height="36" bgcolor="#CCCCCC" align="center" ><img src="imagesCALAZIBU.jpg" alt="" width="71" height="53" /></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">&nbsp;</td> 
</tr> 
</table> 


</div> 
<center> 
<?php include("footer.php"); ?> 
+1

正確編碼'$ _GET [ 「ADDF」]'可能沒有設置,所以檢查它是否設置爲 - >'if(isset($ _ GET [「addf」])&& $ _GET [「addf」] ==「t」)''。你也會想用你的其他變量 - >'$ _SESSION [stuid]','$ _GET [fid]'等來做到這一點。另外,你可以直接在你的查詢中插入用戶值, '...userid = $ _ GET [fid]' – Sean

回答

2

,是因爲你的$產生的誤差_GET [「addf」]沒有設置爲任何仍在檢查其值的東西。所以它的未定義索引錯誤。

而是當前行,如果你把

if(isset($_GET["addf"]) && $_GET["addf"]=="t") 

第15行,它會檢查其設定的,如果它等於牛逼然後將遵循它,如果條件。祝你好運這個&記得檢查變量是否索引,然後纔會使用它,每當你得到未定義的錯誤。

+0

感謝Aniket ..我還有一個小問題是,在friendprofile個人資料圖片來臨,但罰款我自己的個人資料,它沒有顯示任何圖片..我再次更新我的問題,並張貼該代碼 –

+0

張貼代碼:) –

+0

我已經發布了profile.php的代碼 –

-1

試試這個

$sql="INSERT INTO addfriends(meid,friendid) VALUES 
('".$_SESSION['stuid']."','".$_GET[fid]."')"; 

,因爲您的會話變種必須是「或」 ,您可以用if(isset($_GET["addf"]))或使用檢查VAR‘@’如@$_GET["addf"]

+0

但是問題仍然是一樣的..看到我發佈錯誤 –

+0

哦,回答更新 –

1
Here i am getting undefined index error on line 15 which i cant solve.. 

代碼的15號線有:

if($_GET["addf"]=="t") 

你樂呵呵地檢查它的沒有檢查它的存在

你可以這樣做(並有習慣):

if(isset($_GET["addf"]) && $_GET["addf"]=="t") 

你也可以關閉通過以下的告示,但在未來,你會得到性能命中,這是不是一個好練習也懶。

if(@$_GET["addf"]=="t") 

你寫的也是這個:

<hr /> <a href="friendsprofile.php?fid=<?php echo $_GET["fid"]; ?>&fmes=Added as friend&addf=t"> 

注意fmes空間,他們必須使用urlencode()

<hr /> <a href="friendsprofile.php?fid=<?php echo $_GET["fid"]; ?>&fmes=<?php echo urlencode("Added as friend"); ?>&addf=t">