473,698 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Transferring data from one table to another

276 Contributor
I'm writing a work order system using PHP and MySQL and I'm stuck on two things-transferring data and updating the data.

Here is my code:

i'm using checklogin.php to do most of everything so it's most likely something I'm missing here.


Expand|Select|Wrap|Line Numbers
  2. <?php
  3. $host="example.com"; // Host name 
  4. $username="gancsosa"; // Mysql username 
  5. $password="******"; // Mysql password 
  6. $db_name="gancsosa_members"; // Database name 
  7. $tbl_name="logon"; // Table name
  9. // Connect to server and select databse.
  10. mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
  11. mysql_select_db($db_name);
  12. // username and password sent from form 
  13. $Username=$_POST['Username']; 
  14. $Password=$_POST['Password'];
  16. // To protect MySQL injection (more detail about MySQL injection)
  17. $Username = stripslashes($Username);
  18. $Password = stripslashes($Password);
  19. $Username = mysql_real_escape_string($Username);
  20. $Password = mysql_real_escape_string($Password);
  22. $sql="SELECT * FROM $tbl_name WHERE username='$Username' and password='$Password'";
  23. $result=mysql_query($sql);
  25. // Mysql_num_row is counting table row
  26. $count=mysql_num_rows($result);
  27. // If result matched $myusername and $mypassword, table row must be 1 row
  29. if($count==1){
  30. // Register $myusername, $mypassword and redirect to file "login_success.php"
  31. session_register("Username");
  32. session_register("Password"); 
  35. mysql_select_db(gancsosa_crystalworks);
  37. echo "\n";
  39. $link = mysql_connect('example.com', 'gancsosa', '*****');
  40. mysql_select_db("gancsosa_crystalworks") or die(mysql_error()); 
  41. $data = mysql_query("SELECT * FROM inprogress")
  42. or die(mysql_error()); 
  45. //Transfer data
  49. Print "<br><br>";
  51. Print "Inprogress<br><br>";
  53. Print "<table border cellpadding=3>"; 
  54. while($info = mysql_fetch_array( $data )) 
  55. @mysql_query( "UPDATE INTO complete SELECT  FROM inprogress  WHERE Status='1'  ");
  57. Print "<th>ID: ".$info['ID'] . "</th> "; 
  58. Print "<th>Time: " .$info['Time'] . "</th>";
  59. Print "<th>Name: ".$info['Client'] . " </th>"; 
  60. Print "<th>Number: " .$info['Number'] . "</th>";
  61. Print "<th>Address: " .$info['Address'] . "</th>";
  62. Print "<th>Issue: " .$info['Issue'] . "</th>";
  63. Print "<th>Notes: " . $info['Notes'] . "</th>";
  64. Print "<th>Status: " .$info['Status'] . "</th>";
  65. Print "<th>Charge: $" .$info['Charge'] . "</th>";
  66. Print '<th><a href="http://www.1fixcomputermedic.com/update.php" target="_blank">Edit?</a><th>';
  67. Print "<br><br>";
  68. Print "</table>"; 
  70. Print "<br>";
  71. Print "<br>";
  76. Print "<br><br><br>Complete<br><br>";
  78. $data = mysql_query("SELECT * FROM complete") 
  79. or die(mysql_error()); 
  82. Print "<br><br>";
  84. Print "<table border cellpadding=6>"; 
  85. while($info = mysql_fetch_array( $data )) 
  86. Print "<tr>"; 
  87. Print "<th>ID:</th> <td>".$info['ID'] . "</td> "; 
  88. Print "<th>Time:</th> <td>" .$info['Time'] . "</td>";
  89. Print "<th>Name:</th> <td>".$info['Client'] . " </td>"; 
  90. Print "<th>Number:</th> <td>" .$info['Number'] . "</td>";
  91. Print "<th>Address:</th> <td>" .$info['Address'] . "</td>";
  92. Print "<th>Issue:</th> <td>" .$info['Issue'] . "</td>";
  93. Print "<th>Notes:</th><td>" . $info['Notes'] . "</td>";
  94. Print "<th>Notes:</th> <td>" .$info['Notes2'] . "</td>";
  95. Print "<th>Status:</th> <td>" .$info['Status'] . "</td>";
  96. Print "<th>Charge:</th> <td>$" .$info['Charge'] . "</td></tr>";
  97. Print "</table>"; 
  98. }
  100. else {
  101. echo "Wrong Username or Password\r\n";
  103. echo "Please try again....<br><br>";
  104. echo '<a href="http://www.1fixcomputermedic.com/login.php">CLICK</a>';
  106. }
  107. ?>
Now for my second problem.


Expand|Select|Wrap|Line Numbers
  2. <html>
  3. <?
  5. $ID=$_GET['ID'];
  6. $username="gancsosa";
  7. $password="*****";
  8. $database="gancsosa_crystalworks";
  9. mysql_connect("example.com",$username,$password);
  10. @mysql_select_db($database);
  11. $query=" SELECT * FROM inprogress WHERE ID='$ID";
  12. $result=mysql_query($query);
  13. mysql_close();
  16. //Print output
  18. $Client=mysql_result($result,"Client");
  19. $Number=mysql_result($result,"Number");
  20. $Address=mysql_result($result,"Address");
  21. $Issue=mysql_result($result,"Issue");
  22. $Notes=mysql_result($result,"Notes");
  23. $Status=mysql_result($result,"Status");
  24. $Charge=mysql_result($result,"Charge");
  26. ?>
  28. <form action="updated.php" method="post">
  29. <input type="hidden" name="ud_ID" value="<? echo $ID; ?>">
  30. Client: <input type="varchar(56)" name="ud_Client" value="<? echo $Client; ?>"><br>
  31. Address: <input type="text" name="ud_Address" value="<? echo $Address; ?>"><br>
  32. Number: <input type="bigint(20)" name="ud_Number" value="<? echo $Number; ?>"><br>
  33. Issue: <input type="longtext" name="ud_Issue" value="<? echo $Issue; ?>"><br>
  34. Notes: <input type="longtext" name="ud_Notes" value="<? echo $Notes; ?>"><br>
  35. Status: <input type="tinyint(1)" name="ud_Status" value="<? echo $Status; ?>"><br>
  36. <input type="Submit" value="Update">
  37. </form>
  39. <?
  40. //Update
  41. $ud_Address=$_POST['ud_Address'];
  42. $ud_Number=$_POST['ud_Number'];
  43. $ud_Issue=$_POST['ud_Issue'];
  44. $ud_Notes=$_POST['ud_Notes'];
  45. $ud_Status=$_POST['ud_Status'];
  48. $username="gancsosa";
  49. $password="*****";
  50. $database="gancsosa_crystalworks";
  51. mysql_connect("example.com",$username,$password);
  52. @mysql_select_db($database) or die( "Unable to select database");
  54. $query="UPDATE inprogress SET Address='$ud_Address', Number='$ud_Number', Issue='$ud_Issue', Notes='$ud_Notes2', Status='$ud_Status' WHERE ID='ud_ID' ";
  55. mysql_query($query);
  56. mysql_close();
  58. ?>
  61. </html>
Any help would be GREATLY appreciated.
Mar 12 '10 #1
35 9748
276 Contributor
Anyone? Any ideas? ..............
Mar 12 '10 #2
276 Contributor
Thank you for replacing my actual information. LOL I was quite worried about everyone seeing it.
Mar 12 '10 #3
5,058 Recognized Expert Expert

What are you having problems with, exactly?
What are you expecting the code to do? What is it actually doing?
Are you getting any error messages? - We LOVE error messages :)
(Keep in mind that we can't actually run the code on our own test machines.)

A few things I notice, though, that may help.
  • In both of your code examples, you connect to MySQL twice. This is unnecessary, and a waste of resources. A single call to the mysql_connect function is enough, unless you have a specific reason for needing to call it more often.
  • On lines #31 and #32 you use the session_registe r function. This function is deprecated and should not be used anymore. - Instead, you should register session variables like so:
    Expand|Select|Wrap|Line Numbers
    1. $_SESSION['username'] = $username;
  • Indentation - You should always write your code as if the guy who will be maintaining it is a homicidal maniac that knows where you live. It will make your own work on the code easier, and it makes it easier for people like myself - who were not involved in writing it - to work on it.
Mar 12 '10 #4
276 Contributor
Thank you for the response and advise.

No error messages. It's just not transferring the information from one table to another.

When I go into the data page, I want to make sure that the data is in the right tables.
Mar 12 '10 #5
5,058 Recognized Expert Expert
Ok, so after going a bit more thoroughly over it, I think I've found what is causing your main problem.

In your second script, "update.php ", you have a SQL query at the very end of it, line #54. - The problem is the WHERE clause. Instead of using the "ud_ID" from the form (the $_POST array), you are using the name as a static string. That will cause MySQL to either fail with an error (which you don't seem to even check for), or always update the first row. - Either way, you need to replace that with the value passed from the form. (Like you do with the other values in that query.)

Earlier in that script, you do this:
Expand|Select|Wrap|Line Numbers
  1. $Client=mysql_result($result,"Client");
  2. $Number=mysql_result($result,"Number");
  3. $Address=mysql_result($result,"Address");
  4. // etc...
This is incorrect usage of the mysql_result function. Instead, you should be fetching the entire row using the mysql_fetch_ass oc function and using the return array you get from that.
Expand|Select|Wrap|Line Numbers
  1. $row = mysql_fetch_assoc($result);
  2. $Client=$row['Client'];
  3. $Number=$row['Number'];
  4. $Address=$row['Address'];
  5. // etc...
On line #13 of the second example, you have a SQL query. It is missing a quotation mark at the end. The single-quote after the $ID is missing. It needs to be added. - Also, there is an extra space in front of the SELECT that should be removed.

I don't see anything in the first code that would "break" it. It should work, even though there are a few things that could use some "tuning". - However, there is one thing that should be removed or fixed. On line #56 you have a SQL query that is just... wrong. - There is no such thing as a UPDATE INTO query. -Not sure exactly what you were trying to do there, but I would simply remove that line.

Hope that helps any.
Mar 12 '10 #6
276 Contributor
LOL!!!! Yeah, I had INSERT INTO and it wouldn't transfer the data so I tried out the UPDATE. LOL!!!! I'm not THAT much of a PHP noob. Am I?
Mar 12 '10 #7
276 Contributor
I did what you told me to, but unfortunately it still doesn't update the data. :(
Mar 12 '10 #8
276 Contributor
I got it to transfer from table to table, but it still doesn't update for some REALLY annoying reason. I'm either being really stupid or something's dumb with the code....
Mar 12 '10 #9
5,058 Recognized Expert Expert
How does your update script look now?
Mar 12 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

by: jimb | last post by:
I need some advice on how to securely transfer data between two servers. Here is the situation. We have two sql servers that hold student data. I have full access to my sql server, but only write access to the main sql server on campus. I hope to use XML and SSL to transfer student data to the main server. As for generating the XML, I'll have an asp.net page set up in a secure directory that will generate the data in xml format. The...
by: phong.lee | last post by:
Hello all, i'm new at this. I need some assistant in transferring data from excel to access. I created a macro that basically gather all the necessary data that i need to bring into access. I also created a table in access with the correct columns to store the data from excel. Is there a way in VBA code that i can write so that when the data that i need can be automatically transfer into my access table? Thank you
by: Rani | last post by:
hi guys I don't know if this is the right place for it but I created 2 pages in page one there is a text box in which the user enters his name, in page 2 there is a the same text box. I would like the data to be transferred automatically to the second page how do I do that ? thanks
by: http://www.visual-basic-data-mining.net/forum | last post by:
Does anyone have any idea how to transferring data from TextBox1 in form1 to textBox2 in form2..... That means after i fill in any data in textBox1 and click Next button... It will bring me to form2....and there the data that i key in form1 will appear to form2 in textbox2 Thanks
by: neilr | last post by:
Can anyone help with some problkems that have wasted 2 days of my (inexperienced) time already? We have a website which allows people to register for events like conferences We are importing a table of fees for the apporpriate event using an Sp: FeesDataSet = New System.Data.DataSet Dim MySPcommand As New System.Data.SqlClient.SqlCommand MySPcommand.CommandText = "SP4105201getWebFeeTable"
by: meetalps | last post by:
Hi All, Can you please help me with a step by step procedure to transfer files from my PC to DB2-AIX and vice versa. I am new to both. Example transferring a sql file to run from PC to DB2 on AIX. PC-OS windows DB2 on AIX platform. Thanks.
by: ControlHead | last post by:
Hello All, I have a tricky problem. I have two forms in MS Access where the user enters information. The first form links to a table with only one record where data is entered via text boxes. Lets say the user enters "Red", "Blue", "Green" and "Yellow". No problem here. Now on the second form, the user needs to select some of the information previously entered on form 1 by means of drop-down combo boxes, where these selections from...
by: cbs81 | last post by:
hi all, problem: transferring data from workbooks that are stored in a particular directory from excel to a table in access. when done, the workbooks that have been processed are automatically moved into a directory named “processed” . all using vba. this is the pretty complex vb problem that i need some expert solution to. overview. i have created a cash reconciliation application in excel saved by month for each of my bus...
by: OuTCasT | last post by:
I have a table on one server and another on another server. I transfferred that data from the old table to the new table but some of the data didnt pull through. there is an email column in both tables. So i want to compare the 2 tables to see what emails are in the old table that have not been pulled into the new table.
by: angusfreefa | last post by:
Dear All, I am facing a problem of transferring data between 2 tables within the same database. I set up 2 tables. The first table is the permanent table (oos_table) for saving records. the other table is a temp table (oos_table_temp) for storing records which all data would be deleted after the data transferred to the permanent table. below is the code I am currently using. Dim strNewTable As String Dim strOldTable As String
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.