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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • computerfox
    Contributor
    • Mar 2010
    • 276

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

    hey guys,

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

    Code:
    //Get data from form
    $Client1=$_POST['Client'];
    $Number1=$_POST['Number'];
    $Issue1=$_POST['Issue'];
    $Status1=$_POST['Status'];
    $Charge1=$_POST['Charge'];
    $Parts1=$_POST['Parts'];
    
    //Insert new data into inprogress
    
    mysql_query("INSERT INTO new (Client,Number,Job,Status,Charge,Expense)VALUES('$Client1','$Number1','$Issue1','$Status1','$Charge1','$Parts1')");
    
    mysql_close();
    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
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    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? ;)

    Comment

    • computerfox
      Contributor
      • Mar 2010
      • 276

      #3
      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.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        What database are you using?

        Comment

        • computerfox
          Contributor
          • Mar 2010
          • 276

          #5
          Here's everything for the insert:

          Code:
          <html>
          <title>CrystalWorks</title>
          
          <body background="http://www.computerfoxdesign.com/gothbackground2.jpg">
          <?
          $username="*********";
          $password="*********";
          $database="admina_crystalworks";
          mysql_connect("***********.fatcowmysql.com",$username,$password);
          mysql_select_db($database);
          
          $result=mysql_query("SELECT* new");
          ?>
          
          <form method="POST">
          <table>
          
          <tr><th align="left">Client:</th><th><input type="text" name="Client"></th></tr><br>
          
          <tr><th align="left">Number:</th><th><input type="text" name="Number"></th></tr><br>
          
          <tr><th align="left">Issue: </th><th><input type="longtext" name="Issue"></th></tr><br>
          
          <tr><th align="left">Status:</th> <th><input type="char(1)" name="Status"></th></tr><br>
          
          <tr><th align="left">Charge:</th><th> <input type="double(10,2)" name="Charge"></th></tr><br>
          
          <tr><th align="left">Parts:</th><th> <input type="double(10,2)" name="Parts"></th></tr><br>
          
          <tr><th align="left">Paid:</th><th> <input type="char(1)" name="Paid"></th></tr><br>
          
          <tr><th><input type="Submit" value="Submit"></tr></th>
          </table>
          </form>
          
          <?
          //Get data from form
          $Client1=$_POST['Client'];
          $Number1=$_POST['Number'];
          $Issue1=$_POST['Issue'];
          $Status1=$_POST['Status'];
          $Charge1=$_POST['Charge'];
          $Parts1=$_POST['Parts'];
          
          //Insert new data into inprogress
          
          mysql_connect("computerfoxdesigncom.fatcowmysql.com",$username,$password);
          mysql_select_db($database);
          
          mysql_query("INSERT INTO new (Client,Number,Job,Status,Charge,Expense)VALUES('$Client1','$Number1','$Issue1','$Status1','$Charge1','$Parts1')");
          
          mysql_close();
          
          echo $Client;
          echo "<br>$Number<br>";
          ?>
          
          </body>
          </html>
          Seriesly, am I missing something?

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            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?

            Comment

            • computerfox
              Contributor
              • Mar 2010
              • 276

              #7
              Here's where I'm printing it all out:

              Code:
              <title>CrystalWorks</title>
              
              <html> 
              
              <?php
              $host="**********.fatcowmysql.com"; // Host name 
              $username="********"; // Mysql username 
              $password="********"; // Mysql password 
              $db_name="admina_crystalworks"; // Database name 
              
              
              // Connect to server and select databse.
              mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
              mysql_select_db($db_name);
              
              $Username=$_GET['Username'];
              $Password=$_GET['Password'];
              
              
              
              if($Username="****"){{
              // Register $myusername, $mypassword
              
              
              echo "You are logged in as ";
              echo $Username;
              print "<br>";
              
              mysql_select_db(admina_crystalworks);
              
              echo "\n\n";
              
              mysql_select_db("admina_crystalworks") or die(mysql_error()); 
              $data = mysql_query("SELECT* FROM new")
              or die(mysql_error()); 
              
              /*----------------------------------------Put data into right tables--------------------------------------------------------------*/
               
              mysql_query("INSERT INTO complete SELECT* FROM new WHERE Status='Y' ");
              mysql_query("DELETE FROM new WHERE Status='Y'");
              
              mysql_query("INSERT INTO new SELECT* FROM complete WHERE Status='N' ");
              mysql_query("DELETE FROM complete WHERE Status='N'");
               
              mysql_query("INSERT INTO admina_archive.October2010 SELECT* FROM admina_crystalworks.complete WHERE Paid='Y' && Status='Y' ");
              mysql_query("DELETE FROM complete WHERE Paid='Y' && Status='Y'");
              
              
              
              
              /*------------------------------------------Take out duplicates--------------------------------------------------------------------------*/
              mysql_query("DELETE FROM new WHERE Number=' ' ");
              
              /*-------------------------------------------------Inprogress-------------------------------------------------------------------------------*/
              Print "<br><br>";
              
              Print "<br><br>New<br><br>";
              
              $data = mysql_query("SELECT* FROM new") 
              or die(mysql_error());
              
              Print "<table border cellpadding=7>"; 
              
              $flag=1;
              while($info = mysql_fetch_assoc( $data )) 
              { 
              $id=$info['ID'];
              
              if($flag==1){
              Print "<tr>";
              Print "<th>Time Entered</th>";
              Print "<th>Client</th>";
              Print "<th>Number</th>";
              Print "<th>Job</th>";
              Print "<th>Status</th>";
              Print "<th>Charge</th>";
              Print "<th>Edit</th>";
              Print "<th>Print</th>";
              Print "</tr><tr>";
              Print "<th> " .$info['TEntered'] . "</th>";
              Print "<th> ".$info['Client']. " </th>"; 
              Print "<th> " .$info['Number']. "</th>";
              Print "<th>" .$info['Job']. "</th>";
              Print "<th>" .$info['Status']. "</th>";
              Print "<th>$" .$info['Charge']. "</th>";
              Print '<th><a href="https://www.computerfoxdesign.com/CrystalWorks/nupdate.php?id='.$id.' " target="_blank">Edit</a></th>';
              Print '<th><a href ="https://www.computerfoxdesign.com/CrystalWorks/receipt.php?id='.$id.' " target="_blank">Print</a></th>';
              Print "</tr>";
              $flag=0;
              }
              
              else{
              Print "<tr>";
              Print "<th> " .$info['TEntered']. "</th>";
              Print "<th> ".$info['Client']. " </th>"; 
              Print "<th> " .$info['Number']. "</th>";
              Print "<th>" .$info['Job']. "</th>";
              Print "<th>" .$info['Status']. "</th>";
              Print "<th>$" .$info['Charge']. "</th>";
              Print '<th><a href="https://www.computerfoxdesign.com/CrystalWorks/nupdate.php?id=' .$id. ' " target="_blank">Edit</a></th>';
              Print '<th><a href ="https://www.computerfoxdesign.com/CrystalWorks/receipt.php?id=' .$id. ' " target="_blank">Print</a></th>';
              Print "</tr>";
              $flag=0;
              //$id++;
              } 
              }
              Print "</table>"; 
              
              Print "<br>";
              Print "<br>";
              
              /*--------------------------------------------------------Complete-----------------------------------------------------------------------*/
              Print "<br><br><br>Complete<br><br>";
              
              $data = mysql_query("SELECT* FROM complete") 
              or die(mysql_error()); 
              Print "<table border cellpadding=7>"; 
              $flag=1;
              while($info = mysql_fetch_assoc( $data )) 
              { 
              $id=$info['ID'];
              
              if($flag==1){
              Print "<tr>";
              Print "<th>Time Entered</th>";
              Print "<th>Client</th>";
              Print "<th>Number</th>";
              Print "<th>Job</th>";
              Print "<th>Status</th>";
              Print "<th>Charge</th>";
              Print "<th>Paid</th>";
              Print "<th>Time Completed</th>";
              Print "<th>Edit</th>";
              Print "</tr><tr>";
              Print "<th> " .$info['TEntered']. "</th>";
              Print "<th> ".$info['Client']. " </th>"; 
              Print "<th> " .$info['Number']. "</th>";
              Print "<th>" .$info['Job']. "</th>";
              Print "<th>" .$info['Status']. "</th>";
              Print "<th>$" .$info['Charge']. "</th>";
              Print "<th>" .$info['Paid']. "</th>";
              Print "<th>" .$info['TComplete'];
              Print '<th><a href="https://www.computerfoxdesign.com/CrystalWorks/cupdate.php?id=' .$id. ' " target="_blank">Edit</a></th>';
              Print "</tr>";
              $flag=0;
              }
              
              else{
              Print "<tr>";
              Print "<th> " .$info['TEntered']. "</th>";
              Print "<th> ".$info['Client']. " </th>"; 
              Print "<th> " .$info['Number']. "</th>";
              Print "<th>" .$info['Job']. "</th>";
              Print "<th>" .$info['Status']. "</th>";
              Print "<th>$" .$info['Charge']. "</th>";
              Print "<th>" .$info['Paid']. "</th>";
              Print "<th>" .$info['TComplete'];
              Print '<th><a href="https://www.computerfoxdesign.com/CrystalWorks/cupdate.php?id=' .$id. ' " target="_blank">Edit</a></th>';
              Print "</tr>";
              $flag=0;
              //$id++;
              } 
              }
              Print "</table>"; 
              
              }
              
              }
              
              else{
              
              echo "You do NOT have access to this section<br>";
              }
              
              ?>
              </html>
              Also, if I insert through mySQLAdmin everything gets printed out correctly, so it can't be that I'm using the wrong database.

              Comment

              • Atli
                Recognized Expert Expert
                • Nov 2006
                • 5062

                #8
                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.

                Comment

                • computerfox
                  Contributor
                  • Mar 2010
                  • 276

                  #9
                  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.

                  Comment

                  Working...