473,434 Members | 1,834 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,434 software developers and data experts.

One form, two different tables that data needs to be entered in

8
Hello Folks, It's your new mysql and php user looking for some more help.

Background: I'm attempting to develop an online SCUBA Diving Log application. My plans are to put it together in pieces while at the same time learning on what I've done on a previous section.

The first part I have decided to start is the dive buddy section. This section will contain all your standard contact information (ie name, address, city, state, zip, phone numbers, email addresses and a photo).

I've broken this down even further to just wanting to enter a first name, last name, address line one and address line two.

The below code 'works' meaning no errors are produced just no data is being populated in the tables. the buddy table record count never increases were the address table does increase but no data is passed, it is just a blank entry.

The below code was butchered from several different examples from books I'm using. Connection to the database works fine BTW.

Thank you for any advise!!


Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Dive Buddy Entry Page</title>
  6. </head>
  7.  
  8. <body>
  9. <?php require_once('../Connections/scuba.php'); ?>
  10. <?php
  11. $Fname =$POST['Fname'];
  12. $Lname =$POST['Lname'];
  13. $address_1 =$POST['address_1'];
  14. $address_2 =$POST['address_2'];
  15.  
  16. $sql = "INSERT into scubalog.buddy SET
  17.     Fname='$Fname',
  18.     Lname='$Lname'";
  19. $sql = "INSERT into scubalog.address SET
  20.     address_1='$address_1',
  21.     address_2='$address_2'";
  22.  
  23. if  (@mysql_query($sql)) {
  24. echo '<p> New Buddy Added<p>';
  25. } else {
  26. echo '<p>Error adding new buddy<p> ' .
  27. mysql_error() . '<p>';
  28. }
  29. ?>
  30.  
  31. <p><a href="<?php echo $_server['PHP_SELF'];  ?>">Add another buddy</a></p>
  32.  
  33. <FORM ACTION="<?php echo $_server['PHP SELF']; ?>" method="post">
  34.  
  35.     <table align="left">
  36.     <tr valign="baseline">
  37.       <td nowrap align="right">First Name:</td>
  38.       <td><input type="text" name="Fname"  size="32"></td>
  39.     </tr>
  40.     <tr valign="baseline">
  41.       <td nowrap align="right">Last Name:</td>
  42.       <td><input type="text" name="Lname"  size="32"></td>
  43.     </tr>
  44.         <tr valign="baseline">
  45.           <td nowrap align="right">Address_1:</td>
  46.       <td><input type="text" name="address_1"  size="32"></td>
  47.     </tr>
  48.           <td nowrap align="right">Address_2</td>
  49.       <td><input type="text" name="address_2" size="32"></td>
  50.     </tr>
  51.     <tr valign="baseline">
  52.     <tr valign="baseline">
  53.       <td nowrap align="right">&nbsp;</td>
  54.       <td><input type="submit" value="Insert record"></td>
  55.     </tr>
  56.   </table>
  57.   <input type="hidden" name="MM_insert" value="form1">
  58. </form>
  59.  
  60.  
  61.  
  62.  
  63. </body>
  64. </html>
  65.  
Please use code tags when you post to the Forum. Read the Instruction on the Right side pane to your Editor.
Aug 13 '07 #1
5 2301
ak1dnar
1,584 Expert 1GB
So no Errors ! shall we try this first! please.may be in your php.ini it has disabled.(Error Reporting)
Aug 13 '07 #2
gregerly
192 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. <?php require_once('../Connections/scuba.php'); ?>
  2. <?php
  3. $Fname =$POST['Fname'];
  4. $Lname =$POST['Lname'];
  5. $address_1 =$POST['address_1'];
  6. $address_2 =$POST['address_2'];
  7.  
  8. $sql = "INSERT into scubalog.buddy SET
  9.     Fname='$Fname',
  10.     Lname='$Lname'";
  11. $sql = "INSERT into scubalog.address SET
  12.     address_1='$address_1',
  13.     address_2='$address_2'";
  14.  
  15. if  (@mysql_query($sql)) {
  16. echo '<p> New Buddy Added<p>';
  17. } else {
  18. echo '<p>Error adding new buddy<p> ' .
  19. mysql_error() . '<p>';
  20. }
  21. ?>
  22.  
The first thing that jumps out at me is your $sql. You have two $sql variables being declared, so only the last one is ever going to run. Your basically saying:

$sql equals This query.

then

Just kidding, $sql equals this other query. Your resetting the value of the variable.

Your actual SQL looks funky also. To know for sure I need to know is scubalog the table name or the database name? If it's the table name, your query should be rewritten as below:
Expand|Select|Wrap|Line Numbers
  1. $sql = "INSERT INTO scubalog (fname,lname,address_1,address_2) VALUES ('$fname','$lname','$address1','$address2');
I think that is a start to fixing your problem. I'm also assuming that your include at the top of the page is including a database connection and that works properly.

Good Luck

Greg
Aug 13 '07 #3
Markw
8
The first thing that jumps out at me is your $sql. You have two $sql variables being declared, so only the last one is ever going to run. Your basically saying:

$sql equals This query.

then

Just kidding, $sql equals this other query. Your resetting the value of the variable.

Your actual SQL looks funky also. To know for sure I need to know is scubalog the table name or the database name? If it's the table name, your query should be rewritten as below:

$sql = "INSERT INTO scubalog (fname,lname,address_1,address_2) VALUES ('$fname','$lname','$address1','$address2');

I think that is a start to fixing your problem. I'm also assuming that your include at the top of the page is including a database connection and that works properly.

Good Luck

Greg

Hi Greg,

Thanks for the reply.

The Database name is SCUBALOG and the tables are buddy and address.

Thanks for the heads up on the variable name. I'll change one of them to something different unless I can use one variable name to input the 4 values into the two different tables. Look forward to anymore help you can provide to me.
Aug 13 '07 #4
pbmods
5,821 Expert 4TB
Heya, Greg.

Mark's INSERT syntax, while 'funky', actually is valid. Check this out.

P.S. Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Aug 13 '07 #5
gregerly
192 Expert 100+
Heya, Greg.

Mark's INSERT syntax, while 'funky', actually is valid. Check this out.

P.S. Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Good call pbmods. Ya learn something new everyday! I thought I did use code tags (at least I meant to go back and add code tags after I typed my post...whoops)

Thanks for the update to the post pbmods.

Greg
Aug 14 '07 #6

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

Similar topics

3
by: Jason | last post by:
I am trying to filter records in a primary form based on records in related tables. The data in the related tables is being displayed in the primary form through subforms. To be more specific, I...
2
by: Iain Miller | last post by:
Struggling a bit here & would be grateful for any help. I have a table which has a list of people in it. Each person has a unique ID automatically allocated by Access but also belongs to one of 5...
2
by: Iain Miller | last post by:
Now this shouldn't be hard but I've been struggling on the best way as to how to do this one for a day or 3 so I thought I'd ask the assembled company..... I'm writing an application that tracks...
4
by: Kathy | last post by:
What is the standard technique for handling the fields in the following scenario on a continuous form? Multiple Divisions. Each Division has multiple Buildings. Each Building has a Supervisor. ...
6
by: jstaggs39 | last post by:
I want to create a Dcount and an If...Then...Else statement to count the number of records in a table based on the date that is entered to run the form. The If....Else statment comes in because if...
2
by: filbennett | last post by:
Hi Everyone, I'm generally unfamiliar with Access form design, but have programmed Cold Fusion applications for a couple of years. I'd like to build a data entry form in Access that allows the...
9
by: Blarneystone | last post by:
Hi, I am using VB.NET and trying to pull data from two different tables in the database. I am using what I think is standard code. But the data I am pulling is like the following: Table1...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
8
by: tess | last post by:
I have: table 1 - tblLeadInfo which includes a salesman ID field table 2 - tbllkpSalesman with all zips in the state and a Salesman assigned to that area. I have a form based on table #1 When...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
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...
1
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
agi2029
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,...
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...
0
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...

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.