SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Odbc

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    United Kingdom
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Odbc

    Hello, I am trying to add some data to an ODBC database. (in this case Access). I have written a script that connects to Access. It seems to connect to the DB ok so there are no problems there, however it seems to have a problem with actually executing the query. What am I doing wrong here.

    Before anyone says, why am I using access and not MySQL, this is just as a test, to see it connect to other databases. I know that this works well in MySql.

    Here is the script. :



    PHP Code:
    <html>
    <head>
    <title>Address Book</title>
    </head>

    <body>
    <center><form action"<?php echo("$PHP_SELF")?>" method="post">
    First Name &nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="text" NAME="firstname" size ="40"><br>
    Last  Name &nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="lastname" size ="40"><br>
    email address <input type="text" name="email" size="40"><br>
    Tel number <input type="text" name="tel" size="40"><br>
    <br>
    <INPUT TYPE="submit" name="submit" value="Submit!">
    </FORM></center>


    <?php

    if(isset($_POST['submit'])) {


       
    // decalre variables

     
    $firstnametrim $_POST['firstname'] );
     
    $lastname trim ($_POST['lastname']  );
     
    $email trim ($_POST['email'] );
     
    $tel   trim ($_POST['tel'] );

      


    if(
    $firstname!="" && $lastname!="" && $email!="" && $tel!="") {

    $conn odbc_connect ('address''''') or die( "Could    Not Connect to ODBC Database!" ); 
     
    //$conn= mysql_connect("localhost", "root", "") or die("connection error");
     //   mysql_select_db("address", $conn) or die("Could not find database you specified ");
    //$query ="INSERT into details VALUES('$firstname', '$lastname', '$email', '$tel')";
    $query ="Insert into Details (firstname, lastname, email, tel) VALUES ('$firstname', '$lastname', $email','$tel')"

    $result=mysql_query ($query) or die ("There has been a problem with executing the query.");

    if(
    $result)

    echo 
    'Thankyou. The information you submitted, has been added to the database.';


    }

    }


    ?>

    </body>
    </html>

  2. #2
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $result=mysql_query ($query) or die ("There has been a problem with executing the query." ); 
    You're mixing your functions - you need to use the ODBC functions: http://www.php.net/manual/en/ref.odbc.php

    Have a read at: http://php.weblogs.com/odbc for examples.


Bookmarks

Posting Permissions

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