Jump to content

Recommended Posts

Hi Guys Im trying to make a php web page that will let me view my database i used this code below, i created the table but it doesn't show the values Please Help Me.......

 

 

 

 

 

 

 

<?php
$host = "localhost";
$username = "root";
$password = "";
$db_name="genetdb"; // Database name


// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// select record from mysql
$query="SELECT * FROM Products ";
$result=mysql_query($query);
?>

<table align="center" width="1080" border="10" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td colspan="5" bgcolor="#FFFFFF"><strong>Delete or Modify Data From Database</strong> </td>
</tr>

<tr>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Types</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Price</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Qty</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Size</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Origin</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Review</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Image</strong></td>
<td align="center" bgcolor="#FFFFFF"> </td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){


?>

<tr>
<td bgcolor="#FFFFFF"><? echo $rows['Id']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Types']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Price']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Qty']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Size']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Origin']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Review']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Image']; ?></td>
<td bgcolor="#FFFFFF"><a href="Delete_ac.php?id=<? echo $rows['id']; ?>">Delete</a></td>
<td bgcolor="#FFFFFF"><a href="Modify_ac.php?id=<? echo $rows['id']; ?>">Modify</a></td>
</tr>

<?php
// close while loop
}
?>

</table>

<?php

// close connection;
mysql_close();
return $result ;
?>
Edited by ignace
Added code tags
Link to comment
https://forums.phpfreaks.com/topic/278149-display-database/
Share on other sites

please help i want to display the login user but it cant be display, error!

heres my code:

 

login.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" type="text/css" href="css/login.css" />
<link rel="stylesheet" type="text/css" href="css/search.css" />
    <link type="text/css" href="css/menu.css" rel="stylesheet" />
    <link rel="stylesheet" href="css/blueberry.css" />
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/menu.js"></script>
<script type="text/javascript" src="js/jquery-1.4.2.min.js" ></script>
<script type="text/javascript" src="http://info.template-help.com/files/ie6_warning/ie6_script.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="js/jquery.blueberry.js"></script>
<title>What's Up HK</title>
</head>
<body>
<div class="container">
      <div class="header">
    <div class="pink_line"></div>
    <div id="social_links">
        <a href="#"><img src="images/social/fb.png" /></a>
        <a href="#"><img src="images/social/twitter.png" /></a>
        <a href="#"><img src="images/social/gplus.png" /></a>
        <a href="#"><img src="images/social/gmail.png"/></a>
        <a href="#"><img src="images/social/rss.png" /></a>
    </div>
        <div id="search"><!-- search -->
       <div id="tw-form-outer">
        <form action="" method="post" id="tw-form">    
            <input type="text" id="tw-input-text" name="query" value='search' onFocus="if(this.value=='search'){this.value='';}" onBlur="if(this.value==''){this.value='search';}" />
            <input type="submit" id="tw-input-submit" value="" />
        </form>
        </div>
        </div><!-- end .search -->
     </div><!-- end .header -->
      <div id="menu">
      <div id="menu">
            <ul class="menu">
            <li><a href="index.php"><span>Home</span></a></li>
            <li><a href="drink.php"><span>DRINK</span></a></li>
            <li><a href="eat.php"><span>EAT</span></a></li>
            <li><a href="contact.php"><span>Contact</span></a></li>
            </ul>
        </div>
        </div><!-- end .menu -->
        
        <div id="white_hr">
            <b>Login Account</b>
            <h4>Buy card and write/read reviews</h4>
            <dragon><img src="images/dragon.png" width="200" height="100" /></dragon>
        </div>
          <div class="content">
            <div id="login_form">
                <div align="center">
                <div style="width:300px; border: solid 1px #333333; margin-top:50px; " align="left">
                <div style="background-color:#333333; color:#FFFFFF; padding:3px; font-family:Arial, Helvetica, sans-serif;">
                    <b>BUY card | READ/WRITE reviews</b></div>
                <div style="margin:30px">
                <form name="form1" method="post" action="checklogin.php">
                <label>Username  :</label><input type="text" name="username" class="box"/><br /><br />
                <label>Password   :</label><input type="password" name="password" class="box" /><br/><br />
                <div align="center" style="margin-left:75px;">
                    <input type="reset" name="reset" value="Clear">
                        
                    <input type="submit" name="submit" value="Login">
                </div>
                <br />
                </form>
                    <div id="forgot_password">
                        <img src="images/lock.png" /> <a href="#">Forgot password?</a>
                    </div>
                    <div style="margin-top:5px;"></div>
                    <div id="signup">
                    <img src="images/reg.png" /> <a href="registration.php">Sign Up</a> for What's Up HongKong
                    </div>
               </div>
                </div>
                </div>
            </div>  
        </div><!-- end .content -->
  <div class="footer">
      <a href="#">HOME</a> | <a href="#">DRINK</a> | <a href="#">EAT</a> | <a href="#">CONTACT US</a>
  </div>
  <div class="footer_down">
      <space>© 2013 What's Up Hong Kong. All Rights Reserved. </space>
  </div><!-- end .footer -->
</div><!-- end .container -->       
</body>
</html>
 

checklogin.php

<?php
ob_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="whatsuphk"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("whatsuphk")or die("cannot select DB");

// Define $myusername and $mypassword
$username=$_POST['username'];
$password = trim($_POST['password']);
$password = md5($password);

// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

$sql="SELECT member_id FROM members WHERE username='$username' and password='$password'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['username']="username";
$_SESSION['password']="password";

header("location:index_user.php");
}
else {
header("location:login_page.php");
}
?>

 

index_user.php

<?php
    ob_start();
    require('connectDB.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" type="text/css" href="css/login.css" />
<link rel="stylesheet" type="text/css" href="css/search.css" />
    <link type="text/css" href="css/menu.css" rel="stylesheet" />
    <link rel="stylesheet" href="css/blueberry.css" />
<link type="text/css" href="css/drop.css" rel="stylesheet" />
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/menu.js"></script>
<script type="text/javascript" src="js/jquery-1.4.2.min.js" ></script>
<script type="text/javascript" src="http://info.template-help.com/files/ie6_warning/ie6_script.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="js/jquery.blueberry.js"></script>
<title>What's Up HK</title>
<script>
$(window).load(function() {
    $('.blueberry').blueberry();
});
</script>
</head>
<body>
<div class="container">
      <div class="header">
    <div class="pink_line"></div>
    <div id="social_links">
        <a href="#"><img src="images/social/fb.png" /></a>
        <a href="#"><img src="images/social/twitter.png" /></a>
        <a href="#"><img src="images/social/gplus.png" /></a>
        <a href="#"><img src="images/social/gmail.png"/></a>
        <a href="#"><img src="images/social/rss.png" /></a>
    </div>
        <div id="search"><!-- search -->
       <div id="tw-form-outer"><!-- search -->
        <form action="" method="post" id="tw-form">    
            <input type="text" id="tw-input-text" name="query" value='search' onFocus="if(this.value=='search'){this.value='';}" onBlur="if(this.value==''){this.value='search';}" />
            <input type="submit" id="tw-input-submit" value="" />
        </form>
        </div></div><!-- end .search -->
     </div><!-- end .header -->
      <div id="menu">
            <ul id="menu">
                <li> <a href="index.php">Home</a> </li>
                <li> <a href="drink.php">DRINK</a> </li>
                <li> <a href="eat.php">EAT</a> </li>
                <li> <a href="contact.php">Contact</a> </li>
            </ul>
        </div><!-- end .menu -->
        <div id="profile">
        Welcome,
        <name>
        <?php
        session_start();
        if(isset($_SESSION['fname'])) {

        echo "Welcome ".$_SESSION['fname']."";

        } else {        }
        ?></name>
         <br />
           <div id="navMenu" align="right">
            <ul>
            <li><a href="#"><font color="#333">Account ▼</font></a>
                <ul>
                <li><a href="#">View Profile</a></li>
                <li><a href="#">Edit Profile</a></li>
                <li><a href="#">Change Password</a></li>
                <li><a href="logout.php">Logout</a></li>
                </ul>
            </li>
            </ul>
        </div>
            </div>
        <div id="white_hr">
            <img src="images/contact.jpg" width="960" height="100" />
        </div>
          <div class="content">
            <div id="thumbnail_bg">

            </div>  
        </div><!-- end .content -->
  <div class="footer">
      <a href="#">HOME</a> | <a href="#">DRINK</a> | <a href="#">EAT</a> | <a href="#">CONTACT US</a>
  </div>
  <div class="footer_down">
      <space>© 2013 What's Up Hong Kong. All Rights Reserved. </space>
  </div><!-- end .footer -->
</div><!-- end .container -->       
</body>
</html>
 

Link to comment
https://forums.phpfreaks.com/topic/278149-display-database/#findComment-1431483
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.