473,399 Members | 3,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,399 software developers and data experts.

Inserting more than one record

2
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 2002
ak1dnar
1,584 Expert 1GB
$sqlquery = "INSERT INTO $table VALUES('$id','$name','$telephone','$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
No I did not use an array in this case, but instead submitted each value individually.
Aug 7 '07 #3
r035198x
13,262 8TB
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 Expert 1GB
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
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
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...
3
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...
3
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...
20
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...
2
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,...
10
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...
2
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...
5
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. ...
1
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...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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,...

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.