PHP and SQL

Discussion in 'Technology' started by Phil Mitchell, Feb 13, 2006.

Users Viewing Thread (Users: 0, Guests: 1)

  1. Phil Mitchell

    Phil Mitchell check me a dollar brer?

    Joined:
    May 19, 2005
    Messages:
    8,965
    Likes Received:
    1
    Location:
    Melbourne
    PHP and SQL

    I am trying to write some php to add new records to a .mdb file

    my code is as follows and i just cannot see why it isnt working.....



    ----------------------


    <form action = "insertEx2.php" method = "post">
    Description <input type = "text" name = "description“ />
    Year <input type = "text" name = "year“ />
    Country <input type = "text" name = "country“ />
    Type <input type = "text" name = "Type" />
    Theme <input type = "text" name = "Theme" />
    <input type = "submit" name = "submit" value = "Add New Product“ />
    </form>
    <?
    include 'ltdedition_ODBC.php'; // make db connection using ODBC DSN


    $desc = $_POST['description']; // store parameters in variables
    $year = $_POST['year'];
    $country = $_POST['country'];
    $type = $_POST['type'];
    $theme = $_POST['theme'];

    ******odbc_exec($conn, "INSERT INTO Limited_Edition (Description, Year, Country, Type, Theme) values('$desc', '$year', '$country', '$type', '$theme')") or die (odbc_errormsg());


    odbc_close($conn);


    ?>


    i get the following error.....Data Type Mismatch on the line that is starred


    is it something to do with the fact that some of the data in the databases are integers and some are strings?

    what do i use in this section if that is the case?

    $desc = $_POST['description']; // store parameters in variables
    $year = $_POST['year'];
    $country = $_POST['country'];
    $type = $_POST['type'];
    $theme = $_POST['theme'];



    cheers for any help
  2. 1615634792921.png
  3. Jason Bourne

    Jason Bourne Registered User

    Joined:
    Oct 14, 2002
    Messages:
    5,337
    Likes Received:
    0
    Would it not just be the fact that the data your entering doesn't marry up with the data type of the database..

    For example.. if year in your database has a data type of number and your trying to add text into it..
  4. Phil Mitchell

    Phil Mitchell check me a dollar brer?

    Joined:
    May 19, 2005
    Messages:
    8,965
    Likes Received:
    1
    Location:
    Melbourne
    yeah thats what i think it is but i dont know what to change it to



    e.g.


    $year = $_POST['year'];

    year is probably an integer

    so what do i put instead of

    $_post


    ???
  5. Jason Bourne

    Jason Bourne Registered User

    Joined:
    Oct 14, 2002
    Messages:
    5,337
    Likes Received:
    0
    Just change the input type from "text" to "Number" or "Integer"

    Or change the data type in the database to "text"
  6. jamesrw

    jamesrw Member

    Joined:
    Aug 22, 2005
    Messages:
    31
    Likes Received:
    0
    read up on type casting

    in this context you may want to use (int)$_POST["year"];

    fao chandler_90: input type="int" does not exist! secondly, why change the data type to text? surely that defeats the point of data types in the first place!

    ;)
  7. Jason Bourne

    Jason Bourne Registered User

    Joined:
    Oct 14, 2002
    Messages:
    5,337
    Likes Received:
    0
    :lol:

    I was just giving him some options :p
    I'm only a n00b at this.. I thought that perhaps PHP might be like any other language I have learnt.

    Also.. just to make a point.. I have never been taught or even looked at PHP.. I am only now learning ASP.
    So there :strop: :)
  8. jamesrw

    jamesrw Member

    Joined:
    Aug 22, 2005
    Messages:
    31
    Likes Received:
    0
    i'll let you off this time then, but don't let it happen again!
  9. Jason Bourne

    Jason Bourne Registered User

    Joined:
    Oct 14, 2002
    Messages:
    5,337
    Likes Received:
    0
    Yes Sir!

Share This Page