Jump to content

mysqli to mysql error


candice

Recommended Posts

Hi, we are student's doing a web portal service. Initially we did all the codes in Mysqli, but now we need to change them to mysql. these are the problem we faced from the transitions.   

 

As you can see from the image, this is the correct result that we did in Mysqli

http://www.flickr.com/photos/75437207@N00/2859928462/

 

but after we change the codes to mysql, we did a little amendments, we successfully able to retrieve the personal information from the database.

http://www.flickr.com/photos/75437207@N00/2859099589/in/photostream/

 

But we still faced two problems.

 

- unable to retrieve the images

- under "who is in" they sld retrieve different name of staff from the database instead of the same keep repeating.

 

<this is the mysql code from where we changed and where the 2 problems are>

 


<?php 
session_start();
echo $name;
echo $staffid;
ob_start();
?>

<html>
<head>
<title>Staff Signage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">


<script type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>

<style type="text/css">
<!--
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #000000;
}
a:hover {
text-decoration: underline;
color: #333333;
}
a:active {
text-decoration: none;
}
-->
</style></head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('images/icons/rolloverProfile.jpg','images/icons/rolloverStatus.jpg','images/icons/rolloverStatusOut.jpg','images/icons/rollovereditImage.jpg')">
<!-- ImageReady Slices (main1.psd) -->
<table width="800" height="600" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
<tr>
	<td width="800" height="136"><?php include("include/header.php") ?></td>
  </tr>
<tr>
  <td width="800" height="438" valign="top" bgcolor="#FFFFFF">
        <table width="795" height="426" border="0">
          <tr>
            <td width="10" height="2"></td>
            <td width="762"></td>
            <td width="10"></td>
          </tr>
          <tr>
            <td height="409"></td>
            <td valign="top" bgcolor="#FFFFFF"><?php 
   
   			$staffid=$_SESSION['staffid'];

			require 'staffSql.php';
				//connect to the database

				//$mysql = mysql_connect($DATABASE_SERVER, $DATABASE_USERNAME, $DATABASE_PASSWORD) or die(mysql_error());
				mysql_connect ($dbhost, $dbusername, $dbuserpass);
				//select the database
				//mysql_select_db($DATABASE_NAME );
				mysql_select_db($dbname) or die('Cannot select database'); 
				//assign the data passed from Flex to variables
				$_SESSION['staffid'] = $staffid;

				//Query the database to see if the given username/password combination is valid.
				$query = "Select * from staff where staffid = '$staffid'";

				$result = mysql_query($query);	

   while ($row = mysql_fetch_array ($result)) {
		$name=$row['name'];
		$contactNo=$row['contactNo'];
		$ext=$row['ext'];
		$position=$row['position'];
		$photo=$row['photo'];
		$email=$row['email'];
		$status=$row['status'];
   			
   			echo'<table width="769" height="426" border="0">';
            echo'    <tr>';
            echo'      <td width="9" height="2"></td>';
            echo'      <td width="735"></td>';
            echo'      <td width="11"></td>';
            echo'    </tr>';
            echo'    <tr>';
            echo'      <td height="409"></td>';
            echo'      <td valign="top" bgcolor="#FFFFFF"><table width="726" height="516" border="0">';
            echo'        <tr>';
            echo'            <td width="1"> </td>';
            echo'            <td width="204" class="text"><span class="headerText">'.$name.'</span></td>';
            echo'            <td width="507"> </td>';
            echo'        </tr>';
            echo'          <tr>';
            echo'            <td height="210"> </td>';
            echo'            <td valign="top">';

		if($photo == NULL)
		{
			echo '<div align="left"><img src ="images/noImage.jpg" alt="" width="200" height="200" align="middle"/></div>';
		}
		else{
			echo'<div align="left"><img src ="'.$photo.'" alt="" align="middle"/></div>';

		}
		echo'</td>';
            echo'           <td valign="top"><table width="506" border="0"  cellspacing="0">';
            echo'                <tr>';
            echo'                  <td height="24" bgcolor="#437aa6"><span class="contentHeader">  Welcome!</span></td>';
            echo'                </tr>';
            echo'                <tr>';
            echo'                  <td width="538" valign="top" bgcolor="#FAFAF5">';

}		

   
		//displaying the words
		echo'<table width="480" border="0">';
          
            echo'<tr>';
            echo'  <td height = "1"></td>';
            echo"  <td valign='top'><div align='justify'><span class='contentText'>Welcome to staffSignage's web portal. Here you can view the status of your fellow colleagues, change your in/out of office status, and edit your profile. Let's get you started by clicking on some of the icons below!</span><br />";
            echo'  </div></td>';
           echo' </tr>';
         echo' </table>';
		?>


		   <table width="359" height="50" border="0" align="center">  
             <tr>  
               <td width="16"></td>
            <td width="82"><div align="center"><a href="password.php"><img src="images/icons/finaleditpassword.jpg" width="59" height="56" border="0" id="Image1" onMouseOver="MM_swapImage('Image1','','images/icons/rolloverPass.jpg',1)" onMouseOut="MM_swapImgRestore()" /><br />
                   <span class="text">Change <br /> 
                   Password</span></a><br />
               </div></td> 
              <td width="71"><div align="center"><a href="editProfile.php"><img src="images/icons/finaleditprofile.jpg" alt="" width="59" height="54" border="0" id="Image2" onMouseOver="MM_swapImage('Image2','','images/icons/rolloverProfile.jpg',1)" onMouseOut="MM_swapImgRestore()" /><br />
                      <span class="text">Edit<br />
                        Profile</span></a><br />
              </div></td>
              <td width="96"><div align="center">
                <?php
		if ($status == In){?>
                <a href="editStatus.php"><img src="images/icons/finalgreen.jpg" width="59" height="54" border="0" id="Image32" onMouseOver="MM_swapImage('Image32','','images/icons/rolloverStatus.jpg',1)" onMouseOut="MM_swapImgRestore()" />
                <?php }else if($status == Out){?>
                <a href="editStatus.php"><img src="images/icons/finalred.jpg" width="59" height="54" border="0" id="Image3" onMouseOver="MM_swapImage('Image3','','images/icons/rolloverStatusOut.jpg',1)" onMouseOut="MM_swapImgRestore()"/>
                <?php }
		?>
                <br />
                <span class="text">Change  Status<br />
                </span></a> <span class="text"> Status: <?php echo $status?> </span></div></td>
              <td width="72"><div align="center"><a href="editImage.php"><img src="images/icons/editImage.jpg" width="59" height="54" border="0" id="Image31" onMouseOver="MM_swapImage('Image31','','images/icons/rollovereditImage.jpg',1)" onMouseOut="MM_swapImgRestore()"/></a><a href="editImage.php"><br />
                      <span class="text">Upload<br />
                Photo</span></a></div></td>  
            </tr>  
         </table> 



		<?php 

            

		echo'                  </p></td>';
            echo'                </tr>';
            echo'            </table></td>';
            echo'          </tr>';
            echo'          <tr>';
            echo'            <td> </td>';
            echo'            <td valign="top"><table width="200" height="311" border="0"  cellspacing="0">';
            echo'                <tr>';
            echo'                  <td height="24" bgcolor="#437aa6"><span class="text">  <span class="contentHeader">Personal Information</span></span></td>';
            echo'                </tr>';
            echo'                <tr>';
            echo'                  <td width="198" height="287" valign="top" bgcolor="#FAFAF5"><p><span class="contentText"><strong>  Name:</strong><br />';
            echo'                      '.$name.'<br />';
            echo'                    <br />';
            echo'                    <strong>  Contact Number:<br />';
            echo'                    </strong>  '.$contactNo.'</span><br />';
            echo'                    <br />';
            echo'                    <span class="text">  Email:<br />';
            echo'                    </span><span class="contentText">  '.$email.'</span><span class="text"><br />';
            echo'                        <br />';
            echo'                          Ext:<br />';
            echo'                        </span><span class="contentText">  '.$ext.'</span><span class="text"><br />';
            echo'                          <br />';
            echo'                            Position:<br />';
            echo'                         </span><span class="contentText">  '.$position.'</span><span class="text"><br />';
            echo'                            </span><br />';
            echo'                  </p></td>';
            echo'                </tr>';
            echo'            </table></td>';
            echo'            <td valign="top">
		<table width="507" border="0"  cellspacing="0">';
            echo'                <tr>';

           echo'                   <td height="24" bgcolor="#437aa6"><span class="text">  <span class="contentHeader">Who is In?</span></span></td>';
            echo'                </tr>';
            echo'                <tr>';



            echo'  <td width="514" height="287" valign="top" bgcolor="#FAFAF5">';
        //display the teachers who are in
		echo' <div style="height: 282px; width: 510px; overflow: auto;"> 
		<table width="310" height="246" border="0">';
            echo'<tr>';
            echo'  <td height="2"></td>';
            echo'  <td></td>';
            echo'  </tr>';

		echo'<tr>';
            echo'  <td></td>';
            echo'  <td>';

		//DISPLAYING THOSE TEACHERS WHOSE STATUS IS IN



				//assign the data passed from Flex to variables
				//$_SESSION['staffid'] = $staffid;

				//Query the database to see if the given username/password combination is valid.
				$query = "Select photo, name, staffid from staff WHERE staffid NOT IN('admin') and status = 'In' order by name ASC";

				$result = mysql_query($query);	

   while ($row = mysql_fetch_array ($result)) {
		$staffid=$row['staffid'];

		if($photo == NULL)
					{
					echo '<img src ="images/noImage.jpg" width="50" height="50"/>  ';
					echo '<span class = "contentText"><b>'.$name.'</b></span><br><div class="hr"><hr/></div>';

					}//close of if
				else{
					echo '<img src ="'.$photo.'"width="50" height="50"/>  ';
					echo '<span class = "contentText"><b>'.$name.'</b></span><br><div class="hr"><hr/></div>';

				};//close of else
			}

		echo'</td>';
            echo'  </tr>';
           
          echo'</table>';



			//$stmt->close();
			//$mysqli->close();


            echo'                      </p>';
            echo'              </td> </tr>';
            echo'            </table></td>';
            echo'          </tr>';
            echo'      </table></td>';
            echo'      <td></td>';
            echo'    </tr>';
            echo'  </table>';

   		
   
?>   <!--HERE--></td>
            <td></td>
          </tr>
        </table>
      </td>
</tr>
<tr>
	<td width="800" height="26">	<?php include("include/footer.php") ?>		</td>
</tr>
</table>
<!-- End ImageReady Slices -->



</body>
</html>
<?php ob_flush(); ?>

 

 

Link to comment
Share on other sites

You'll need to define the variables $photo, $name within your second while loop, otherwise the data used from the first loop will be used and thus you get the same results repeated over and over.

chnage

while ($row = mysql_fetch_array ($result)) {
		$staffid=$row['staffid'];

		if($photo == NULL)

to

while ($row = mysql_fetch_array ($result))
{
		$staffid = $row['staffid'];
		$photo = $row['photo'];
		$name = $row['name']

		if($photo == NULL)

 

As for why your images are not displaying change any instance of

if($photo == NULL)

to

if(!empty($photo))

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.