tags:

views:

58

answers:

3
+5  A: 
$result2=mysql_query($sql2,$conn);

$conn is not defined in the scope of your function (even if you're including the connect.php file before that.

although you can use the suggestion to make $conn global, it's usually better practice to not make something global just for the sake of globalizing it.

i would instead pass $conn to the function as a parameter. this way, you can reuse the same function you wrote with different connections.

Sev
thanks a lot. I am a beginner in PHP and I still have the habit of forgetting that global variables are not available in functions in PHP, unlike C. THanks a lot.
+2  A: 

$conn isn't declared as a global so the function cannot access it, as it is not defined within it.

Either simply add

global $conn;

To the top of the function to allow it to access the $conn.

Or you can remove $conn from the mysql_query() statement. By default it will use the current connection (as mentioned in the comments below).

Pez Cuckow
Or you can remove `$conn` from the `mysql_query()` statement. By default it will use the current connection.
Joseph
thanks a lot. I am a beginner in PHP and I still have the habit of forgetting that global variables are not available in functions in PHP, unlike C. THanks a lot.
+1  A: 

Where do you set $conn? It doesn't look like you set a connection within that function

Barlow Tucker