www.webdeveloper.com
Results 1 to 2 of 2

Thread: Find Problem

  1. #1
    Join Date
    Dec 2011
    Posts
    39

    Find Problem

    Dear I have following codes

    PHP Code:
    <?php
    // Connection variables
    $host="localhost";
    $username="root";
    $password="";
    $db_name="asia"

    // Connect to database
    $con=mysqli_connect("$host""$username""$password");

    // Connect result
    if(!$con){
    die(
    'Error Connecting to Database: ' mysqli_error());
    //die '<script type="text/javascript">alert("Error Connecting to Database"). mysqli_error($con);</script>'; 
    }
    else
    {
    echo 
    '<script type="text/javascript">alert("Connected"). mysqli_error($con);</script>'
    }

    // Database Selection
    $sel =mysqli_select_db($con,"$db_name");

    // Database Selection result
    if(!$sel){
    die(
    'Error selecting Database: ' mysqli_error());
    }
    else
    {
    //echo "Database Selected" . mysqli_error($con);
    echo '<script type="text/javascript">alert("Database Selected"). mysqli_error($con);</script>'
    }
    $result mysql_query("select sno,packing,weight from ghee");  
     if(!
    $result){
      echo 
    'select query error or data not found';
      }
      else
      {
      echo 
    'data found';
          
    echo 
    "<table border='1' style='border-collapse: collapse'>";  
    echo 
    "<th>SNo</th><th>Name</th><th>Weight</th>";  
    while (
    $row mysql_fetch_array($result))
    {  
    echo
    "<tr><td>".$row['sno']."</td><td>".$row['packing']."</td><td>".$row['weight']."</td></tr><br>";
    echo 
    "</table><br>";
    }
    }
    mysqli_close($con);  

    ?>
    on this line number 35

    PHP Code:
    echo 'select query error or data not found'
    it says:select query error or data not found

    connection with mysql is ok
    and
    Database is selected properly

    but why I get above error message

    Here is screen shot of database

    http://i41.tinypic.com/2w5lx8y.jpg

    Please help me to get rid of error message

  2. #2
    Join Date
    Apr 2013
    Posts
    56
    Try replacing echo statement with this one die('Invalid query: ' . mysql_error()); .It should tell you what is the error.

    Also use MySQLi instead of MySQL.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles