Results 1 to 3 of 3

Thread: HELP: PHP Code doesn't work.

  1. #1
    Join Date
    May 2010
    Posts
    3,851
    Rep Power
    17

    Exclamation HELP: PHP Code doesn't work.

    I am having trouble getting the PHP Code below to work. This is the error I get, when I open the page:

    Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/jsalmon/public_html/a9p2.php on line 131
    The text surrounded by "//Error ZONE" is the are where it points to the error

    The code is being used to build a table based on a database table.

    The table was created like this:

    Code:
    CREATE TABLE hardware_t (
        hdw_part_no char(10) PRIMARY KEY,
        hdw_name char(20),
        hdw_price numeric(6, 2),
        hdw_weight numeric(4, 1),
        hdw_picture char(30),
        hdw_description varchar);

    PHP Code:
    <table border = "border">

      <caption class = "font"> TOOL LIST AND QUANTITY</caption

    <tr><th>Quantity</th><th>Tool</th>Weight</tr>

    <!-- Retrieve records from database -->
    <?php
    $db
    =pg_connect("dbname=***********");
    if (!
    $db) die("Can't connect to DB.");
    $query "select hdw_name, hdw_price, hdw_weight ";
    $query .= "from hardware_t ";
    $query .= "order by hdw_name;";
    $db_result pg_query($query);
    if (!
    $db_result)
    die(
    "Database error...");
    $num pg_num_rows($db_result);
    if (
    $num == 0) {
    echo 
    '<tr><td colspan="2">';
    echo 
    'Query got no rows!</td></tr>';
    }

    $i 0;
    while (
    $i $num) {
    $hdw_name pg_fetch_result
    ($db_result$i'hdw_name');
    $hdw_price pg_fetch_result
    ($db_result$i'hdw_price');
    $hdw_weight pg_fetch_result
    ($db_result$i'hdw_weight');


    //Error ZONE
    echo "<tr><td align="center"> <input type="text" name= '{$hdw_name}' size="5" maxlength="3"/> </td><td>$hdw_name</td> <td align="right">$hdw_price</td> <td align="right"> $hdw_weight</td></tr>";

    //Error ZONE



    $i++;
    }
    ?>
    <!-- Close out the table and end -->
    </table>
    Last edited by King_Jay16; Apr 15, 2012 at 12:59 PM.

  2. #2
    Join Date
    Jun 2008
    Posts
    74
    Rep Power
    0

    Default

    Code:
    echo "<tr><td align=\"center\"> <input type=\"text\" name=\"{$hdw_name}\" size=\"5\" maxlength=\"3\"/> </td><td>$hdw_name</td> <td align=\"right\">$hdw_price</td> <td align=\"right\"> $hdw_weight</td></tr>";
    Escape double quotes with backslash

  3. #3
    Join Date
    May 2010
    Posts
    3,851
    Rep Power
    17

    Default

    Quote Originally Posted by jayrulez View Post
    Code:
    echo "<tr><td align=\"center\"> <input type=\"text\" name=\"{$hdw_name}\" size=\"5\" maxlength=\"3\"/> </td><td>$hdw_name</td> <td align=\"right\">$hdw_price</td> <td align=\"right\"> $hdw_weight</td></tr>";
    Escape double quotes with backslash
    how could i miss that lol...

    Thanks!! I'ma test it and see what error pops up next.

    EDIT: Fixed!! No more errors
    Last edited by King_Jay16; Apr 15, 2012 at 05:54 PM.

Posting Permissions

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