0

Hello all, I am having a bit of an issue with a problem in my Web Dev Class. I am unable to get my "localhost" to pull up, it keeps giving me an error of; Parse error: syntax error, unexpected '<', expecting end of file in C:\xampp\htdocs\xampp\Chap19\Fig19_9.php on line 19. That line is correct, its a basic <h1> URL Description</h1>. Nothing else is on the line.
This is the actual exercise-
Write a PHP script that obtains a URL and its description from a user and stores the information into a database using MySQL. create and run a SQL script with a database named URLand a table named Urltable. the first field of the table should contain an actual URL, and the second, which is named description, should contain a description of the URL. Use www.deitel.com as the first URL, and input COOL Site! as its description. The ssecon URL should be www.php.net, and the description should be The Official PHP site. After each new URL is submitted, print the contents of the database in the table.

Here is what I have, about 3 days ago the professor changed up my orginal php work saying that we are using legacy code and now MySQL is MYSqli and proffered the new code. I barely knew enough before let alone now with this new stuff. It starts at; if ( !( $database = mysqli, and ends at mysqli_error() );
Blundering around in this work is a close assessment of what I am doing.

    <?php
            $query = "SELECT * FROM urltable";
            if ( !( $database = mysqli_connect( "localhost", "iw3htp", "password" ) ) )
         die( "<p>Could not connect to database</p>" );

      if ( !mysqli_select_db( $database, "URLs") )
         die( "<p>Could not open URL database</p>" );

      if ( !( $result = mysqli_query( $database, $query) ) )
      {
         print( "<p>Could not execute query!</p>" );
         die( mysqli_error() );
      }    

     while ( $row = mysqli_fetch_row( $result ) )
               print( "<tr><td>" . $row[ 0 ] . "</td><td>" . $row[ 1 ] . "</td></tr>" );
      mysqli_close( $database );

        <h1>URL Descriptions</h1> <table> <caption>Descriptions stored in the database</caption> <tr> <th>www.deitel.com</th> <th>Cool Site</th> </tr> <?php
            while ($row = mysql_fetch_assoc($result))
            {
                print("<tr>");
                    foreach ($row as $key => $value)
            {
                print("<td>$value</td>");
        }
            print("</tr>");
        }
                mysql_close( $database );
        ?> </table>

Also, do I save this as .php or put in an .html format. I tried both, however, none are working. I have my xampp Control Panel working and can access it via the cmd window.

2
Contributors
1
Reply
21
Views
1 Month
Discussion Span
Last Post by diafol
1

You have a slab of raw html in the middle of your php script. End php tag before this and open a new php tag after it. Php can't parse this. Also you must keep it in a .php file. It is working if you got the error msg.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.