473,379 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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

computerfox
276 100+
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 2267
Markus
6,050 Expert 4TB
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 100+
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 Expert 4TB
What database are you using?
Oct 30 '10 #4
computerfox
276 100+
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 Expert 4TB
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 100+
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 Expert 4TB
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($sql) or die(mysql_error());, for example.
  4. Your INSERT query is wide open to SQL Injection. Always run data through the mysql_real_escape_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 100+
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
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)...
2
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...
3
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...
0
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. ...
1
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...
4
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...
1
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 ...
2
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...
3
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.