RE: Beginner's php/mysql connection probs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----Original Message-----
From: John Nichel [mailto:john@xxxxxxxxxxxx]
Sent: Friday, April 28, 2006 9:11 PM
To: Php-General
Subject: Re:  Beginner's php/mysql connection probs


sathyashrayan wrote:
>  Dear group,
>
> (I am a very beginner so please bear with me for a simple question)
>
>   I am a self thought php beginner. I wrote my first toy
> code for database connection in php/mysql. The connection
> is successful but iam getting a warning and my rows/columns
> are not showing. I am getting a warning:
>
> Warning:  mysqli_fetch_row() expects parameter 1 to be mysqli_result,
> boolean given in c:\webs\test\dbs\one.php on line 13
>
> I went through the php manual for the above mentioned function where
> I get no clue. Pls guide me.
>
> code:
>
> <html>
>   <head>
>      <title> my first data base page </title>
>   </head>
>  <body>
>    <pre>
>  <?php
>     $conn = mysqli_connect("localhost","root","passwd","temp")
>             or die("conn failed");
>     $temp1 = "select *from grape_varity";
>     $result = mysqli_query($conn,$temp);

Your query is failing.  I'm guessing that it's because you don't have a
space between '*' and 'from'

Better if you check to make sure the query was successful before trying
to get the data....

if ( ! $result = mysqli_query ( $conn, $temp ) ) {
	echo ( mysqli_error ( $conn ) );
} else {
	while ( $row = mysqli_fetch_row ( $result ) ) {
	///  more code

Thanks for the quick help. I changed the code as you sugested and get

"Query was empty" as the result of the line echo (mysqli_error($conn)). So
does that mean the table is empty? But I did filled the table with some
value and mysql query displays the tables.

Simple error handling...you'll want to do more than that, but that will
give you the gist of it

>     while($row=mysqli_fetch_row($result))
>     {
>       for($i =0;$i < mysqli_num_fields($result);$i++)
>         echo $row[i]." ";
>         echo "\n";
>     }
>
>      mysqli_close($conn);
>
>  ?>
> </pre>
> </body>
> </html>
>
> [OT]
> And one more thing is if I want to replay to a msg in this mail list
> do I have to hit replay button or replay-all button for posting
> in the mail list. I use "microsoft outlook 2000"
>
> [/OT]
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux