Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    please help! going up the wall!!!!

    Hi, I've been staring at this for hours, and can't see where im going wrong, can someone just have a look and see if they can see what it is.

    Basically, I have three pages, one of which is a form where the user enters the title of book they are searching for, this links to the 2nd page which returns all the books from the ts_module_book table which matches the search term the user entered on page 1.
    The code for the second page is this


    PHP Code:

    <html> <head> <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <?php
    $_GET 
    $HTTP_GET_VARS;
    $_POST $HTTP_POST_VARS;
    $vars array_merge $_GET$_POST );
    $search $vars[search];
    ?>

    <body bgcolor="#ffffff" text="#000000">
    <table width="100%" border="0" bgcolor="" height="435">
      <tr> 
        <td align="left" bgcolor="#ffffcc" height="47"> 
          <p align="center"><font color="#003300" size="3"><b>University Of Leeds</b></font><font color="#003300" size="2"><b><br>
            School Of Computing</b></font><font color="#003300" size="3"></font></p>
          </td>
        <td height="47" valign="top" bgcolor="#ffffcc"> 
          <div align="right"><font size="6" color="#003300"><b>Student BOOK EXCHANGE</b></font></div>
        </td>
      </tr>
      <tr valign="top"> 
        <td width="20%" height="339"> <br>
        
          <?php include("menu.php"); ?>
        <p>&nbsp;</p><p>&nbsp;</p></td>
        <td width="100%" bgcolor="" height="339"> 
          <p align="right">
            <?php include("smallInclude.php"); ?>
          </p>
          <table width="98%" border="0" align="center" height="112">
            <tr> 
              <td valign="top" height="315"><b><font size="2" color="#003300">The 
                following books have been returned for your search criteria "<?php echo $search?>"</font></b> <br><br>
                          
    <?php
    include("connectBookdb.php");

    $query pg_query("select * from ts_module_books where book_title LIKE '%$search%' order by book_title ASC");

    $row 0;
    $numrows pg_numrows($query);

    echo (
    "<table border=1 width='95%'>");
    echo (
    "<tr><td width='40%'>Book Title</td><td width='30%'>Author</td><td width='15%'>Publisher</td><td width='10%'>&nbsp;</td></tr>");


    if (
    $numrows == )
    {
    printf ("no books");
    }
    else
    {
    while (
    $row $numrows)
    {
    $data pg_fetch_row ($query$row);
    print 
    "<tr><td>{$data[4]}</td><td>{$data[3]}</td><td>{$data[5]}</td><td> 
    <a href=\"addDataToDatabase.php?title={$data[4]}&auth={$data[3]}&pub={$data[5]}&pubYear={$data[6]}&id={$data[0]}\">Sell Book</a> 
    </td></tr>"


    $row++;
    }
    }
    printf ("</table>");
    pg_close();
    ?>

                <br>
              </td>
            </tr>
          <!--</table>-->
        </td>
      </tr>
      <tr valign="top"> 
        <td colspan="2" ><br><hr>&nbsp;
        
         </td>
          <table width="98%" border="0" align="center" height="112">
          </table>
      </tr>
    </table>
    </body>
    </html>

    On this second page with all the results output into a table, there is a hyperlink for each result which when clicked outputs on the next page - page 3, more information about that record.




    PHP Code:

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="#FFFFFF" text="#000000">
    <table width="100%" border="1">
      <tr>
        <td width="20%"><?php include("menu.php"); ?></td>
        <td width="80%">
          <p>&nbsp;</p>
        
         
    <?php
    include("connectBookdb.php");
    if(
    $_POST['submit']) 

    echo 
    "Thank you! Information entered.\n"
    echo 
    "<META HTTP-EQUIV=Refresh CONTENT=\"1; URL=addDataToDatabase.php\">"
    $test "$askingPrice$position$textfield";
        if(
    $test != "")
        {
            
    $sql = ("INSERT INTO advert2 (mod_book_id, asking_price, condition, description) VALUES ('$id', '$askingPrice', '$condition', '$textfield')");
            
    $result pg_exec($sql);
        }
        else
        {
            echo 
    "<br>Error you have not completed the form";
            
        }


    else 

    $title $_GET['title'];
    $author $_GET['auth'];
    $publisher $_GET['pub'];
    $pubYear $_GET['pubYear'];
    $id $_GET['id'];

    echo 
    "<h1>Please enter further details for your advert</h1>";

    echo 
    "<hr>";
    echo 
    "<b>Book Details</b><br><br>";
    echo 
    "<b>Title</b> : $title<br>";
    echo 
    "<b>Author</b> : $author<br>";
    echo 
    "<b>Publisher</b> : $publisher<br>";
    echo 
    "<b>Year</b> : $pubYear<Br>";
    ?>

    <form method="post" action="<? echo $PHP_SELF?>"> 
    Asking Price:<INPUT TYPE="text" NAME="askingPrice" SIZE="30"><br><br>
    Condition of book:
    <select name="condition">
    <option value="Like new">Like New
    <option value="Good">Good
    <option value="Fair">Fair
    <option value="Worn">Worn
    <option value="Worn">Excellent
    </select><br><br> 

    Additional Comments:<br><textarea name="textfield" cols="50" rows="5"></textarea> <br><br>

    <input type="Submit" name="submit" value="Enter information"></form> 
    <? 

    ?> 

        </td>
      </tr>
    </table>
    </body>
    </html>
    However, it won't insert into the database! When i enter the details in the form - price, condition and description. when i submit it, and then check my postgres database, nothing has been inserted into the table.
    Any ideas? I know its probably really simple, but its driving me up the wall!!!!
    Help!

    ps - For reference, the two tables are:

    ts_module_detail (id, module_code, author, book_title, publisher, pub_year)

    advert2 (advert_id, username, mod_book_id, asking_price, condition, description, date_added)

    module_book_id, is the foreign key relating to id in ts_module_detail.

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've never used Postgres, but according to this tutorial:
    Code:
    pgconnect(host, port, options, tty, dbname)
    
    $result = pg_exec($db, $query); 
    
    if (!$result) { printf ("ERROR"); $errormessage = pg_errormessage($db); echo $errormessage; exit; }
    There's three things there:
    1. You include a connectBookdb.php file which, I assume, connects to the db. This is fine and all, but I don't know how you're connecting to the database. I'm also unfamiliar with the options you can give, but one of them may be your permissions -- like if you're allowed to insert into the database?

    2. With their pg_exec they specify a $db connection to run the query on. I don't know if this is mandatory, but it's a good idea to put that in there.

    3. They can tell if there's an error after executing a query. You may want to incorporate this into your code for some help with debugging.

    The last thing I can say is to try the insert directly into the Postgres console (I'm assuming it's got one similar to MySQL...):
    INSERT INTO advert2 (mod_book_id, asking_price, condition, description) VALUES (2, 4.50, 'blah', 'blah')

    Or something to that effect anyway and ensure that it's a valid query and that it really SHOULD work.

    Hope that helps a little and good luck with it. Perhaps someone else with Postgres experience will be able to better lend you a hand.

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,093
    Thanks
    11
    Thanked 101 Times in 99 Posts
    Hi , please use more descriptive topic titles when posting a new thread, it helps us help you..

    check what postgreSQL says about it by adding ...
    <?
    echo pg_result_error ( $result );
    ?>

    after your query , I suspect that you should not be quoting the '$id' or any other integer fields, hopefully the error message will help.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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