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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    inserting problem

    Hi, I have a form which will allow users to add data to the database.
    For testing purposes I have changed the SQL query so it posts static information to test it is inserting into the database.
    The sql query works fine in postgres, but when i run it on the php page, it doesn't insert into the table.

    the query is this:

    PHP Code:
    $sql = ("INSERT INTO advert2 (username, mod_book_id, asking_price, condition, description, date_added) 
    VALUES ('isxlm', '2231', '45', 'Good', 'second time now', 'now');"
    );
    $result pg_exec($sql); 
    Can anyone see why this isn't working??? Here is the entire page:

    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 (username, mod_book_id, asking_price, condition, description, date_added) VALUES ('isxlm', '2231', '45', 'Good', 'second time now', 'now');");
            
    $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>

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Take the first semi-colon off

    'now');");

  • #3
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I took the first semi-colon off
    'now')");

    but it hasn't made a difference, it's still not posting to the database.

    any ideas?
    thanks.

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Try taking the variable off the query
    $result =

    Apart from that I can't see anything obvious, is there a function to show an error with that database? I only know mysql's, mysql_error()

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 96 Times in 94 Posts
    for more info
    <?echo pg_result_error($result);?>

    I suspect it will have something to do with the quoting of integer values & I doubt that the 'now' command will work when quoted ?
    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
    •