Hello everyone, I'm a newbie on mysql and php language, but i'm trying to build a simple code to query a DB (Mysql) but i'm getting an Mysql error: index.php (query page) code is: ?php require_once('../Connections/ahbvc.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_ahbvc, $ahbvc); $query_Recordset1 = "SELECT saida, cdos, `DATA`, DataRegisto, HORAENTRADA, codigo, MORADA, OpServiço, NumeroPedidoSocorro FROM registo WHERE HORAENTRADA IS NULL"; $Recordset1 = mysql_query($query_Recordset1, $ahbvc) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1);mysql_select_db($database_ahbvc, $ahbvc); $query_Recordset1 = "SELECT saida, cdos, DATA, DataRegisto, HORAENTRADA, codigo, MORADA, OpServiço, NumeroPedidoSocorro FROM registo WHERE HORAENTRADA IS NULL"; $Recordset1 = mysql_query($query_Recordset1, $ahbvc) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); $query_Recordset1 = "SELECT saida, cdos, `DATA`, DataRegisto, HORAENTRADA, codigo, MORADA, OpServiço, NumeroPedidoSocorro FROM registo WHERE HORAENTRADA IS NULL ORDER BY saida"; $Recordset1 = mysql_query($query_Recordset1, $ahbvc) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php echo $row_Recordset1['']; ?> </body> </html> <?php mysql_free_result($Recordset1); ?> PHP: Connection code is: <?php # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_ahbvc = "www.ahbvc.org.pt"; $database_ahbvc = "ahbvc2_infos"; $username_ahbvc = "ahbvc2"; $password_ahbvc = "Cvb.2011"; $ahbvc = mysql_pconnect($hostname_ahbvc, $username_ahbvc, $password_ahbvc) or trigger_error(mysql_error(),E_USER_ERROR); ?> PHP: i've tried to read php and mysql manual to find the error, but i'm not being able to find out what is the issue. Can please someone help me ? Tks! Cheers! Rui Jácome
I didn't read this initially because I don't use dreamweaver but it seems that the problem is in the code, not the editor. I can't tell which of your queries is causing the problem so could you make some minor changes and rerun please mysql_select_db($database_ahbvc, $ahbvc); $sql = "SELECT saida, cdos, `DATA`, DataRegisto, HORAENTRADA, codigo, MORADA, OpServiço, NumeroPedidoSocorro FROM registo WHERE HORAENTRADA IS NULL "; $Recordset1 = mysql_query($sql, $ahbvc) or die(mysql_error().'<br>1st query<br>'.$sql); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); $Recordset2 = mysql_query($sql, $ahbvc) or die(mysql_error().'<br>2nd query<br>'.$sql); $row_Recordset2 = mysql_fetch_assoc($Recordset2); $totalRows_Recordset2 = mysql_num_rows($Recordset2); $sql .= "ORDER BY saida"; $Recordset3 = mysql_query($sql, $ahbvc) or die(mysql_error().'<br>3rd query<br>'.$sql); $row_Recordset3 = mysql_fetch_assoc($Recordset3); $totalRows_Recordset3 = mysql_num_rows($Recordset3); Code (markup): I wasn't sure why you were reselecting the database when it didn't seem to change I don't get why you have the second query when it appears to be identical to the first This version will output the sql that is run and you can use that in MySQL's phpMyAdmin tool and that will give you more feedback on the error. Some thoughts... your column naming appears inconsistent - some will all caps, some upper and lower. That makes it really hard to manage. use the `fieldname` is good practice, you should use it more consistently