0


I wanna recieve data from my MySQL database. First, here is the code:

<!DOCTYPE html> 
<html>
<head>
<meta charset="UTF-8">
<title>Filmliste</title>
<link href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" rel="stylesheet" type="text/css"/>
<script src="http://code.jquery.com/jquery-1.5.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js" type="text/javascript"></script>
</head> 
<body> 

<div data-role="page" id="page">
    <div data-role="content">   
        <ul data-role="listview">
            <?php
            $db = mysql_connect('12345.db.1and1.com', 'dbo42545132301', 'password', 'db4255412601') or die('Fail');
            $sql = "SELECT * FROM movielist";
            $ergebnis = mysql_query($sql);
            while($row = mysql_fetch_object($ergebnis))
            {
            ?>
            <li><a href="/detail.php"><?php $row->cover; ?>&nbsp;<?php $row->titel; ?></a></li>
            <?php

}

$mysql_close($db);
?>
        </ul>       
    </div>
</div>


</body>
</html>

If I load this in my browser, i get this: Fatal error: Call to undefined function: () in /homepages/44/d18421343246/htdocs/project/index.php on line 26

tshepang
  • 12,111
  • 21
  • 91
  • 136
Kitzng
  • 105
  • 1
  • 9
  • 2
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](http://j.mp/XqV7Lp). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. – Kermit Feb 16 '13 at 16:28
  • In addition to fixing the mysql_close(), and considering learning with a tutorial that teaches PDO or MySQLi with prepared statements; you might also want to change `cover; ?>` to `cover; ?>` and `titel; ?>` to `titel; ?>` – Mark Baker Feb 16 '13 at 16:28

2 Answers2

4

You are using $ before mysql_close()

$mysql_close($db);

Should be

mysql_close($db);

Note: Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated.

So use either PDO or MySQLi (IMO PDO is way to go)

Zoe
  • 27,060
  • 21
  • 118
  • 148
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
-1

1) $mysql_close($db); ----> "$" should not be there.

2) use echo before $row->cover and $row->titel ----> probably "titel" spelling is wrong

3) use mysql_select_db("db4255412601", $db); instead.

Code example ---

    <!DOCTYPE html> 
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Filmliste</title>
    <link href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" rel="stylesheet" type="text/css"/>
    <script src="http://code.jquery.com/jquery-1.5.min.js" type="text/javascript"></script>
    <script src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js" type="text/javascript"></script>
    </head> 
    <body> 

    <div data-role="page" id="page">
        <div data-role="content">   
            <ul data-role="listview">
                <?php
                $db = mysql_connect('12345.db.1and1.com', 'dbo42545132301', 'password') or die('Fail');

                mysql_select_db("db4255412601", $db);
                $sql = "SELECT * FROM movielist";
                $ergebnis = mysql_query($sql);

                while($row = mysql_fetch_object($ergebnis))
                { 
                ?>
                <li><a href="/detail.php"><?php echo $row->cover; ?>&nbsp;<?php echo $row->titel; ?></a></li>
                <?php

    }

    mysql_close($db);
    ?>
            </ul>       
        </div>
    </div>


    </body>
    </html>
Thamaraiselvam
  • 6,961
  • 8
  • 45
  • 71
Biswajit Maji
  • 869
  • 13
  • 23
  • WOW! It works! Thank you, Biswajit! Why it is it important to use mysql_select_db ? ($mysql_close($db); is wrong, but nevertheless it didn't work with this fix) – Kitzng Feb 17 '13 at 13:32
  • Hey, I have a second Question: I have changed all that you have marked. Now i want to load the data into the page. Maybe you have already seen that this will be a jQuery Mobile Page. The List is displayed, but there are no values. The number of list-items is correct (3), but without content. Do you know what can be wrong? – Kitzng Feb 17 '13 at 19:19