Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


Advertisements:




SuperbHosting.net & Arvixe.com have generously sponsored dedicated servers and web hosting to ensure a reliable and scalable dedicated hosting solution for BigResource.com.







Insert Data From Another Table With Foreign Key?


I have a problem inserting a data into another table that has foreign key using PHP. I have a table named CUSTOMER_INFORMATION with fields(customer_no(PK), first_name, last_name, etc..) and a CATERING_RESERVATION table with fields(catering_no(PK), type_of_event, number_of_persons, customer_no(FK), etc).. I wanted to insert the customer_no in the CATERING_RESERVATION table but I have this error:

"Cannot add or update a child row: a foreign key constraint fails (`thesis/catering_reservation`, CONSTRAINT `catering_reservation_ibfk_1` FOREIGN KEY (`customer_no`) REFERENCES `customer_information` (`customer_no`) ON DELETE CASCADE)"

But I think I lack some codes on this. I'm just a newbie in php.[code]...

I AM TRYING TO INSERT THE DATA AT THE SAME TIME..


View 1 Replies (Posted: Mar 20 at 15:30)

Sponsored Links:

Related Forum Messages:
Insert Query Doesn't Insert Data To Mysql Database Table?
i have a recipe table and ingredient table the primary key of both tables are auto increament and primary key of recipe is foreign key in ingredient. i post data from html to php.Note that my ingredient textboxes are generated dynamically and successfully post the data to php script. posted data is correct when i insert this data to table my query working fine but data is not added to mysql table. my code and output is

$sql = "insert into recipe (rec_id, Name, Overview,category, Time, Image) values ('', '$name','$overview','$category','$time','$TARGET_PATH')";
$result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
$rec_id = mysql_insert_id();

[Code].....

Posted: Dec 10 10 at 8:13

View 5 Replies!   View Related
Grab Data From A Table, Echo, Then Insert It Into A New Table...
I'm trying to do is count the number of times usernames shows up in a table. I then want to reinsert that information into a different table with the Username in column1 & the occurrences in column2 for every user that is echoed on the page. Code:

Posted: September 18, 2007, 01:34:07 AM

View 5 Replies!   View Related
Checkbox Form - Insert Row Data From One SQL Table To Another Table?
I have two tables "tbl_jobs" and "tbl_jobs_done". I have an SQL query which displays and formats my daily job list from tbl_jobs SQL database, and has a checkbox at the end of each row. I want to be able to select 1, 2, 3 or more checkboxs and then click my submit button which will then insert the data into my second MySQL database named "tbl_jobs_done". i have spent hours and hours looking at tutorials and other peoples forum posts but can't seem to find something that hits home and works for me I only need the jobs_id field data from the tbl_jobs to be inserted into tbl_jobs_done table and into jobs_id field. I have other data on the form that will also be submitted. But in general, that's all I need. Here is my SQL Query ->

[Code]....

Posted: November 15, 2009, 11:16:49 PM

View 4 Replies!   View Related
Find All Of The Rows In The Primary Table That Doesn't Exist In The Foreign Table
i have 2 databases, one uses the primary key of another as the foreign key. I want to find all of the rows in the primary table that doesn't exist in the foreign table. e.g:

table jobs:

job_id
company_id
job_name
job_text
date
...

table companies
company_id
company_name
...

from the example above i want to find all companies that have NOT had any jobs between one date and another.

Posted: 08-19-2005, 08:39 AM

View 5 Replies!   View Related
CakePHP - Custom HasOne Object Association - Using A Join Table Instead Of In-table Foreign Keys?
In CakePHP, I'm trying to build a $hasOne relationship, but I can't add a foreign key to the tables (for legacy reasons). Is there any way I can create a join table (object1_object2) and link them together like this? I want to leverage Cake's powerful object relationship functionality, so if there's a way I can make this custom association permanent throughout the model, without always building a custom $options array for each find(), that'd be great. (Maybe a bindModel in the Model's initalize()?)

Posted: Sep 22 10 at 15:33

View 2 Replies!   View Related
Use Multiple Foreign Keys In One Table Referencing Another Table In Cakephp?
Using cakephp, I have a generic address table, which I want to link to customers, vendors, contacts. most of the tables only have a 1 to 1 relationship, but I want my customers table to have 2

perhaps for clarification: I have a customers table

id, int
mailing_address_id, int
billing_address_id, int

and an addresses table

id,int
addr, varchar
city, varchar
etc....

Now I know I could put a customer_id in the addresses table. But I don't want to do that because I have a vendors table, and contacts table, and other tables that all are going to use the addresses table. the customer_id would not really be relavant to those other tables.

I'd like the Customer model to automatically link in the two addresses

Posted: Mar 17 09 at 16:45

View 4 Replies!   View Related
Update Table While Insert Data To Another Table
it seem like mine coding din work.
[php]<?

include("checkin.html");
$conn=mysql_connect('localhost','root','') or die ('Could not connect to server');
$today = date("Y.m.d");
mysql_select_db('hms', $conn);

$ok = mysql_query("INSERT INTO check_in(ID,room_no,datein)values ('$ID','$room','$today')", $conn);

if( $ok ){

$up = mysql_query("UPDATE studtable SET checked = 'checkin' where [ID] = '%ID');

if(mysql_affected_rows( $up ) == 1)
{
echo'Checked IN!'
}else { echo'No such student to check in' }}
else { echo'Check In FAILED, please check again'}?>[php]

Posted: February 7th, 2006, 10:51 AM

View 1 Replies!   View Related
Put The Value Of One Field In The First INSERT Into The Second As A Foreign Key
I am developing what could be likened to a very simple php/mysql forum solution for a client. I have come to an instance where I need to do two INSERT queries on my MySQL database to put data into two tables. However i need to put the value of one field in the first INSERT into the second as a foreign key sorta thing.

The field i need the value for is an auto incrementing field. Is it possible to return the value of the auto incremented field after and INSERT query so that i can then use this value and insert it into the second table. I think I could probably do this by doing a SELECT query in between to find the max value of that column and then use that but I can't see this being the most efficient method.

Posted: 4:26 pm on Nov. 25, 2004

View 1 Replies!   View Related
Using Session To Insert Foreign Key?
i am trying to use a session to insert in to the database a user_id of a user who is posting a topic in to the topic table to act as a foreign key in the topic table. but i kept getting 0 in the user_id column instead of the real userid below is my code.

<?php require_once('Connections/forum_con.php'); ?>
<?php
//initialize the session
session_start();
require_once('Connections/con_user.php');

[Code].....

Posted: Aug 5th, 2010

View 2 Replies!   View Related
Insert Data And View Data From Multiple Table?
Can some 1 tearch how to insert data and view data from multiple table, by primary key and unique.

Posted: Jul 24 09

View 8 Replies!   View Related
MySQL Insert With Undefined Foreign Key?
I have some table with such schema (simplified):

CREATE TABLE folders(
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
parent INT(11) UNSIGNED NOT NULL,
PRIMARY KEY (id),
INDEX FK_folders_folders_id (parent),
CONSTRAINT FK_folders_folders_id FOREIGN KEY (parent)
REFERENCES folders (id) ON DELETE CASCADE ON UPDATE CASCADE
)

1 folder can have many subfolders and can belongs to one another folder. If it's root folder then parent will contain it's own ID. The problem is: how can I create root folder? ID is auto_increment and I can get it only after inserting a row but I cant insert row while parent is not defined. Recursion...

Posted: Feb 5 at 16:41

View 1 Replies!   View Related
Insert Data To A Table
I just can't figure out why it isn't sending the data to the table, I've check the names over and over, all the info is parsed correctly, but it falls flat at: $result = mysql_query($sql);

Posted: June 16, 2007, 11:25:30 PM

View 4 Replies!   View Related
Insert Data To Table
i have a user(members) form that pulls from my database 3 fields: name, age, about. i want the user to be able to edit their info then re-submit back to the database. however, i want to have some control as to what they edit their info to. so instead of just update the info back to the database.

i want to hve any fileds that have 'changed' by the user get put to a different table(review), so after i have approved the changes i will 'update the master user table. is there a logical way that i could do this, i guess just flag any fields that have changed when the user form is submitted.

Posted: November 08, 2007, 11:04:38 AM

View 1 Replies!   View Related
Insert Data Into A Table
PHP Code:

<?php
$connection = mysql_connect("localhost", "******", "******");
if (!$connection)
{
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("trickyph_testdb1", $connection) or die('Could not select DB.');
$query = "INSERT INTO users (FirsName, LastName, Address, City) VALUES ('Jimmy', 'Watts', &#39484; Wolfer Ln.', 'Springston')";
mysql_query($query, $connection);
mysql_close($connection);
?>

Posted: 07-21-2007, 07:54 PM

View 5 Replies!   View Related
Insert XML Data To SQL Table
how to handle xml files. Here's the scenario, I have XML file, i want that each data from my xml file will be inserted into my database. How can I do that?

Posted: Posted 03 March 2011 - 02:06 AM

View 5 Replies!   View Related
Data Not Getting Insert In To Table?
I am getting the error msg; Mysql error, data not saved, try again -You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 7

PHP Code:
<?php 
// PUT YOUR DATABASE CONNECTION SCRIPT HERE 
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="merchandising"; // Database name 

[Code]...

Posted: Mar 4, 2011, 15:08

View 2 Replies!   View Related
Insert Data Into A Table?
I am trying to insert data into a table, but I am not able to insert it. I wanted to see what the error was using mysql_error() function, but it does not return any error string for me.

global $error;
[code]....

Posted: November 10, 2009, 05:39:58 PM

View 2 Replies!   View Related
Can't Insert Data Into Table?
// set date variables

date_default_timezone_set("America/New_York");
$date=date("l F d, Y, h:i:s");
$datedb=date("m.d.y");
[code].......

Posted: July 18, 2010, 07:16:04 PM

View 4 Replies!   View Related
Using An Array To Insert Data Into A Table.
This works:
$col1 = 2;
$col2 = 2;
$col3 = 2;
$col4 = 2;
$query = "INSERT INTO test (a,b,c,d) VALUES ($col1,$col2,$col3,$col4)";

and this does not

$col = array(2,2,2,2);

$query = "INSERT INTO test (a,b,c,d) VALUES ($col)";

Posted: July 17th, 2005 09:40 AM

View 6 Replies!   View Related
Mysql_query - Insert Data Into A Table
I have the following code to insert data into a table. Why doesn't it work?

$db=mysql_connect("mysite.com","username","pw");
mysql_select_db("site_log",$db);
$query="INSERT INTO logs (ipaddress,sid,cid,vid) VALUES ($ipaddress,$sid,$cid,$vid)";
mysql_query($query);

Posted: 12-07-2006, 03:25 PM

View 3 Replies!   View Related
Insert Data In A Html Table
here is the code:

<?
$a=array(1,2,3,4,5,6,7,8,9,10);
$b=array(1,3,5,7,9);
$c=array(1,1,2,2,3,3);
$d=array_count_values($b);
$e=array_count_values($c);

foreach($a as $key)
echo '<table><tr><td>'.$key.'</table></tr></td>'

foreach($d as $key=>$value)
echo '<table><tr><td>'.$key.'<td>'.$value.'</table></tr></td>'

foreach($e as $key=>$value)
echo '<table><tr><td>'.$key.'<td>'.$value.'</table></tr></td>'.

Posted: July 17th, 2005 09:59 AM

View 2 Replies!   View Related
Fastest Way To Insert Data Into Table?
I am trying to find the fastest way to insert data into a table (data from a select) I always clear the table:

TRUNCATE TABLE table;

Then I do this to insert the data:

INSERT INTO table(id,total) (SELECT id, COUNT(id) AS Total FROM table2 GROUP BY id);

Someone told me I shouldn't do this. He said this would be much faster: CREATE TABLE IF NOT EXISTS table (PRIMARY KEY (inskey)) SELECT id, count(id) AS total FROM table2 GROUP BY id I think my solution is cleaner, because I don't have to check for the table.

Posted: Jun 19 09 at 10:36

View 7 Replies!   View Related
Can't Insert Data In Pmsout Table
I'm trying to insert some data into 2 tables, in the first table the data are going OK, but in the second no ... why?

<?php
session_start();
include ("blocks/db.php");
if (!empty($_SESSION['username']) and !empty($_SESSION['password']))
{
$username = $_SESSION['username'];
[Code]...

The problem is: I can't insert data in pmsout table

Posted: Posted 29 June 2010 - 03:33 PM

View 5 Replies!   View Related
Insert Xml Data Into Mysql Table?
So far I can read and print the data using simple xml or dom. My next step is insert the data into a mysql table.

Posted: 10-17-2010, 06:04 AM

View 3 Replies!   View Related
Insert Data Into Different Database Table?
Through one html form how to insert data into different database table.

Posted: May 15 09

View 23 Replies!   View Related
Insert Data Into Two Table From A Web Form?
table person
"person_id"
"person_name"
table email
"email_id"
"email"
"person_id"

What is the sql comment for insert data form a web form into these tables? In the web form I have a text box for name and dynamic text box for email

Posted: Jun 24 at 10:09

View 4 Replies!   View Related
What Is Required To Insert New Data To A Table
I am trying to create a simple form for inserting to a database table. It seems the data from the form are passed through the "insert" script, but nothing is added to the table. My question is: what is required to insert new data to a table? must all fields have a value for the new data to be added?

Posted: April 12, 2011, 05:24:29 PM

View 2 Replies!   View Related
Insert Data From A Form Into Table?
Anyway, here goes.I have 2 tables

Table 1
Levels
[code].............

Posted: December 23, 2010, 08:23:10 PM

View 2 Replies!   View Related
Insert Into Multiple Tables Linked By Foreign Keys (MySQL)?
I've managed to get (in my opinion) quite far surfing forums for any problem I encounter, but now I’ve hit a wall and can't find the solution anywhere.  As most of the previous answered I found were on this site, I hope you don't mind me asking my question!The problem:  I have two tables: customerdetail (with primary key custid) and customeraddress (with primary key addressid and foreign key custid). My insert statement was working perfectly inserting into both tables from one form.  As soon as I create the foreign key for customeraddress (in phpmyadmin) my insert statement only working for customerdetail (i.e the table without the foreign key), and nothing gets inserted into customeraddress.I suspect this is because I’m inserting into both tables using one php form and therefore customeraddress can't pull the foreign key from customerdetail as it’s not been created yet...but i have no clue how to solve this or if it really is the problem.QuotePHP Code:

<?
$localhost="xxx";
$username="xxx";

[code]...

Posted: March 06, 2011, 03:28:50 PM

View 9 Replies!   View Related
Make An Application To Insert New Data Into A Table
I´m trying to make an application to insert new data into a table. So i extract the fields of the table and let the user introduce new values. The problem is when i´m trying to put them into a table.

Firstly i get the new data sent via form with a while loop, because the number anda name of the fields can be different in each case. I do it like this

$sql = " SHOW COLUMNS FROM " .$_SESSION["nomtab"]. " ";

$res= mysql_query($sql);

while($row = mysql_fetch_array($res))
{

$$row[0] = $_POST["$row[0]"]; }

Now i introduce correctly the first´s field value and i create two auxiliar variables $primercampo and $valorprimercampo which contains the name of the first field and its value, so i can use them later to update the values, it goes like that Code:

Posted: November 23, 2007, 08:00:01 AM

View 3 Replies!   View Related
How To Insert Data Into Table With " Marks
I was trying to insert a double quote " mark in to my field along with some text and could not find a way to do it.

Is it possible to do something like: '".$value."' to concatenate a " with a variable then another " ??

Posted: 11-21-2005, 12:41 PM

View 5 Replies!   View Related
Insert Array Data To Mysql Table
I need some advice regarding inserting data from a form to a mysql table. I am unable to get the data posted into the table.

Following are my two files : First file generates dynamic input fields and stores in a array (i hope my syntax is correct). Then upon submit i want the values to be inserted into the table. Code:

Posted: 12-28-2005, 04:44 PM

View 5 Replies!   View Related
Insert Data Into A Database And Display It In A Table.
I have managed to insert data into a database and display it in a table. i just did a very basic example to see if it would work. Code:

Posted: April 01, 2007, 03:30:11 PM

View 5 Replies!   View Related
Insert Data From A Pick List In To Table?
I am working on a script which uses a pick list allowing users to pick items from a list (single or multiple items) and insert them in to a table.I am using code provided by PickList II script (aka Menu Swapper)- By Phil Webb (http:[url]...)My form has 2 text select objects:

List one contains a list of items, list 2 would contain the items selected from list 1.Once the list 1 items have been selects and moved to list 2 I want to save the list 2 items in to my table.The code so far only allows one item in list 2 to be written to the table but not multiple items.

CODE'

PHP Code:

<form method="post" name="form4" action="<?php echo $editFormAction; ?>">
            <input name="member_id" type="hidden" value="<?php $_SESSION['_amember_user']['member_id']; ?>" />
<select  multiple size="10" name="list1" class="packinglist" style="width:350"[code].....

Posted: 10-17-2009, 05:34 AM

View 3 Replies!   View Related
Check Existing Data Insert Into The Table?
im inserting data into the table using drop-down list & multi select list,well it works very well. but i need to make sure i should not insert same StudentID & CourseID twice. here my code for you could anyone tell me pls where should i write code to check existing data?

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error());
$result  = mysql_query("SELECT * FROM student") or trigger_error('MySQL error: ' . mysql_error());
echo '<select name="sid">';

[Code]...

Posted: November 08, 2010, 06:33:54 PM

View 6 Replies!   View Related
Trying To Insert The Data To Hbase Table Wth One Cloumn?
I am trying to insert the data to hbase table wth one cloumn family info with column keys name,age..in table hbase format should be like this

row column+cell
1 column=info:name timestamp=--- value=vani
2 column=info name timestamp=--- value=veena

.. the above this be the format.. then I am using THrift API with hbase +php..Now I have to write php code for above data insertion to hbase table

Posted: May 30 at 6:33

View 1 Replies!   View Related
Insert Data Into Top/beginning Of Mysql Table?
im using this code atm and it's working, but the new rows created are put in the end of the table. I want them to stack up from the beginning pushing older rows down.

<?php
$con = mysql_connect("localhost","*****","*******");
if (!$con)
{

[code]...

Posted: December 23, 2010, 12:25:42 PM

View 7 Replies!   View Related
Insert Data Into A Table If It Doesn't Exist
I need to insert data into a table if it doesn't exist or update if it does.

im using mySQL 5.1.42 im using phpMyAdmin 3.1.o

Posted: July 31, 2010, 05:25:21 PM

View 12 Replies!   View Related
Reading Data From EXCEL And Insert Into Table?
I have to search record on the basis of excel sheets column field from a table and then insert whole row into a table. How I can do this ?

Posted: Jun 2nd, 2011

View 2 Replies!   View Related
Copyright © 2005-08 www.BigResource.com, All rights reserved