Note that there are some explanatory texts on larger screens.

plurals
  1. POInset data into table that were connected to another table by a foreign key
    primarykey
    data
    text
    <p>i'm having a problem where i have created two tables in MYSQL where one table is bookticket and the other table is the customer table.</p> <p>customer table <strong>customer_id(pk)</strong>,fullname,matric_id,ic_no,gender,address,postcode,state,hp_number,tel_number,username,password,repeatpassword.</p> <p>booktickect table <strong>ticket_id(pk)</strong>,liner,direction,from,f_date,f_time,destination,t_date,t_time,total_price,<strong>customer_id(fk)</strong></p> <p>So now after i have registered and login as a user,how can i create a php code to enter the bookticket data where it will be automatically assigned to the current logged in user based on the customer_id foreign key that i have implemented in my bookticket table.Thank you in advance.</p> <p>Sorry for not providing my php code in my earlier post.I have edited my question. :)</p> <pre><code>&lt;?php echo "&lt;h1&gt;Booking&lt;/h1&gt;"; $submit = $_POST['submit']; //ticket booking form data $liner = strip_tags($_POST['liner']); $direction = strip_tags($_POST['direction']); $from = strip_tags($_POST['from']); $f_date = strip_tags($_POST['f_date']); $f_time = strip_tags($_POST['f_time']); $destination = strip_tags($_POST['destination']); $t_date = strip_tags($_POST['t_date']); $t_time = strip_tags($_POST['t_time']); $total_price = strip_tags($_POST['txttotal']); if ($submit) { //check the direction selected by user if ($direction == "return") { //check for existance if($liner &amp;&amp; $direction &amp;&amp; $from &amp;&amp; $f_date &amp;&amp; $f_time &amp;&amp; $destination &amp;&amp; $t_date &amp;&amp; $t_time &amp;&amp; $total_price ) { $connect = mysql_connect("localhost" ,"cc11205","11205"); mysql_select_db("cc11205"); $queryreg = mysql_query(" INSERT INTO bookticket VALUES ('','$liner','$direction','$from','$f_date','$f_time','$destination','$t_date','$t_time','$total_price',''); "); die("Your booking details has been succesfully inserted into the database.Please &lt;a href='customer.php'&gt;Click here&lt;/a&gt; to go to the main page to view your booking"); } else echo "Please fill in &lt;b&gt;all&lt;/b&gt; fields!"; } else if ($direction == "oneway") { if($liner &amp;&amp; $direction &amp;&amp; $from &amp;&amp; $f_date &amp;&amp; $f_time &amp;&amp; $destination &amp;&amp; $total_price ) { $connect = mysql_connect("localhost" ,"cc11205","11205"); mysql_select_db("cc11205"); $queryreg = mysql_query(" INSERT INTO bookticket VALUES ('','$liner','$direction','$from','$f_date','$f_time','$destination','','','$total_price',''); "); die("Your booking details has been succesfully inserted into the database.Please &lt;a href='customer.php'&gt;Click here&lt;/a&gt; to go to the main page to view your booking"); } else echo "Please fill in &lt;b&gt;all&lt;/b&gt; fields!"; } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload