www.webdeveloper.com
Results 1 to 4 of 4

Thread: PHP site not displaying MySQL result

  1. #1
    Join Date
    Jun 2014
    Posts
    2

    PHP site not displaying MySQL result

    Morning guys.

    I have no experience with HTML / PHP and only just recently set-up MySQL server. Server is currently set-up nicely with all the data i required in it. I am using DW CS6, Database is connected just fine too the server too.

    Now i followed this link for creating a search and result page http://help.adobe.com/en_US/dreamwea...d65-78b0a.html now when i create a recordset and click test it works fine but when I implement the dynamic table onto the site and run the site from my server no details will show on the table, can anyone help with this? code below for both pages. Now go gently on me as said I have no experience with php nor html etc and this is the first time ive set-up the MySQL server :P

    Code:
    <!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>
    <form action="result.php" method="get" enctype="application/x-www-form-urlencoded" name="form1" target="_parent" id="form1">
      <label for="textfield"></label>
      <input type="text" name="textfield" id="textfield" />
      <input type="submit" name="button" id="button" value="Submit" />
    </form>
    </body>
    </html>
    Code:
    <?php require_once('Connections/MySQL.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;
    }
    }
    
    $colname_Recordset1 = "-1";
    if (isset($_GET['Asset Tag'])) {
      $colname_Recordset1 = $_GET['Asset Tag'];
    }
    mysql_select_db($database_MySQL, $MySQL);
    $query_Recordset1 = sprintf("SELECT * FROM mfdtble WHERE `Asset Tag` = %s ORDER BY `Asset Tag` ASC", GetSQLValueString($colname_Recordset1, "text"));
    $Recordset1 = mysql_query($query_Recordset1, $MySQL) 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>
    <table border="1">
      <tr>
        <td>Asset Tag</td>
        <td>IP Address</td>
        <td>Device Model</td>
        <td>Name</td>
        <td>Location</td>
        <td>Serial Number</td>
        <td>Color</td>
        <td>Controller Version</td>
        <td>DeviceId</td>
        <td>Mac</td>
      </tr>
      <?php do { ?>
        <tr>
          <td height="68"><?php echo $row_Recordset1['Asset Tag']; ?></td>
          <td><?php echo $row_Recordset1['IP Address']; ?></td>
          <td><?php echo $row_Recordset1['Device Model']; ?></td>
          <td><?php echo $row_Recordset1['Name']; ?></td>
          <td><?php echo $row_Recordset1['Location']; ?></td>
          <td><?php echo $row_Recordset1['Serial Number']; ?></td>
          <td><?php echo $row_Recordset1['Color']; ?></td>
          <td><?php echo $row_Recordset1['Controller Version']; ?></td>
          <td><?php echo $row_Recordset1['DeviceId']; ?></td>
          <td><?php echo $row_Recordset1['Mac']; ?></td>
        </tr>
        <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    </table>
    </body>
    </html>
    <?php
    mysql_free_result($Recordset1);
    ?>

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    875
    So many things wrong......

    Why are you using MySQL_* functions? Didnt' you notice in the manual where you looked these up that they are all DEPRECATED and about to removed from PHP? Learn mysqlI or PDO functions.

    Where did you learn to use sprintf function to write a query statement? Just write it!

    $q = "select * from table where something=somethingelse order by col1";

    That's how you write a query.

    If you have multiple rows to be output in your html you can't just fetch one of them and then output your html.

    PHP Code:

    <?php require_once('Connections/MySQL.php'); ?>
    <?php
    ...
    Why do you leave php mode only to enter it on the very next line?

    Where did you learn to test for the existence of a function before you write it up? That's certainly not something a newbie picks up on day 1. And why do you even want to test for it if you KNOW you are going to write it? Just write it.

    A label tag with no label? How do you not catch that?

    As for outputting your results that code can be written much cleaner this way:
    PHP Code:
    while ($row_Recordset1 mysql_fetch_assoc($Recordset1))  // REMOVED ONE SEMI COLON HERE
    {
         
    $code=<<<heredocs
           <tr>
          <td height="68">
    {$row_Recordset1['Asset Tag']}</td>
          <td>
    {$row_Recordset1['IP Address']}</td>
          <td>
    {$row_Recordset1['Device Model']}</td>
          <td>
    {$row_Recordset1['Name']}</td>
          <td>
    {$row_Recordset1['Location']}</td>
          <td>
    {$row_Recordset1['Serial Number']}/td>
          <td>
    {$row_Recordset1['Color']}</td>
          <td>
    {$row_Recordset1['Controller Version']}</td>
          <td>
    {$row_Recordset1['DeviceId']}</td>
          <td>
    {$row_Recordset1['Mac']}</td>
          </tr>
    heredocs;
         echo 
    $code;
    }
    //  NOTE: heredocs must be in col. 1 
    </table
    Of course you don't want to do that first fetch now before you begin the loop.

    Don't know why you have a height on the first td element but none others.
    Last edited by ginerjm; 06-15-2014 at 02:15 PM.

  3. #3
    Join Date
    Jun 2014
    Posts
    2
    Cheers for the reply

    In no way did i code any of it, this is all done from design view on dreamweaver cs6, at no point did I click on code and start typing :P I followed too the T that site on the first post, so what every code you see is form that.

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    875
    Good luck in your programming adventures then.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles