Hello my friends!
I’m a very php novice and I need your help!
I have created a form in html which prompts users to input first name, last name and phone number. I want this data to be inserted into an oracle table called W_TEST. I want the phone number to be unique (e.g. two users may have the same first and last name, but not the same number. The database I use is oracle. One way I fixed this was by setting phone number as primary key, but i don’t like that solution.
How could I modify my php code to warn user that his/her data was not inserted in case of duplicate phone numbers?
I would appreciate your valuable help!
My code is the following:
(1) oracle table:
CREATE TABLE W_TEST
(
FNAME VARCHAR2(64) NULL,
LNAME VARCHAR2(64) NULL,
TNUM INT NOT NULL,
CONSTRAINT MYKEY PRIMARY KEY (TNUM) – I want to work without it!
);
COMMIT;
(2) html form:
> <!DOCTYPE html>
> <html lang="en">
> <head>
> <meta charset="UTF-8">
> <link rel="stylesheet" type="text/css" href="form_style.css">
> <title>User Input Data</title>
> </head>
> <body>
>
> <k1 class = "myhome">Input Data</k1>
>
> <!-- <h3>Please enter your personal data</h3> --->
>
> <form method="post" action="form_data.php" id="forma">
> <fieldset>
> <legend>Insert your data below:</legend>
> Όνομα:<br>
> <input type="text" name="firstname" required><br>
> Επώνυμο:<br>
> <input type="text" name="lastname" required><br>
> Τηλέφωνο:<br>
> <input type="number" name="phone" required pattern="[0-9]{11}"><br>
> <input type="submit" value="ok!">
> </fieldset>
> <h6>(*Note: You must fill all fields!)</h6>
> </form>
>
> </body>
> </html>
>
> ----
>
> (3) **php code (this is where I need your help!):**
>
> <?php
>
> echo "<link rel='stylesheet' type='text/css' href='form_style.css'>";
>
> error_reporting(E_ALL);
> ini_set('display_errors', 'On');
>
> $username = "KONRMS"; // Use your username
> $password = "Welcome2018"; // and your password
> $database = "localhost/XE"; // and the connect string to connect to your database
>
> $a = $_POST["firstname"];
> $b = $_POST["lastname"];
> $c = $_POST["phone"];
>
> $quake = "
> INSERT INTO W_TEST
> (FNAME, LNAME, TNUM)
> VALUES
> ('$a', '$b', '$c')
> ";
>
> $c = oci_connect($username, $password, $database, 'UTF8');
>
> if (!$c) {
> $m = oci_error();
> trigger_error('Could not connect to database: '. $m['message'], E_USER_ERROR);
> }
>
> $s = oci_parse($c, $quake);
> if (!$s) {
> $m = oci_error($c);
> trigger_error('Could not parse statement: '. $m['message'], E_USER_ERROR);
> }
>
> $r = oci_execute($s);
> if (!$r) {
> $m = oci_error($s);
> trigger_error('Could not execute statement: '. $m['message'], E_USER_ERROR);
> }
>
> echo "<ppp> Successfully saved data! </ppp>";
>
> ?>