Sorry for being such a newbie but I spent ALL yesterday trying to do this with no success. each website is telling me something different so i am very confused.

i have a very simple database with 4 columns of data:

column 1="PRIMARYKEY" field type=INTEGER
column 2="CLIENT" field type=VARCHAR
column 3="LIVEDATE" field type=DATE

i have included a form underneath. the code for this is as follows:

<form name="form1" method="post" action="submit.php"
}
?>
<p>Primary Key:
<input name="primarykey" type="text" id="primarykey" maxlength="4">
</p>
<p>Client:
<input name="client" type="text" id="client" maxlength="50">
</p>
<p>Live Date:
<input name="livedate" type="text" id="livedate" max length="10">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>

the action part of this form refers to a file called submit.php.

could anyone please tell me EXACTLY what code i need to put inside submit.php to have my form add a new record onto my Borland Interbase database when the user clicks the submit button. All I want is a snippet of code that will actually work. I have been trying for hours and am close to tears.

many thanks for any help

    Generally speaking I don't write other people's programs for them unless they pay me.

    You're probably being given different answers because there are so many ways of doing what you describe, and some details depend on your precise configuration.

    submit.php----------------------
    $primarykey=$POST['primarykey'];
    $client=$
    POST['client'];
    $livedate=$_POST['livedate'];

    $host= // You'll have
    $username= // to fill
    $password= // these out.

    $dbconn=ibase_connect($host,$username,$password);
    $query="INSERT INTO [table] (PRIMARYKEY, CLIENT, LIVEDATE) values ($primarykey,'$client','$livedate')";
    $succeed=ibase_query($dbconn,$query);

    if($succeed)
    { echo "Insertion succeeded.";
    }
    else
    { echo "Insertion failed.";

    }

    Now, I don't have an Interbase DBMS, and never used one in the past, so I don't know what the date format is. I also don't know certain things about your configuration. As a result there is no checking in the above snippet to make sure that the data supplied is of the right type and format, or whether the result is even consistent (usually the primary key is generated by the DBMS, not supplied by the user - but it has to be unique throughout the table.); so I'll have to leave that and the question of whether you need to do $client=str_replace("'","''",$client) before putting it in the query to you to figure out.

      I'm also assuming that you're using PHP4.1 or later; if not, replace $_POST with $HTTP_POST_VARS.

      And it should go without saying (but so often on this forum doesn't seem to) that "[table]" should be replaced by the real name of the table you're inserting into.

        Write a Reply...