473,708 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Data not showing up in database but can be extracted as usual

computerfox
276 Contributor
hey guys,

I have a little problem that been haunting me for the past two days.

Expand|Select|Wrap|Line Numbers
  1. //Get data from form
  2. $Client1=$_POST['Client'];
  3. $Number1=$_POST['Number'];
  4. $Issue1=$_POST['Issue'];
  5. $Status1=$_POST['Status'];
  6. $Charge1=$_POST['Charge'];
  7. $Parts1=$_POST['Parts'];
  8.  
  9. //Insert new data into inprogress
  10.  
  11. mysql_query("INSERT INTO new (Client,Number,Job,Status,Charge,Expense)VALUES('$Client1','$Number1','$Issue1','$Status1','$Charge1','$Parts1')");
  12.  
  13. mysql_close();
  14.  
  15.  
When I print out the data in the form it prints out the correct data, but when I check the database, there's no information, but it does insert a new entry. What gives? Any help would be greatly appreciated.

-FOX
Oct 30 '10 #1
8 2279
Markus
6,050 Recognized Expert Expert
That is strange and we can't really help (this isn't a PHP issue, either). Are you sure you're looking at the right database? ;)
Oct 30 '10 #2
computerfox
276 Contributor
Yes, of course. I've did this multiple times so I'm not new to it so that's why it's surprising me. It goes in, but no data. I print it out on the page and the data is there. I don't get it.

PS Thank you for changing the name of the thread.
Oct 30 '10 #3
Markus
6,050 Recognized Expert Expert
What database are you using?
Oct 30 '10 #4
computerfox
276 Contributor
Here's everything for the insert:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <title>CrystalWorks</title>
  3.  
  4. <body background="http://www.computerfoxdesign.com/gothbackground2.jpg">
  5. <?
  6. $username="*********";
  7. $password="*********";
  8. $database="admina_crystalworks";
  9. mysql_connect("***********.fatcowmysql.com",$username,$password);
  10. mysql_select_db($database);
  11.  
  12. $result=mysql_query("SELECT* new");
  13. ?>
  14.  
  15. <form method="POST">
  16. <table>
  17.  
  18. <tr><th align="left">Client:</th><th><input type="text" name="Client"></th></tr><br>
  19.  
  20. <tr><th align="left">Number:</th><th><input type="text" name="Number"></th></tr><br>
  21.  
  22. <tr><th align="left">Issue: </th><th><input type="longtext" name="Issue"></th></tr><br>
  23.  
  24. <tr><th align="left">Status:</th> <th><input type="char(1)" name="Status"></th></tr><br>
  25.  
  26. <tr><th align="left">Charge:</th><th> <input type="double(10,2)" name="Charge"></th></tr><br>
  27.  
  28. <tr><th align="left">Parts:</th><th> <input type="double(10,2)" name="Parts"></th></tr><br>
  29.  
  30. <tr><th align="left">Paid:</th><th> <input type="char(1)" name="Paid"></th></tr><br>
  31.  
  32. <tr><th><input type="Submit" value="Submit"></tr></th>
  33. </table>
  34. </form>
  35.  
  36. <?
  37. //Get data from form
  38. $Client1=$_POST['Client'];
  39. $Number1=$_POST['Number'];
  40. $Issue1=$_POST['Issue'];
  41. $Status1=$_POST['Status'];
  42. $Charge1=$_POST['Charge'];
  43. $Parts1=$_POST['Parts'];
  44.  
  45. //Insert new data into inprogress
  46.  
  47. mysql_connect("computerfoxdesigncom.fatcowmysql.com",$username,$password);
  48. mysql_select_db($database);
  49.  
  50. mysql_query("INSERT INTO new (Client,Number,Job,Status,Charge,Expense)VALUES('$Client1','$Number1','$Issue1','$Status1','$Charge1','$Parts1')");
  51.  
  52. mysql_close();
  53.  
  54. echo $Client;
  55. echo "<br>$Number<br>";
  56. ?>
  57.  
  58. </body>
  59. </html>
  60.  
Seriesly, am I missing something?
Oct 30 '10 #5
Markus
6,050 Recognized Expert Expert
Well if you can retrieve the data from the database correctly, then it is being inserted and there is nothing wrong with your code. Again, what database are you using?
Oct 30 '10 #6
computerfox
276 Contributor
Here's where I'm printing it all out:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <title>CrystalWorks</title>
  3.  
  4. <html> 
  5.  
  6. <?php
  7. $host="**********.fatcowmysql.com"; // Host name 
  8. $username="********"; // Mysql username 
  9. $password="********"; // Mysql password 
  10. $db_name="admina_crystalworks"; // Database name 
  11.  
  12.  
  13. // Connect to server and select databse.
  14. mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
  15. mysql_select_db($db_name);
  16.  
  17. $Username=$_GET['Username'];
  18. $Password=$_GET['Password'];
  19.  
  20.  
  21.  
  22. if($Username="****"){{
  23. // Register $myusername, $mypassword
  24.  
  25.  
  26. echo "You are logged in as ";
  27. echo $Username;
  28. print "<br>";
  29.  
  30. mysql_select_db(admina_crystalworks);
  31.  
  32. echo "\n\n";
  33.  
  34. mysql_select_db("admina_crystalworks") or die(mysql_error()); 
  35. $data = mysql_query("SELECT* FROM new")
  36. or die(mysql_error()); 
  37.  
  38. /*----------------------------------------Put data into right tables--------------------------------------------------------------*/
  39.  
  40. mysql_query("INSERT INTO complete SELECT* FROM new WHERE Status='Y' ");
  41. mysql_query("DELETE FROM new WHERE Status='Y'");
  42.  
  43. mysql_query("INSERT INTO new SELECT* FROM complete WHERE Status='N' ");
  44. mysql_query("DELETE FROM complete WHERE Status='N'");
  45.  
  46. mysql_query("INSERT INTO admina_archive.October2010 SELECT* FROM admina_crystalworks.complete WHERE Paid='Y' && Status='Y' ");
  47. mysql_query("DELETE FROM complete WHERE Paid='Y' && Status='Y'");
  48.  
  49.  
  50.  
  51.  
  52. /*------------------------------------------Take out duplicates--------------------------------------------------------------------------*/
  53. mysql_query("DELETE FROM new WHERE Number=' ' ");
  54.  
  55. /*-------------------------------------------------Inprogress-------------------------------------------------------------------------------*/
  56. Print "<br><br>";
  57.  
  58. Print "<br><br>New<br><br>";
  59.  
  60. $data = mysql_query("SELECT* FROM new") 
  61. or die(mysql_error());
  62.  
  63. Print "<table border cellpadding=7>"; 
  64.  
  65. $flag=1;
  66. while($info = mysql_fetch_assoc( $data )) 
  67. $id=$info['ID'];
  68.  
  69. if($flag==1){
  70. Print "<tr>";
  71. Print "<th>Time Entered</th>";
  72. Print "<th>Client</th>";
  73. Print "<th>Number</th>";
  74. Print "<th>Job</th>";
  75. Print "<th>Status</th>";
  76. Print "<th>Charge</th>";
  77. Print "<th>Edit</th>";
  78. Print "<th>Print</th>";
  79. Print "</tr><tr>";
  80. Print "<th> " .$info['TEntered'] . "</th>";
  81. Print "<th> ".$info['Client']. " </th>"; 
  82. Print "<th> " .$info['Number']. "</th>";
  83. Print "<th>" .$info['Job']. "</th>";
  84. Print "<th>" .$info['Status']. "</th>";
  85. Print "<th>$" .$info['Charge']. "</th>";
  86. Print '<th><a href="https://www.computerfoxdesign.com/CrystalWorks/nupdate.php?id='.$id.' " target="_blank">Edit</a></th>';
  87. Print '<th><a href ="https://www.computerfoxdesign.com/CrystalWorks/receipt.php?id='.$id.' " target="_blank">Print</a></th>';
  88. Print "</tr>";
  89. $flag=0;
  90. }
  91.  
  92. else{
  93. Print "<tr>";
  94. Print "<th> " .$info['TEntered']. "</th>";
  95. Print "<th> ".$info['Client']. " </th>"; 
  96. Print "<th> " .$info['Number']. "</th>";
  97. Print "<th>" .$info['Job']. "</th>";
  98. Print "<th>" .$info['Status']. "</th>";
  99. Print "<th>$" .$info['Charge']. "</th>";
  100. Print '<th><a href="https://www.computerfoxdesign.com/CrystalWorks/nupdate.php?id=' .$id. ' " target="_blank">Edit</a></th>';
  101. Print '<th><a href ="https://www.computerfoxdesign.com/CrystalWorks/receipt.php?id=' .$id. ' " target="_blank">Print</a></th>';
  102. Print "</tr>";
  103. $flag=0;
  104. //$id++;
  105. }
  106. Print "</table>"; 
  107.  
  108. Print "<br>";
  109. Print "<br>";
  110.  
  111. /*--------------------------------------------------------Complete-----------------------------------------------------------------------*/
  112. Print "<br><br><br>Complete<br><br>";
  113.  
  114. $data = mysql_query("SELECT* FROM complete") 
  115. or die(mysql_error()); 
  116. Print "<table border cellpadding=7>"; 
  117. $flag=1;
  118. while($info = mysql_fetch_assoc( $data )) 
  119. $id=$info['ID'];
  120.  
  121. if($flag==1){
  122. Print "<tr>";
  123. Print "<th>Time Entered</th>";
  124. Print "<th>Client</th>";
  125. Print "<th>Number</th>";
  126. Print "<th>Job</th>";
  127. Print "<th>Status</th>";
  128. Print "<th>Charge</th>";
  129. Print "<th>Paid</th>";
  130. Print "<th>Time Completed</th>";
  131. Print "<th>Edit</th>";
  132. Print "</tr><tr>";
  133. Print "<th> " .$info['TEntered']. "</th>";
  134. Print "<th> ".$info['Client']. " </th>"; 
  135. Print "<th> " .$info['Number']. "</th>";
  136. Print "<th>" .$info['Job']. "</th>";
  137. Print "<th>" .$info['Status']. "</th>";
  138. Print "<th>$" .$info['Charge']. "</th>";
  139. Print "<th>" .$info['Paid']. "</th>";
  140. Print "<th>" .$info['TComplete'];
  141. Print '<th><a href="https://www.computerfoxdesign.com/CrystalWorks/cupdate.php?id=' .$id. ' " target="_blank">Edit</a></th>';
  142. Print "</tr>";
  143. $flag=0;
  144. }
  145.  
  146. else{
  147. Print "<tr>";
  148. Print "<th> " .$info['TEntered']. "</th>";
  149. Print "<th> ".$info['Client']. " </th>"; 
  150. Print "<th> " .$info['Number']. "</th>";
  151. Print "<th>" .$info['Job']. "</th>";
  152. Print "<th>" .$info['Status']. "</th>";
  153. Print "<th>$" .$info['Charge']. "</th>";
  154. Print "<th>" .$info['Paid']. "</th>";
  155. Print "<th>" .$info['TComplete'];
  156. Print '<th><a href="https://www.computerfoxdesign.com/CrystalWorks/cupdate.php?id=' .$id. ' " target="_blank">Edit</a></th>';
  157. Print "</tr>";
  158. $flag=0;
  159. //$id++;
  160. }
  161. Print "</table>"; 
  162.  
  163. }
  164.  
  165. }
  166.  
  167. else{
  168.  
  169. echo "You do NOT have access to this section<br>";
  170. }
  171.  
  172. ?>
  173. </html>
  174.  
Also, if I insert through mySQLAdmin everything gets printed out correctly, so it can't be that I'm using the wrong database.
Oct 30 '10 #7
Atli
5,058 Recognized Expert Expert
Hey.

A few comments on your insert code.
  1. The type attribute of a input element can only be one of: text, password, checkbox, radio, submit, reset, file, hidden, image or button. (This is not the MySQL data type.) - Not sure how the browsers handle this -- they may default to text for invalid values -- but you should not depend on that. They may just as well ignore the field altogether.
  2. The part of the code that inserts the new data into the database is executed regardless of whether or not there is actually any data. As such, it will ALWAYS be executed, even the first time the form is shown, where it will just insert an empty row. - You need to check to see if there is actually any data to insert before you try to insert it.
  3. You are ignoring the return value of the mysql_query() calls, so even if the query fails, you wouldn't know about it. - You should always capture the return value and dump or log the error. mysql_query($sq l) or die(mysql_error ());, for example.
  4. Your INSERT query is wide open to SQL Injection. Always run data through the mysql_real_esca pe_string function before putting it into a MySQL query.
  5. The SELECT query on line #12 has an error. You are missing the FROM clause.
  6. You connect to the same database twice, once for the select and once for the INSERT. (Once is enough.)
  7. Avoid using <? ... ?> style code blocks. They are disabled by default. The <?php ... ?> style blocks always work.
Oct 31 '10 #8
computerfox
276 Contributor
Thank you all for the responses. I figured out what it was. Turns out that php doesn't like " ' ". That's weird, I never had that.
Oct 31 '10 #9

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

Similar topics

3
11227
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL) on the server because of that. Our site will have an SSL certificate next week, so I would like to use AIM instead of SIM, however, I don't know how to send data via POST over https and recieve data from the Authorize.net server over an https...
2
5822
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues to execute the code until the browser send his reply to the header instruction. So an exit(); after each redirection won't hurt at all
3
23016
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which field is completed.
0
8478
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. 354 roberto@ausone:Build/php-4.3.2> ldd /opt/php4/bin/php libsablot.so.0 => /usr/local/lib/libsablot.so.0 libstdc++.so.5 => /usr/local/lib/libstdc++.so.5 libm.so.1 => /usr/lib/libm.so.1
1
8590
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the column below. The viewer can select states from the drop down lists above the other two columns as well. If the viewer selects only one, only one column fills. If the viewer selects two states, two columns fill. Etc. I could, if appropriate, have...
4
18282
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the user comes back to a page where he had a submitted POST data the browser keeps telling that the data has expired and asks if repost. How to avoid that? I tried registering all POST and GET vars as SESSION vars but
1
6838
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url http://www.mis.gla.ac.uk/biquery/training/ but each of the courses held have maximum of 8 people that could be
2
31425
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value to :parameter I dont like the idea of making the SQL statement on the fly without binding parameters as I dont want a highly polluted SQL cache.
3
23582
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the results of the picture half the size. The PHP I have installed support 1.62 or higher. And all I would like to do is take and image and make it fit a 3x3. Any suggestions to where I should read or look would be appreciated.
0
8792
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9293
Oralloy
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...
1
9064
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9003
tracyyun
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...
1
6617
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4456
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4713
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3151
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2508
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.