SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: PHP error

  1. #1
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Unhappy PHP error

    Hi all, i am getting error on line 18. tried to fixed it but i can't make it right can anyone help me out?

    Code PHP:
    <?php
    $connection = mysql_connect("localhost","root","");
    if($connection){
    die ("Cannot be connected to database" .mysql_error());
    }
     
    $db_select= mysql_select_db("wiget_corp");
    if($db_select) {
    	die("Database selection failed" .mysql_error())
    ?>
    <?php require_once("includes/functions.php");?>
    <?php require_once("includes/header.php");?>
       	<table id="structure">
        	<tr>
            	<td id="navigation">
    	<?php
    	$result = mysql_query("select * from subjects", $connection)
    	if (!$result){
    	die("Cannot execute MySQL command" .mysql_error());
    }
     
    while($row =mysql_fetch_array($result)){
    echo $row["menu_name"]." ".$row["position"]."<br/>";
    }
    ?>
     
    </td>
    <td id="page">
    <h2>Content Page</h2>
     
    </td>
    </tr>
    </table>
    <?php require_once("includes/footer.php"); ?>

  2. #2
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are two things I noticed:
    - on line with mysql_query you need to add a semicolon at the end.
    - you have one unclosed brace, starting in "if($db_select) {"

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You had a few unclosed lines and missing parentheses, additionally you had some error checking which was not working as intended.

    You may want to post the actual error you are receiving should you post again, it helps tremendously when trying to resolve your issues.

    Try this:-

    PHP Code:
    <?php
    $connection 
    mysql_connect("localhost","root","");
    if(!
    $connection){
        die (
    "Cannot be connected to database" .mysql_error());
    }
    $db_selectmysql_select_db("wiget_corp");
    if(!
    $db_select) {
        die(
    "Database selection failed" .mysql_error());
    }
    require_once(
    "includes/functions.php");
    require_once(
    "includes/header.php");
    ?>
    <table id="structure">
    <tr>
    <td id="navigation">
    <?php
    $result 
    mysql_query("select * from subjects"$connection);
    if (!
    $result){
        die(
    "Cannot execute MySQL command" .mysql_error());
    }
    while(
    $row =mysql_fetch_array($result)){
        echo 
    $row["menu_name"]." ".$row["position"]."<br/>";
    }
    ?>

    </td>
    <td id="page">
    <h2>Content Page</h2>
    </td>
    </tr>
    </table>
    <?php
        
    require_once("includes/footer.php");
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •