-2

I want to display product details in php page that is stored in mysql database. my php page is as follows:

 <?phpinclude 'databaseconfile.php';
    $sql = "select * from book";
    $result = mysql_query($sql);
    ?>
    <html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
        <title>Shop | ShareMyBook</title>
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <link href="css/font-awesome.min.css" rel="stylesheet">
        <link href="css/prettyPhoto.css" rel="stylesheet">
        <link href="css/animate.css" rel="stylesheet">
        <link href="css/main.css" rel="stylesheet">
        <link href="css/responsive.css" rel="stylesheet">     
        <link rel="shortcut icon" href="images/ico/favicon.ico">
        <link rel="apple-touch-icon-precomposed" sizes="144x144" href="images/ico/apple-touch-icon-144-precomposed.png">
        <link rel="apple-touch-icon-precomposed" sizes="114x114" href="images/ico/apple-touch-icon-114-precomposed.png">
        <link rel="apple-touch-icon-precomposed" sizes="72x72" href="images/ico/apple-touch-icon-72-precomposed.png">
        <link rel="apple-touch-icon-precomposed" href="images/ico/apple-touch- icon-57-precomposed.png">
    </head>
    <body>
    <div class="col-sm-4">
        <div class="product-image-wrapper">
            <div class="single-products">
                <div class="productinfo text-center">
                    <?phpwhile ($row = mysql_fetch_array($result))
                    {?>
                    <img src="images/home/" alt="" />
                    <h2><?php echo $row['Book_Name']; ?></h2>
                    <p>Book 10</p>
                    <?php}?>
                </div>
                <div class="product-overlay">
                    <div class="overlay-content">
                        <h2>Price</h2>
                        <p>Book 10</p>
                        <a href="#" class="btn btn-default view-item"><i class="glyphicon glyphicon-eye-open"></i>view Book</a>
                    </div>
                </div>

            </div>
            <div class="choose">
                <ul class="nav nav-pills nav-justified">
                    <li><a href="#"><i class="fa fa-plus-square"></i>Add to  wishlist</a></li>
                    <li><a href="#"><i class="fa fa-shopping-cart"></i>Add to  cart</a></li>
                </ul>
            </div>
        </div>
    </div>
    </body>
    </html>

when I try to run this page it says-Notice:Undefined variable:row on line 32, when it is already defined.

riya
  • 51
  • 1
  • 1
  • 6
  • 5
    a space needed here between php and while " – Maha Dev Dec 01 '15 at 05:25
  • Just so it's said... [Why shouldn't I use mysql\_\* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php?rq=1) – cHao Dec 01 '15 at 05:33
  • Use [pdo](http://a2znotes.blogspot.in/2014/09/introduction-to-pdo.html) instead of mysql_* functions because its deprecated. – RN Kushwaha Dec 01 '15 at 05:44

2 Answers2

1

The mistake is the space required between php and while loop. I already told you in comment. Replace this chunk of code:

Replace first line with:

<?php include 'databaseconfile.php';

and :

<div class="productinfo text-center">
   <?php while ($row = mysql_fetch_array($result))
     {?>
       <img src="images/home/" alt="" />
       <h2><?php echo $row['Book_Name']; ?></h2>
       <p>Book 10</p>
  <?php}?>
</div>
Maha Dev
  • 3,915
  • 2
  • 31
  • 50
0

The mistake is in first line.<?phpinclude 'databaseconfile.php';

You have to give space between php tag and include like this <?php include 'databaseconfile.php';