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 -
<html>
-
<head>
-
</head>
-
<center>
-
<form method="post" action="script.php">
-
<input type="hidden" name="id" value="null">
-
<table>
-
<tr><td align="left">Name</td>
-
<td><input type="text" name="name"></td>
-
</tr>
-
<tr><td align="left">Telephone</td>
-
<td><input type="text" name="telephone" size="20"></td>
-
</tr>
-
<tr><td align="left">Birthday</td>
-
<td><input type="text" name="birthday" size="20"></td>
-
</tr>
-
<tr><td colspan="2">
-
<p align="center">
-
<input type="submit" value="Enter record">
-
</td>
-
</tr>
-
</table>
-
</form>
-
</center>
-
</html>
-
And Heres the code for the php script -
<?
-
$DBhost = "localhost";
-
$DBuser = "username";
-
$DBpass = "password";
-
$DBName = "database name";
-
$table = "table name";
-
-
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
-
-
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
-
-
$sqlquery = "INSERT INTO $table VALUES('$id','$name','$telephone','$birthday')";
-
-
$results = mysql_query($sqlquery);
-
-
mysql_close();
-
-
print "<html><body><center>";
-
print "<p>You have just entered this record<p>";
-
print "Name : $name<br>";
-
print "Telephone : $telephone<br>";
-
print "Birthday :$birthday";
-
print "</body></html>";
-
?>
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.
No I did not use an array in this case, but instead submitted each value individually.
No I did not use an array in this case, but instead submitted each value individually.
Change your results line to - $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).
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. - $name=$_POST['name'];
-
$telephone=$_POST['telephone'];
-
$birthday=$_POST['birthday'];
Pass The varibales to the MySQL Queary String. - $sqlquery = "INSERT INTO sample_table (name,telephone,birthday)
-
VALUES (
-
'$name', '$telephone', '$birthday'
-
);";
-
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?
Your id column must be declared with auto_increment property. If u dont want to add id to your db by manually..
Kind Regards...
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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.
|
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...
|
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...
|
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.
| |
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...
|
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
|
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...
|
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...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |