473,785 Members | 2,938 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inserting more than one record

2 New Member
Hi, I recently created a mysql database using phpmyadmin. I then proceeded to make a form to insert data into the database, but the problem is that the form is only able to insert one record, and then if I try inserting another record, the new one is not seen in the database. There is no error messages seen in the form when entering a new record.

Heres the code for the form
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. </head>
  4. <center>
  5. <form method="post" action="script.php">
  6. <input type="hidden" name="id" value="null">
  7. <table>
  8. <tr><td align="left">Name</td>
  9. <td><input type="text" name="name"></td>
  10. </tr>
  11. <tr><td align="left">Telephone</td>
  12. <td><input type="text" name="telephone" size="20"></td>
  13. </tr>
  14. <tr><td align="left">Birthday</td>
  15. <td><input type="text" name="birthday" size="20"></td>
  16. </tr>
  17. <tr><td colspan="2">
  18. <p align="center">
  19. <input type="submit" value="Enter record">
  20. </td>
  21. </tr>
  22. </table>
  23. </form>
  24. </center>
  25. </html>
  26.  
And Heres the code for the php script
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $DBhost = "localhost";
  3. $DBuser = "username";
  4. $DBpass = "password";
  5. $DBName = "database name";
  6. $table = "table name";
  7.  
  8.  mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
  9.  
  10. @mysql_select_db("$DBName") or die("Unable to select database $DBName");
  11.  
  12. $sqlquery = "INSERT INTO $table VALUES('$id','$name','$telephone','$birthday')";
  13.  
  14. $results = mysql_query($sqlquery);
  15.  
  16. mysql_close();
  17.  
  18. print "<html><body><center>";
  19. print "<p>You have just entered this record<p>";
  20. print "Name : $name<br>";
  21. print "Telephone : $telephone<br>";
  22. print "Birthday :$birthday";
  23. print "</body></html>";
  24. ?>
Aug 7 '07 #1
5 2026
ak1dnar
1,584 Recognized Expert Top Contributor
$sqlquery = "INSERT INTO $table VALUES('$id','$ name','$telepho ne','$birthday' )";
Did you create a $_POST Array to Collect the VALUES? I didn't see it on the Script.php.
Aug 7 '07 #2
bob44
2 New Member
No I did not use an array in this case, but instead submitted each value individually.
Aug 7 '07 #3
r035198x
13,262 MVP
No I did not use an array in this case, but instead submitted each value individually.
Change your results line to

Expand|Select|Wrap|Line Numbers
  1.      $results =mysql_query($sqlquery) or die("Error : ".mysql_error());
Also don't forget to make use of the poor man's debugger( echo, printf, or whatever you call those things in PHP).
Aug 7 '07 #4
ak1dnar
1,584 Recognized Expert Top Contributor
No I did not use an array in this case, but instead submitted each value individually.
Please you may better to read here.

Get the HTML form elements to variables. I think Now you might know what is $_POST.

Expand|Select|Wrap|Line Numbers
  1. $name=$_POST['name'];
  2. $telephone=$_POST['telephone'];
  3. $birthday=$_POST['birthday'];
Pass The varibales to the MySQL Queary String.

Expand|Select|Wrap|Line Numbers
  1. $sqlquery = "INSERT INTO sample_table (name,telephone,birthday)
  2. VALUES (
  3. '$name', '$telephone', '$birthday'
  4. );";
  5.  
I didn't add the id formelement (may be it is the PK of your Table Structure). Actually value for that, has set up as Null. Still Only a String value. Its not same as the NULL on MySQL.

How is your Table Structure goes?
Aug 7 '07 #5
afraze
18 New Member
Your id column must be declared with auto_increment property. If u dont want to add id to your db by manually..

Kind Regards...
Aug 7 '07 #6

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

Similar topics

4
4406
by: Greg Ofiesh | last post by:
Anyone who can help, I have two tables T1 and T2. T1 has fields K1 and F2 and T2 has fields K2 and F1. F1 is the foreign key relating to K1 and F2 is the foreign key relating to K2. My initial question has been how can I add a row to both tables with accurate Fx values in one SQL INSERT statement? I have been told it cannot be done.
3
1365
by: Chris Dixon | last post by:
I am using a SQL Server 7 databaes with an Access 2000 front-end. I have a form where after the user inserts a record the screen refreshes to display a completely different record (without any prompt to do so in the code). The table being inserted into has an autonumber field for the PK. The SQL insert trigger on the table audits these changes to another table, which again uses an autonumber field.
3
1771
by: veerapureddy | last post by:
Hai everybody, i like to insert some records into database from html form by entering data.my problem is how can i check , whether a record is available in database about a particular employee before inserting. if a employee record is available(for example based on employee num) , then if i try to insert again with that employee id, it should not enter into database(avoid duplicate records with same employee num) can any one...
20
3021
by: dav3 | last post by:
Alright folks I am in need of a lil guidance/assistance here. I have a program which reads in a txt file. This txt file contains lines of the form January 3, 2007, 85.8 Now each line of the txt file is to be read into my java program and then inserted (from the program into an Access Database). I am not exactly sure of where the problem lies. I know it has something to do with how I am parsing the file, or how I am passing my arguments to...
2
1814
by: Question123 | last post by:
Hi i have one database table Table1.which contains almost 20000000 recordes. record to this table are inserted through storedprocedure. storedprocedure takes parameter as "value", Beginningdate, Endate . which will insert one record for each day between Beginning date and EndDate. Before inserting record i check is record exsist for date,if exsist i will update value otherwise insert new record.
10
2588
by: jmartmem | last post by:
Greetings, I have an ASP page with a 5x5 table embedded inside an Insert Record Form. This table contains several fields (mostly drop down list menus) and is used for corporate timekeeping (users record their daily hours by making selections from the list menus). My challenge is to figure out how the user can complete all rows of the table and click one button to submit the entire form AND have each row inserted as a unique record. In...
2
3097
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography section: Discography --------------------- DiscID
5
2169
by: rando1000 | last post by:
Okay, here's my situation. I need to loop through a file, inserting records based on a number field (in order) and if the character in a certain field = "##", I need to insert a blank record. So here's my method. I created two tables with the same structure as the table I'm inserting from. One table, Split_Temp, is the one I'll be inserting to. The other table, Split_Insert, contains the "Blank" record, which actually just has the word...
1
4610
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in Database but I'm stuck in the EDIT. I'm getting 2 problems over here. Below is the description: 1)The FIRST page will list all the records from the table which Admin can EDIT with CHECKBOX for each record to select. He can select one or more than one...
0
9645
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
10330
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
10093
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
9952
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...
0
8976
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
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
5381
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...
1
4053
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
3654
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.