1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Basic Dreamweaver mysql DB query not working

Discussion in 'MySQL' started by Rui Jacome, Oct 17, 2013.

  1. #1
    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
     
    Rui Jacome, Oct 17, 2013 IP
  2. Rui Jacome

    Rui Jacome Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    Totally forgot to post the error:

     
    Rui Jacome, Oct 17, 2013 IP
  3. jscg

    jscg Well-Known Member

    Messages:
    161
    Likes Received:
    5
    Best Answers:
    3
    Trophy Points:
    108
    Digital Goods:
    2
    #3
    Its seems that this word is making an error "OpServiço" because of "ç" character.
     
    jscg, Oct 23, 2013 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,498
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #4
    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
     
    sarahk, Oct 29, 2013 IP