"invisible" query

Discussion in 'PHP' started by gilk, Aug 18, 2007.

  1. #1
    Hi,
    the following query appears to be invisible to the program....
    ie it does not appear to be executed....no echos
    
    
    // open the connection
    
    $conn = mysql_connect("h41mysql45.secureserver.net", "ezevetdistanceed", "password");
    
        // pick the database to use
    
    mysql_select_db("ezevetdistanceed",$conn) or die(mysql_error());
    
        // create the SQL statement
        
    $getsomething = "SELECT  * FROM studentanswers";     
    $result = mysql_query($getsomething, $conn) or die(mysql_error("cant access student answers"));    
    $numberofrows = mysql_num_rows($result);
    echo "the number of rows is $numberofrows";
    
    
    echo "got thru to studentanswers";
    
    PHP:
    all of the subsequent queries are executed, so I think that $conn is OK.
    the server and database and password must also be OK....so why the invisibility anyone??? PLEASE?
    gilk
     
    gilk, Aug 18, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Place these lines on top of your code and see what you get:
    
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    
    PHP:
    EDIT:

    This doesn't look right:
    
    die(mysql_error("cant access student answers"));  
    
    PHP:
     
    nico_swd, Aug 18, 2007 IP
  3. srobona

    srobona Active Member

    Messages:
    577
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    88
    #3
    Check all the connections, and remove the extra white space after SELECT in the query. Then try again.
     
    srobona, Aug 18, 2007 IP
  4. gilk

    gilk Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Did all that....even the white space....even tho they reckon that php ignores white space.
    Code still seems to be invisible to php
    Any more ideas???
    gilk
     
    gilk, Aug 18, 2007 IP
  5. gilk

    gilk Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hope you can come up with somethins else.....im off to bed now but hope to find an answer in the (our) morning
    Cheers,
    gilk
     
    gilk, Aug 18, 2007 IP
  6. Muhammad Haris

    Muhammad Haris Peon

    Messages:
    576
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #6
    echo "the number of rows is ".$numberofrows;
    PHP:
     
    Muhammad Haris, Aug 18, 2007 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    mysql_error() expects a resource (or nothing) as first parameter, and not a string. it should be:
    
    die("cant access student answers. MySQL error: " . mysql_error());  
    
    PHP:
     
    nico_swd, Aug 18, 2007 IP
  8. Chemo

    Chemo Peon

    Messages:
    146
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #8
    
    	// open the connection
    	if ( false === ($conn = mysql_connect("h41mysql45.secureserver.net", "ezevetdistanceed", "password")) ){
    		die('Could not connect to DB: ' . mysql_error());
    	}
    	
    	// pick the database to use
    	if ( false === ($db = mysql_select_db("ezevetdistanceed", $conn)) ){
    		die('Could not select DB: ' . mysql_error());
    	}
    	
    	// create the SQL statement
    	$sql = "SELECT * FROM studentanswers";     
    	
    	if ( false === ($query = mysql_query($sql, $conn)) ){
    		echo 'Query failed: ' . mysql_error();
    	} else {
    		$numRows = mysql_num_rows($query);
    		echo 'Number of rows: ' . $numRows;
    	}	
    
    PHP:
     
    Chemo, Aug 18, 2007 IP
  9. tamilsoft

    tamilsoft Banned

    Messages:
    1,155
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #9

    echo "the number of rows is $numberofrows";

    Its also working
     
    tamilsoft, Aug 18, 2007 IP