Query in a function

From: Date: Tue, 19 Jun 2001 08:21:44 +0000
Subject: Query in a function
Groups: php.db 
Request: Send a blank email to php-db+get-9621@lists.php.net to get a copy of this message
Hello I have a query that I have placed in a function that is in a file that I "include" in the page to be displayed. It doesn't work. I know that the code works because when I place the code in the page to be displayed directly it works fine. I can't figure it out. Thanks in advance for any help. John Here is the function contained in lib.inc: function type_select() { $connection = mysql_connect($server, $user, $pass); echo("<select name=\"type_id\">"); $query1 = "SELECT * FROM type"; $result1 = mysql_db_query($db, $query1, $connection); echo(!isset($type_id)?"<option value=\"\">--Please select a Type--</option>":""); if(mysql_num_rows($result1) > 0) { while($row1 = mysql_fetch_array($result1)) { $result1_type_id = $row1["type_id"]; $result1_type_desc = $row1["type_description"]; echo("<option "); echo(isset($type_id)?($result1_type_id==$type_id ? "selected " : ""):""); echo("value=\""); echo($result1_type_id); echo("\">"); echo( $result1_type_desc); echo("</option>"); } } else { echo("<option value=\"error\">Error</option>"); } echo("</select>"); } And here is the call to that function in the page that is displayed: include("lib.inc"); ?> <form method="post" action="disp_item_test.php"> <? //TYPE selection if(!isset($type_id)) { type_select(); } And here is the error message: Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /web/sites/268/seriousj/www.mccartney.f2s.com/opus/tnzp/lib.inc on line 21

« previous php.db (#9621) next »