473,406 Members | 2,371 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,406 software developers and data experts.

Row Added But No Data Inserted?

Hi. Please excuse my noobiness, but I'm new to PHP. My problem is data was not inserted into the database but PHP didn't return any error. Row was added since there was a new ID number, but then the rest of the columns are blanks and Sequence No and Date inserted 0's(zeros) instead of the real data. Could you kindly please check my code for any discrepancies? Please also check the images attached. Thanks.

***PROCESS PAGE***

Expand|Select|Wrap|Line Numbers
  1. <?php include("includes/db_connect.php"); ?>
  2. <?php require_once("includes/functions.php"); ?>
  3.  
  4. <html>
  5. <head><title>Add Equipment</title></head>
  6.  
  7. <body>
  8. <h3>Please review the data before finally submitting to the database.</h3>
  9. <h3>Press the back button of your browser if you want to edit the data.</h3>
  10. <h3>Press the submit button to submit it to the database.</h3><hr>
  11. <br />
  12. <?php
  13.  
  14.     $equipname = $_POST['equipname'];
  15.     $manufacturer = $_POST['manufacturer'];
  16.     $serno = $_POST['serno'];
  17.     $modelno = $_POST['modelno'];
  18.     $capacity = $_POST['capacity'];
  19.     $curloc = $_POST['curlocation'];
  20.     $equipcode = $_POST['equipcode'];
  21.     $seqno = $_POST['seqno'];    
  22.     $addDate = $_POST['dateYr']. "-";
  23.     $addDate .= $_POST['dateMO']. "-";
  24.     $addDate .= $_POST['dateDay'];
  25.  
  26.     echo "Equipment Name : <b>{$equipname}</b><br />";
  27.     echo "Manufacturer : <b>{$manufacturer}</b><br />";
  28.     echo "Serial No. : <b>{$serno}</b><br />";
  29.     echo "Model No. : <b>{$modelno}</b><br />";
  30.     echo "Capacity/Range : <b>{$capacity}</b><br />";
  31.     echo "Current Location : <b>{$curloc}</b><br />";
  32.     echo "Equipment Code : <b>{$equipcode}</b><br />";
  33.     echo "Sequence No. : <b>{$seqno}</b><br />";
  34.     echo "Date Added : <b>{$addDate}</b>";
  35. ?>
  36. <hr>
  37. <form action="adddata.php" method="POST">
  38. <input type="submit" name="submit" id="submit" value="Submit"></form>
  39.  
  40. </body></html>
  41. <?php 
  42.     if (isset($equip_db)) {
  43.         mysqli_close($equip_db); 
  44.     }
  45. ?>
-------------

***ADDDATA***

Expand|Select|Wrap|Line Numbers
  1. <?php include("includes/db_connect.php"); ?>
  2. <?php require_once("includes/functions.php"); ?>
  3. <?php
  4.  
  5.     $equipname = $_POST['$equipname'];
  6.     $manufacturer = $_POST['$manufacturer'];
  7.     $serno = $_POST['$serno'];
  8.     $modelno = $_POST['$modelno'];
  9.     $capacity = $_POST['$capacity'];
  10.     $curloc = $_POST['$curlocation'];
  11.     $equipcode = $_POST['$equipcode'];
  12.     $seqno = $_POST['$seqno'];    
  13.     $addDate = $_POST['$dateYr'] ."-". $_POST['$dateMO'] ."-". $_POST['$dateDay'];
  14.  
  15.     $query_add = "INSERT INTO tblequipmentmasterlist (equipname, manufacturer, serno,
  16.                     modelno, capacity, curlocation, equipcode, seqno, adddate) 
  17.                     VALUES ('{$equipname}','{$manufacturer}','{$serno}','{$modelno}',
  18.                     '{$capacity}','{$curloc}','{$equipcode}','{$seqno}','{$addDate}')";
  19.  
  20.     if (mysqli_query($db_cxn, $query_add)) {
  21.         header ("Location: newequipment.php");
  22.         exit;
  23.         } else {
  24.             echo "<p>Data addition has failed. Please contact the site administrator.</p>";
  25.             echo "<p>" . mysqli_error($db_cxn) . "</p>";
  26.         }                
  27. ?>
  28. <?php 
  29.     if (isset($db_cxn)) {
  30.         mysqli_close($db_cxn); 
  31.     }
  32. ?>
Attached Images
File Type: jpg MainPage.jpg (63.9 KB, 148 views)
File Type: jpg MissingData.jpg (73.7 KB, 130 views)
File Type: jpg DataCheckBeforeDatabaseInsertion.jpg (66.9 KB, 134 views)
Sep 25 '11 #1

✓ answered by Dormilich

actually, I can’t see anything odd in the material given. you may try var_dump($_POST) to check that all data are correctly passed.

additionally, the redirect may fail in adddata.php.

I may also note that there are no precautions against SQL Injection attacks.

4 1643
Dormilich
8,658 Expert Mod 8TB
actually, I can’t see anything odd in the material given. you may try var_dump($_POST) to check that all data are correctly passed.

additionally, the redirect may fail in adddata.php.

I may also note that there are no precautions against SQL Injection attacks.
Sep 25 '11 #2
Thanks for the quick reply. I inserted a var_dump and a print_r to my ADDDATA script and they came up empty actually. It returned an error but when I checked my database, it added another row. I really don't understand it. And what do you mean by "no precautions against SQL injection attacks?" I've revised both my PROCESS and ADDDATA scripts. Also, I've attached some new images showing the results. Thanks.

PROCESS_STRING_ESCAPED
Expand|Select|Wrap|Line Numbers
  1. <?php include("includes/db_connect.php"); ?>
  2. <?php require_once("includes/functions.php"); ?>
  3.  
  4. <html>
  5. <head><title>Add Equipment</title></head>
  6.  
  7. <body>
  8. <h4>Please review the data before finally submitting to the database.</h4>
  9. <h4>Press the back button of your browser if you want to edit the data.</h4>
  10. <h4>Press the submit button to submit it to the database.</h4><hr>
  11. <br />
  12. <?php
  13.  
  14.     $equipname = mysqli_real_escape_string($db_cxn, $_POST['equipname']);
  15.     $manufacturer = mysqli_real_escape_string($db_cxn, $_POST['manufacturer']);
  16.     $serno = mysqli_real_escape_string($db_cxn, $_POST['serno']);
  17.     $modelno = mysqli_real_escape_string($db_cxn, $_POST['modelno']);
  18.     $capacity = mysqli_real_escape_string($db_cxn, $_POST['capacity']);
  19.     $curloc = mysqli_real_escape_string($db_cxn, $_POST['curlocation']);
  20.     $equipcode = mysqli_real_escape_string($db_cxn, $_POST['equipcode']);
  21.     $seqno = mysqli_real_escape_string($db_cxn, $_POST['seqno']);    
  22.     $addDate = mysqli_real_escape_string($db_cxn, $_POST['dateYr']). "-";
  23.     $addDate .= mysqli_real_escape_string($db_cxn, $_POST['dateMO']). "-";
  24.     $addDate .= mysqli_real_escape_string($db_cxn, $_POST['dateDay']);
  25.  
  26.     echo "Equipment Name : <b>{$equipname}</b><br />";
  27.     echo "Manufacturer : <b>{$manufacturer}</b><br />";
  28.     echo "Serial No. : <b>{$serno}</b><br />";
  29.     echo "Model No. : <b>{$modelno}</b><br />";
  30.     echo "Capacity/Range : <b>{$capacity}</b><br />";
  31.     echo "Current Location : <b>{$curloc}</b><br />";
  32.     echo "Equipment Code : <b>{$equipcode}</b><br />";
  33.     echo "Sequence No. : <b>{$seqno}</b><br />";
  34.     echo "Date Added : <b>{$addDate}</b>";
  35. ?>
  36. <hr>
  37. <form action="adddata.php" method="POST">
  38. <input type="submit" name="submit" id="submit" value="Submit"></form>
  39.  
  40. </body></html>
  41. <?php 
  42.     if (isset($db_cxn)) {
  43.         mysqli_close($db_cxn); 
  44.     }
  45. ?>
----------------

ADDDATA with VAR_DUMP and PRINT_R

Expand|Select|Wrap|Line Numbers
  1. <?php include("includes/db_connect.php"); ?>
  2. <?php require_once("includes/functions.php"); ?>
  3. <?php
  4.  
  5.     $equipname = $_POST['$equipname'];
  6.     $manufacturer = $_POST['$manufacturer'];
  7.     $serno = $_POST['$serno'];
  8.     $modelno = $_POST['$modelno'];
  9.     $capacity = $_POST['$capacity'];
  10.     $curloc = $_POST['$curlocation'];
  11.     $equipcode = $_POST['$equipcode'];
  12.     $seqno = $_POST['$seqno'];    
  13.     $addDate = $_POST['$dateYr'] ."-". $_POST['$dateMO'] ."-". $_POST['$dateDay'];
  14.  
  15.     $query_add = "INSERT INTO tblequipmentmasterlist (equipname, manufacturer, serno,
  16.                     modelno, capacity, curlocation, equipcode, seqno, adddate) 
  17.                     VALUES ('{$equipname}','{$manufacturer}','{$serno}','{$modelno}',
  18.                     '{$capacity}','{$curloc}','{$equipcode}','{$seqno}','{$addDate}')";
  19.  
  20.     if ($query_add != null) {
  21.         mysqli_query($db_cxn, $query_add);
  22.         echo "<pre>";
  23.         echo print_r($query_add);
  24.         echo var_dump($query_add);
  25.         echo "</pre>";
  26.         //header ("Location: newequipment.php");
  27.         exit;
  28.         } else {
  29.             echo "<p>Record was not added : ". $query_add.  " Please contact the site administrator.</p>";
  30.             echo "<p>" . mysqli_error($db_cxn) . "</p>";
  31.         }                
  32. ?>
  33. <?php 
  34.     if (isset($db_cxn)) {
  35.         mysqli_close($db_cxn); 
  36.     }
  37. ?>
Attached Images
File Type: jpg RowAddedNoData.jpg (39.0 KB, 128 views)
File Type: jpg VarDump.jpg (76.8 KB, 151 views)
Sep 25 '11 #3
Dormilich
8,658 Expert Mod 8TB
I inserted a var_dump and a print_r to my ADDDATA script and they came up empty actually.
that is indicating that there is something wrong with your HTML form.

when I checked my database, it added another row.
even if the values are empty, they will be inserted.

besides that, did you really name the form elements like $eqipname?
Sep 26 '11 #4
The problem is now resolved. What I did was do away with the ADDDATA page and just insert the record at the PROCESSFORM page, taking into account character escaping. It is now working as it should be. Here is my new code for the revised PROCESSFORM page. Thanks for the help.

NEW PROCESS FORM PAGE

Expand|Select|Wrap|Line Numbers
  1. <?php include("includes/db_connect.php"); ?>
  2. <?php require_once("includes/functions.php"); ?>
  3.  
  4. <?php
  5.  
  6.     $equipname = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['equipname'])));
  7.     $manufacturer = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['manufacturer'])));
  8.     $serno = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['serno'])));
  9.     $modelno = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['modelno'])));
  10.     $capacity = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['capacity'])));
  11.     $curloc = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['curlocation'])));
  12.     $equipcode = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['equipcode'])));
  13.     $seqno = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['seqno'])));    
  14.     $addDate = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['dateYr']))). "-";
  15.     $addDate .= mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['dateMO']))). "-";
  16.     $addDate .= mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['dateDay'])));
  17.  
  18.     $query_add = "INSERT INTO tblequipmentmasterlist (equipname, manufacturer, serno,
  19.                     modelno, capacity, curlocation, equipcode, seqno, adddate) 
  20.                     VALUES ('{$equipname}','{$manufacturer}','{$serno}','{$modelno}',
  21.                     '{$capacity}','{$curloc}','{$equipcode}','{$seqno}','{$addDate}')";
  22.  
  23.     if ($query_add != null) {
  24.         mysqli_query($db_cxn, $query_add);
  25.         echo "<pre>";
  26.         echo "<h4>You have successfully added the following records to the database : </h4>";
  27.         echo "<hr>";
  28.         echo "<br />";
  29.         echo "Equipment Name : <b>{$equipname}</b><br />";
  30.         echo "Manufacturer : <b>{$manufacturer}</b><br />";
  31.         echo "Serial No. : <b>{$serno}</b><br />";
  32.         echo "Model No. : <b>{$modelno}</b><br />";
  33.         echo "Capacity/Range : <b>{$capacity}</b><br />";
  34.         echo "Current Location : <b>{$curloc}</b><br />";
  35.         echo "Equipment Code : <b>{$equipcode}</b><br />";
  36.         echo "Sequence No. : <b>{$seqno}</b><br />";
  37.         echo "Date Added : <b>{$addDate}</b>";
  38.         //echo print_r($_POST);
  39.         //echo var_dump($_POST);
  40.         echo "</pre>";
  41.         echo "<hr>";
  42.         echo "<form action='newequipment.php' method='POST'>";
  43.         echo "<input type='submit' name='submit' id='submit' value='Continue' /></form>";
  44.         //header ("Location: processform_old.php");
  45.         //exit;
  46.         } else {
  47.             echo "<p>Record was not added : ". $query_add.  " Please contact the site administrator.</p>";
  48.             echo "<p>" . mysqli_error($db_cxn) . "</p>";
  49.         }                
  50. ?>
  51.  
  52. <?php 
  53.     if (isset($db_cxn)) {
  54.         mysqli_close($db_cxn); 
  55.     }
  56. ?>
Sep 26 '11 #5

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

Similar topics

0
by: rami | last post by:
Hi I'm using ADO.Net and Access 2002. I have two processes written in vc++ .net, lets call them for, example A and B. A opens a connection, do something and closes the connection. Then A...
1
by: krian | last post by:
Hi, I need a help from anybody. My problem is here I wrote two WebApplication in ASP.net Using C#. The name of the applications are (Journal.aspx and Payment.aspx). These Two pages have DataGrids...
5
by: Chris | last post by:
I have a meetings section I'm developing on our intranet. Using PHP/MySQL. Meeting info and Meeting docs reside on 2 related tables in the db. Users may want to upload anywhere from 1 to 10 or...
5
by: cheergurl | last post by:
i have a problem to display the data inserted at parent page.After i click a button submit at child page,the data that was inserted before are lost...can anybody give a solution to me how to remain...
18
by: fjm | last post by:
Hi everyone, I am looking for a php and maybe javascript solution that will show a particular php page when there is new data entered into a database table. So when a field in a table has new...
2
vinci
by: vinci | last post by:
Greetings! I Have A Little Problem... Is It Possible To Make The Identity In My Table Reset? I Have Used The Table Already To Make Insert Some Sample Data.. Now I Deleted Those Data Inserted.....
2
by: robin1983 | last post by:
Dear All, Firstly I would like thank all senior and junior who helping and sharing the knowledge to us. Actually, I have a small query. The problem is that I have a form which have only two...
8
jinalpatel
by: jinalpatel | last post by:
I have two tables. tblClass and tblWithdrawn. On my main form(bound to tblClass) I have several data entry fields like Date withdrawn, Status (active or withdrawn) Date Classified etc. Also...
1
by: digituf | last post by:
I have a form named:"RegistrationForm.php". when i click the "submit button", there's a data inserted in the database (the prove is, there a new row in the database), but there's no value from user...
2
by: Faran Akhtar | last post by:
Hello everyone. i m new on asp.net i m trying to insert data in sql database from textboxes on the page, but i m not succeded. i got no errors when i run my code, but no data get inserted in the...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
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...
0
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...
0
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...
0
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...

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.