Trying to update data in access database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Yew12
    New Member
    • Mar 2008
    • 23

    Trying to update data in access database

    I have been trying to update the details in a access database but, all I get is a white screen and all the errors I have built-in give me no help at all.

    All help is greatly appreciated.


    [PHP]<html>
    <head><title> Customer Information Updated</title></head>
    <body>

    <?php

    $connstr = "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=" . realpath("2Poin tB.mdb").";";
    $conn=odbc_conn ect($connstr,'' ,'') or die(Print "connect error: ".odbc_error()) ;


    if($_POST[Emergency_Conta ct_Name]=="")$Emergency _Contact_Name=' NULL';
    else $Emergency_Cont act_Name=$_POST[Emergency_Conta ct_Name];

    if($_POST[Emergency_Conta ct#]=="")$Emergency _Contact#='NULL ';
    else $Emergency_Cont act#=$_POST[Emergency_Conta ct#];

    if($_POST[Telephone]=="")$Telephone ='NULL';
    else $Telephone=$_PO ST[Telephone];

    if($_POST[Special_Deitary _Requirements]=="")$Special_D eitary_Requirem ents='NULL';
    else $Special_Deitar y_Requirements= $_POST[Special_Deitary _Requirements];


    $sql="update tblCustomer set Customer_ID='$_ POST[Customer_ID]',Surname='$_PO ST[Surname]',Forename='$_P OST[Forename]', DOB='$_POST[DOB]',Sex='$_POST[Sex]',Address='$_PO ST[Address]', Town ='$_POST[Town]', City='$_POST[City]', Post_Code ='$_POST[Post_Code]', Telephone='$_PO ST[Town]', Emergency_Conta ct_Name='$_POST[Emergency_Conta ct_Name]', Emergency_Conta ct#='$_POST[Emergency_Conta ct#]', Special_Deitary _Requirements=' $_POST[Special_Deitary _Requirements]' where Customer_ID='$_ POST[Customer_ID]'";


    $stmt=odbc_exec ($conn, $sql)
    or die (Print "execute error: ".odbc_error()) ;

    odbc_exec($conn , $stmt) or die (Print "error".odbc_er ror());

    print "Thanks ".$Forename "your customer information has been updated";
    ?>
    </body>
    </html>
    [/PHP]
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    [PHP]print ("Thanks ".$Forename .", your customer information has been updated.";[/PHP]

    You forgot to join the string between your variable and the rest of the message (and I fixed up a little grammer), which might have confused the output line. Post back if that does not solve it and I will look at the code a bit closer.

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      By the way: great SQL statement code for some SQL injection!

      Ronald

      Comment

      • Yew12
        New Member
        • Mar 2008
        • 23

        #4
        Thanks very much that help a lot. At least now I get an error.

        [PHP]<html>
        <head><title> Customer Information Updated</title></head>
        <body>

        <?php

        $connstr = "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=" . realpath("2Poin tB.mdb").";";
        $conn=odbc_conn ect($connstr,'' ,'') or die(Print "connect error: ".odbc_error()) ;


        if($_POST[Emergency_Conta ct_Name]=="")$Emergency _Contact_Name=' NULL';
        else $Emergency_Cont act_Name=$_POST[Emergency_Conta ct_Name];

        if($_POST[Emergency_Conta ct_No]=="")$Emergency _Contact_No='NU LL';
        else $Emergency_Cont act_No=$_POST[Emergency_Conta ct_No];

        if($_POST[Telephone]=="")$Telephone ='NULL';
        else $Telephone=$_PO ST[Telephone];

        if($_POST[Special_Deitary _Requirements]=="")$Special_D eitary_Requirem ents='NULL';
        else $Special_Deitar y_Requirements= $_POST[Special_Deitary _Requirements];


        $sql="update tblCustomer set Customer_ID='$_ POST[Customer_ID]',Surname='$_PO ST[Surname]',Forename='$_P OST[Forename]', DOB='$_POST[DOB]',Sex='$_POST[Sex]',Address='$_PO ST[Address]', Town ='$_POST[Town]', City='$_POST[City]', Post_Code ='$_POST[Post_Code]', Telephone='$_PO ST[Town]', Emergency_Conta ct_Name='$_POST[Emergency_Conta ct_Name]', Emergency_Conta ct_No='$_POST[Emergency_Conta ct_No]', Special_Deitary _Requirements=' $_POST[Special_Deitary _Requirements]' where Customer_ID='$_ POST[Customer_ID]'";

        Print $sql;

        $stmt=odbc_exec ($conn, $sql)
        or die (Print "execute error: ".odbc_error()) ;

        odbc_exec($conn , $stmt) or die (Print "error".odbc_er ror());

        print ("Thanks ".$Forename . "your customer information has been updated");

        ?>
        </body>
        </html>
        [/PHP]

        The error is odbc error 22005 a date problem I think. Do you know what to do from here.

        I don't know if this matters but Im from the uk so my date goes dd/mm/yyyy.


        Oh thanks Ronald for making me aware.
        Last edited by Yew12; Apr 16 '08, 10:42 PM. Reason: thanks

        Comment

        • TheServant
          Recognized Expert Top Contributor
          • Feb 2008
          • 1168

          #5
          Originally posted by ronverdonk
          By the way: great SQL statement code for some SQL injection!

          Ronald
          One step at a time Ron. But Ron's right, you cannot go public with the code you have now. You need to take some security steps to stop people from using your database how they see fit. This means validating and sanitizing you inputs. Here is one to start you off (you can continue with google). But make another post if you have questions about that - one problem per post.

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            ....I don't know if this matters but Im from the uk so my date goes dd/mm/yyyy.....
            It matters! I do not know the standard date format for Access but I quess it is, just like MySQL, YYYY-MM-DD. If that is true, you'll have to reformat your date before storing it in the database. You can use the PHP strtotime() and date() functions for that.

            Ronald

            Comment

            Working...