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]
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Insert To One Table, Update To Another
I'm trying to do two queries at once utilizing data from a form. I'm creating a new row in one table, and I need to reflect the ID number and other supplementary data to an existing record in another table. Is there a way to string two queries together so they execute at the same time? Here's what I've been trying so far: Code:
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);
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)";
Form Data Array - Need To Update Table
I have a form that is dynamically generated by the fields I have in a table. This table generates the navigation for my site, and I want to create a page that will allow me to reorder and hide/show and activate/deactivate the links. The form is working and I have the form generating an array based on the data collected on submit. I need to know how to break this data apart so I can update my site navigation table with the correct values. The table looks like this:
Using PHP To Sort Data In MySQL Table 1 By Values In Table 2
I have a MySQL database with 2 tables in it. products and prices.. Products has a field in it called 'prodno'. Prices has a field in it called 'prodid'. There is one of each item in products and each product has it's own unique 'prodno' There are multiple instances of each product's pricing in prices.. One for each price.. So if a product had multiple prices depending on quantity it would have an entry for each price.. Example: id = 1 prodid = 7001 qty = 300 price = 12.5 id = 2 prodid = 7001 qty = 400 price = 15.5 I was wondering if I could query the database getting info from the products table but sort it according to the prices in the prices table. Kinda like doing a "SELECT * FROM products" ordering it by the lowest price value from each item.. This is all very confusing to me, and I'm the one writing it. Let's try one last time.. Query the database selecting * from products (I plan on using all the info in products) and ordering them by the lowest price for each item in the prices table. I've tried sorting the results of just a basic SELECT * FROM products using Javascript and PHP but with pagination in the results it makes it a bit hard.
UPDATE Table
I am trying to update a table from a form. Right now it is not updating. I'm still new to the php mysql world so most of code comes form books I have or searches on the internet. I have been trying to figure this one out for a while. Code:
UPDATE To Table
I have been having problems with updating a table of mine for the past few days and cannot find a solution or reason why it is not working. What happens with the code below is a user logs in so an query is made to update their login status to 1 (0 = logged out, 1 = logged in). Then to make sure that the update to the database is made there is a check to see if it has been changed to 1 before the page is redirected to logged_IN.htm (the code below does find $login_num = 1). The problem is that in the table after the header function is executed. The value for login never changed to 1 in the table, it is always still 0. If I remove the header and have it not redirect to another page the login value in the table does change to 1. I have tried using 2 different servers also and still have no luck. Code:
How To Check And Update Table?
I am trying to work out the best way to update the details in a table I have for customer data. Each time the customer interacts with the script all the data that is used in the table is sent to the script from an external source. What I want to do is check to see if the email address is already in the table. If it is I want to check all the other fields and update the data. If the email address is not in the table I want to add all the details as a new user. I am playing with this code but I can't see to get check right to see if the email address exsists. This code always inserts a new customer into the table.
Php, Mysql And Update Table
I have one mysql table and I need to update it by form. But what is the best way. I think First I need atleast following php-files: list.php --> list all data rows from my table included link to select certain row and update.php --> ...when selected you will get form view where you can update field updated.php --> update your database table.
Insert Into Table Using For Loop
i managed to get bits a pieces and managed to get this script to nearly work. I put together this script which a)gets a no. of fields to create 2) creates those fields 3) on submission it checks for blank fields & may display error msg 4) also it checks in the db for duplicates & may display error msg 5) if all good it submits to db. Here comes my dilemma. 1, 2, 3 and 4 work fine however the final part 5 doesnt work at all. 5 works if 3 and 4 are taken away for some reason. I am sure there i am missing something. Can someone please take on the challenge and direct me to where i could be going wrong. PHP Code:
MS Access And Php- Insert Row In A Table
I am not able to insert a row through a form in my database which is in Access.Please see my code below and help..Select works O.K. but inserting through form is a problem.This is form1.php.here I am inserting the values.This form has action process.php......
Switch And Insert Into Table
I want to build a questionnaire with php. My problem is that the second page where i insert the results into the database doesnt work. Code:
Mulitiple Table Insert
I have a table that when you add a new department it will add the name to the table and assign the row and id based on an auto_increment column. From there you need to get the value of the last insert id. SO what I did was use the msql_insert_is() function. and assigned it to a variable. I then used that variable in my next query because this vaule is a forigen key in another table. Here is my code it should be exectued if you where to post this page with the value of $department_id = "" then the section of script in question will execture. Essentially need it to grab this id number and then place it into 2 more insert statements that should execute immediately after the first insert statement. Then only insert id that I would need is the one produced in the first insert statement what an auto increment value is assigned to the same table as the department_name Code:
Multiple Table Insert
I have a table that when you add a new department it will add the name to the table and assign the row and id based on an auto_increment column. From there you need to get the value of the last insert id. SO what I did was use the msql_insert_is() function. and assigned it to a variable. I then used that variable in my next query because this vaule is a forigen key in another table. Here is my code it should be exectued if you where to post this page with the value of $department_id = "" then the section of script in question will execture. Essentially need it to grab this id number and then place it into 2 more insert statements that should execute immediately after the first insert statement. Then only insert id that I would need is the one produced in the first insert statement what an auto increment value is assigned to the same table as the department_name Code:
MySQL Index And UPDATE Table
"When you update a table with an index, you have to update the index as well" What does this mean? For example, my table has four columns:
Can't Update Mysql Table Via Php Form
I have a form that updates an item pulled from a database, but after the form is posted, it does not update the mysql database with the new info, here's what I am using: Code:
HTML Table Update Row PHP/MySQL
I have a dynamic HTML page with 4 columns of data, retrieved with PHP from a MySQL database. At the end of every row I have an UPDATE submit button, which activates a php update script to update the database. I now encounter the problem that in the update script I cannot trace back for which row the UPDATE buttom was pressed. I first had defined the UPDATE button as : <input name="update" value="UPDATE" type="submit">. That doesn't work ... If I change the definition to <input name="update" value=<? echo "UPDATE".$nt['id']; ?type="submit">, then I can get the id number in the update script, but the display is not that good, because you see UPDATE1, UPDATE7,UPDATE4 and so on ... So I need something, so I can find back in the update script for which row the update button was pressed. Each row has his unique id (which is not shown in the table)
Insert Into Table Via Assoc Array
I am trying to populate data from an array into a table, but i cant figure out what i am doing wrong. //mysql query $sql = "SELECT charge_location.dept_code, charge_location.week, Sum(charge_location.total_hrs_paid) AS sum_of_total_hrs_paid, Sum(charge_location.hrs_non_chargeable) AS sum_of_hrs_non_chargeable FROM charge_location GROUP BY charge_location.dept_code, charge_location.week"; $result = mysql_query($sql); $num_results = mysql_num_rows($result); //populate the stats_table for($i=0; $i<$num_results; $i++){ $row = mysql_fetch_array($result); mysql_query("insert into stats_summary values( ($row[dept_code]), ($row[week]), ($row[sum_of_total_hrs_paid]), ($row[sum_of_hrs_non_chargeable])) "); } PS i get no errors when it executes, just fails to populate the table.
How Do You Insert A Value From Drop Down List To SQL Table?
I am a bit new to PHP and SQL so this may seem like a dumb question. I have already created a drop down list as part of a form which is automatically populated with values taken from a separate database. When a user goes onto this page and either leaves the default value or selects a value from the drop down list and presses the submit button, I would like that selected value to be stored into a database which I have already created in SQL. Just to let you know that I can do the above using a text field but just don't know how to do it with drop down list. If your going to explain any coding then it may help if I give you the names of certain items that are involved. Database is called "Company" Field within database is called "Name"
Multiple Table Insert With Php Mysql
I am having and issue getting this code working. It seems rather simple but I cannot figure out why only one sql statement is exectuing and the insert statements the other 2 are not exectuting and updating the other 2 tables. I need to do this. I need to update one table, then from that I need to retrieve the mysql_insert_id or just get the id of the last record in the tabe. There is an auto increment column that gets assigned a unique id each time a record is inserted. I need this id number then I need it to place data into 2 other tables that will use this value as a reference. here is the code:
Update MySQL Table Row Upon Leaving Site
How would I update a mysql table row when a user closes their window when they're logged in to my site? I want it to update a table row called logged_in when they close the window without logging out of the session. Is this possible?
Using Update To Give A Table Default Values
I have a table that is already created but all the fields are set to NULL by default. How would I go about changing this with a mysql_query(), so that if only say 2 of 5 fields are given a value for a column the rest will fill with the default value?
Insert Into Microsoft Access Table Using ODBC
The following lines of code don't return an error but they also do not insert the row into the database: $SQLText="Insert into member (MailingID, MemberID, [File As], EMail, LetterID, AudienceID, DateSent, Sent) Select $MailingCode, $row[0], '".$row[5]."', '".$row[6]."', $LIDToInsert, $AIDToInsert, '".$DateSent."', 1;"; print '<br>'.$SQLText; $rs_upd=odbc_exec($link, $SQLText); if (!$rs_upd) die("Couldn't update database"); I've tested the resulting $SQLText string in Access directly and it works find there so this must be a PHP or ODBC issue.
Insert New Row In Table After 5 Lines - Detect Whole Number?
I have a script that loops through an image directory to create a table of thumbnails. I want to start a new row after every fifth thumbnail. I assumed there was a function which identified whole numbers, but alas, there doesn't seem to be. How do I produce a short version of my long, working version below. PHP Code:
Insert Empy Variable Into Mysql Table
I've got a form in which a couple of the address fields can be empty when the form is submitted... I haven't actually managed to get the Insert statement to work yet (see other post..), but I know this seems to also be causing problems. I have set up the table fields for these 2 address form fields to be Yes under the NULL column, but it still gives the almighty: 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 ' , London, W1, UK, 9991, 007, 'warstormer@hotmail.com'' at line 1 Code:
Php Script To Perform Mysql Table Insert
I'm trying to have my php script insert into 2 tables at once, it's for a picture database. Is it actually possible to insert into 2 tables at once? If so what would the sql statement look like.
Multiple Table Insert From Tab Delimited File
I have a page I'm coding for batch updates from a tab delimited file. Each row has data that has to be checked against and inserted/updated on different tables in my mySQL database. How would I go about parsing through the tab delimited file and then storing data between the tabs in order to insert individually into separate tables?? Here's what I have so far... $contents = file('/myfile.txt'); for ($i=0; $i<sizeof($contents); $i++) { $line = trim($contents[$i]); $arr = explode(" ", $line); $line[$i] = array('ID' => $arr[0], 'Record_Type' => $arr[1], 'First_Name' => $arr[2], 'MI' => $arr[3], 'Last_Name' => $arr[4], 'Firm' => $arr[5], 'Address' => $arr[6], 'type' => rtrim($arr[13])); I need to take the different columns.. ID, Record_Type, etc. and update different tables with each value where the IDs match.
Store Result Of SELECT Stament To Be Used To UPDATE Another Table
im trying to update a field of a table which is done through the results of a select statement. I need to be able to a store the results of the select statement which can then be used to determine if an update another table is initiated. This is where i have got so far: Code:
Multi Table Insert Delete Select Function Needed.
I am going nuts here and I know with all the functions out there, there must be an easier way to do this. Maybe someone can point me to the right tutorial or even show me how to do this. I have a $main_id and many $sub_id tables and like to “SELECT to view” INSERT and DELETE those. UPDATE must not be but would be nice. Here is how it looks:
Grab Content From HTML Table And Place Into MySQL Table?
I am in the process of helping a co-worker upgrade some of his old static html pages into dynamic MySQL driven pages. He currently has a lot of pages with huge tables displaying data. Does anyone know if there is a script or class that can convert a table to a .sql file for upload?
Table Background Color Based On Results From MySQL Table
I am trying to get the "Did User Agree" field on a database query to be colored Green for "Agreed" Red for "Disagreed" and Blue for "Agreed (2nd Time)" .. I have my PHP setup to do the query just fine as of right now with alternating column colors, just can't seem to get the colors to work as I am hoping for. Can anyone help me get the Agreed? table's background color to the colors above? Code:
Outputting A Table Or Form Using SHOW FIELDS FROM Table
In the code the MySQL database was queried using "SHOW FIELDS FROM table" which and the returned results of column names was then use to build an output for a form and a table with php using a series of if statements along the lines of if the returned field name matches something echo a text input field. I have never seen this done this way before, so I want to get the opinion of the devshed user. Does it seem like an unsual long process to build up a form. Is there a security advantage doing it this way? Has anyone ever done it this way before?
Finding Matches In A Table And Then Moving That Match To Another Table?
Ok, I have a database that has a table called critiera in this table is to fields on is ID and the other is critiera. Now I want to filter out all the one that don't apple to the list and move the one that match to a different database. I know how to open a connection, close, select but I don't know how I would inside of a database use another one as the way to create the list of critieras....
Mysql Fetch_field Gets Table Alias, Not Real Table Name
After a SQL 'select .... from tablename alias' the mysql_fetch_field function returns a value $result=>table which will contain the alias, not the actual table name. Is there a way to get the actual table name ? I am running mysql 4.1 and php 4.4
Table Data
I have a table on a php page with the cells containing database data from a mysqldatabase. what would be the easiest way to allow a user to change how the data is listed by clicking on the top of each data column? I have seen this feature on most applications but cant figure out how to doit??
Table Data Row
I have a script that pulls information from a table. This table contains foreign id keys for other tables. This code works just fine, but pulls id numbers. I would like to make a change to this file to convert the id numbers into their matching names. I have tried to use this type of code:
Data Into Table
I'm trying to get a neat and clean readout of all of the parasites that are in the MySQL table. Right now everything works except all of the info is all over the table and I can't seem to get the table to be clean and presentable for when I open my site to the public. Code:
Help Listing Data In Php From My Table.
I have a result set that came from the query "SELECT * FROM characters" and I want it to list on my php page the results like: Name gender race Name gender race Name gender race How could I do that?
Inserting Data Into A Table
I would like to know if there is anything strange about the script below(I have only just started to learn php so there may well be!) Although it seems to work, occasionally it doesn't just insert a single row into the data base, instead 2 or 3 duplicate rows end up in the table. Could the explanation be that I tried this morning to create a table and forgot I already had one with this table name in the database. Would that have damaged the table in some way making it misbehave! I have commented out the bit about creating tables as I only want to insert data with this script at the moment. One other thought occurs to me, is the problem due to my host freedom to surf as its only a free host and I expect you get what you pay for(or don't pay for in this case). I have subscribed to a pay host http://www.phpwebhosting.com but I am unable to use the database that they have provided because they have informed me that I must use a telnet shell to log into my database and I have absolutly no idea what this is(is it in my Win98?) or do I need to go and get one. I am still waiting for this host to email me back with some help. If there is anyone out there who could tackle all or some of my problems I would be very grateful indeed! One last thought - I think there is something very strange going on as sometimes when I visit my database, there is less entries in this table than last time, some have been chucked away and my id entries are all out of order now, something like 1,2,3,11,5,7,12 - the last insert had id = 12 next to it and somehow another duplicate has sprung up id = 11???????? Whats going on please! <html> <head> <title> Connecting to Mysql server at ISP host</title> </head> <body> <?php $Host = "db.davegraham.f2s.com:3306";// Set the variables for the database access: $User = "p0c79"; $Password = "********"; $DBName = "p0c79"; $TableName = "Jokes2"; $link = @mysql_connect("$Host", "$User", "$Password"); if (!$link) { print("<P>Unable to connect to the " . "database server at this time.</P> "); //note how 2 strings have been concatonated exit(); } else { print("Your now connected to the Mysql server at the host ISP.<P> "); } if (! @mysql_select_db("$DBName") ) { print("<P>Unable to locate the $DBName database at this time.</P> "); exit(); } else { print("The database $DBName has been located.</P> "); } /* $sql = "CREATE TABLE $TableName (ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, JokeText TEXT, JokeDate DATE NOT NULL )"; if ( mysql_query($sql) ) { print("<P>$TableName table successfully created!</P> "); } else { echo("<P>Error creating $TableName table: " . mysql_error() . "</P>"); } */ $Query="INSERT into $TableName VALUES(Ɔ', 'hello hello hello!', ��-08-08')"; if (mysql_query ($Query)) { print ("The query was successfully executed!<br> "); } else { print ("The query could not be executed!<br> "); } mysql_close($link); ?> </body> </html>
Column Data From One Table To Another
im trying to get the vend_name column data from one table(manuf) into another table (products2) that has the same vend_name column which is empty but has a vend_code column as a key identifier. im wondering if theres a way to put the data from the vend_code column and vend_name column from the first into an array so that i can populate the vend_name column of the 2nd table this is what ive come up with below, it seems to be just puting the last record into those two array variables PHP Code:
Entering Data Into A Second Table:
Using a script, I able to insert the data into the first table of my mysql db, but when I try to insert the same into second table(duplicate, so same vars, etc.. no prob at that level), it doesn't go through. It doesn't even make an empty row(which would mean wrong vars) Someone told me to check in the logs of both PHP and mySQL. How do I do this?
Copy Table Data To Another
I've been searching in the PHP forums for this answer, and I've found something similar, and have used to this to the problem I have. Anyway, when I do run this script I get an error line 5 which is the 'while' statement. $query_newsfeed = "SELECT itemid,heading,news_date,content FROM newsfeed"; $query1_exec = mysql_query ( $query_newsfeed ); // Error here! while ( $query_row = mysql_fetch_assoc ( $query1_exec ) ) { $query2 = "INSERT INTO newsfeed_map ( itemid,heading,news_date,content ) VALUES ( $query_row[$itemid],'$query_row[$heading]','$query_row[$news_date]','$query_row[$content]' )" $query2_exec = mysql_query ( $query2 ); Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource Any ideas where I could be going wrong?
How To Replace ID With Data From Another Table.
I'm working on a project where I have a MySQL table that contains profile data. This data has 2 grouping fields one for group and one for criteria. The client wants the flexibility to edit and rename these grouping fields without having to go back and make changes to each profile. With this said, I created 2 more tables one for group and one for criteria. Tables would look like this:
|