This tutorial is a continuation on the “How to Access a MySQL Database Using PHP” tutorial that showed you how to setup a database using phpMyAdmin and how to read data from the database using PHP. In the tutorial I will show you how to write data to the database directly through a from on your website. This is going to be a very basic writing tutorial. We will get into more advanced stuff later on.
You will need to follow the first part of the the “How to Access a MySQL Database Using PHP” tutorial to setup the database and user permissions. After you do that you can continue with this tutorial.
At this point you should have the database setup with some test data in it. I am going to show you how to update the date by using a form on a website. First we will create the form. You can use any editor you would like. Sometimes I use notepad, but for this tutorial I will be using cPanel’s web base editor. It allows me to edit the files directly on my server and also color codes the lines nicely.
First we will create our form. We will name it “form.php”.

Now we will create the form using some basic html, nothing fancy. Start with the form tag. Notice that the form action is set to update.php, that is the script that will update the database.

Now we will add 3 input boxes for our 3 columns in the database. FName, LName, and PHON. There is a 4th column in the database we created, the ID field. That field is auto generated so we do not need to update it.

We created the input boxes for each field in the database. You will notice that the size of each input is limited to the size of our fields in the database. Each field is a text because we want a text box.
Next we need to add a submit button.

A submit button is also an input field. The type is submit, which will create a button and the value gives the button a label that you will see from your browser.
That is it for form.php. I might as well mention that there is no reason that I named this with a .php extension. It could have been called form.html and it would have functioned the same way because there is no php code on the form. Save the fiel and open it in your browser. It should look like this.

The next step is to create the update.php file. This file will update the database with the new information. Create a new file called update.php.

Now to start coding a php file we always start with the open and close php tags.

The first thing we are going to do is capture the data that was sent from the form.php file and store the info as variables. Because the form method was set to post, we can use the post variable function to collect the data. You will notice that the names in the post function will match the names we used on the form.

Now we will make a connection to the database. You will have to replace:
“localhost” with the location of your server
“projectc_testuse” with your username
“password” with your password
Then we are selecting the “projectc_Test” database you will change that to whatever you named the database in the first tutorial.

Next we are going to create the query that will insert a new row in the database. As you can see we are inserting in the table called TestTable and were are inserting the fields ID, FName, LName, and PHON. The actual values are coming from the variables. The ID fields is left NULL because it is auto generated by the database.

Now all we have to do is have the query execute. Then if the query fails we will print an error. If it is successful we will print the info that was added to the database.

Now you can test out the form.

When you submit the form you should see your results displayed.

Now if you run the php file from part one of this tutorial you should see you updated info in displayed along with everything else that was in the database.

So that is a very basic way of writing to a MySQL database using PHP. Now you should be able to create a database, write data to the database, and read from the database. I hope to create some more advanced PHP/MySQL tutorials in the future.
Jalaj on February 4, 2008 at 1:29 am
Good post for those new to php/mysql. Glad to see regular posts after a long inactivity. Please continue posting regularly if not frequently.
[Reply]
janaka on February 26, 2008 at 2:30 am
That is a great help
[Reply]
sunita Reply:
July 31st, 2010 at 12:06 pm
hello
[Reply]
Enlamsweawn on February 29, 2008 at 4:21 am
Hello there.
Just found your site. Great job!
I like it much.
look here http://live.com
[Reply]
gabr on February 29, 2008 at 10:55 am
dasdasdasd
[Reply]
upendra on March 11, 2008 at 5:31 am
Hello
Just found your site. !
I like it and thanks .
[Reply]
Hunter on March 15, 2008 at 1:32 am
I run the script and it echos it was updated but the table doesnt show any info was inserted, what could i have possibly one wrong?
[Reply]
John Ward on March 15, 2008 at 5:09 am
Do you have any info in the table at all. For some reason if I do not enter the first row of data manually using php my admin, then the table will not update from the php file.
[Reply]
Hunter on March 15, 2008 at 9:20 pm
i entered data myself through phpmyadmin and then tried to with the script and it did squat
[Reply]
John Ward on March 15, 2008 at 10:19 pm
It’s hard to tell what could be happening. I would check the code one more time. It is strange that it is not throwing a MySQl error. Make sure the query is right.
[Reply]
ds Reply:
June 2nd, 2010 at 4:10 am
dssa
[Reply]
Hunter on March 16, 2008 at 8:27 pm
i checked it but i also found a friends script and its doing what i need but not exactly i need to code a script that pulls info from a database but can also put it in and yeah theres to much to explain in this lol, i just need to find someone to talk mono on mono on like a chat thing or something and see if they can help me
[Reply]
Zeek on March 17, 2008 at 6:50 pm
Thank you very much for the training lesson above. It has come in handy close to a deadline.
[Reply]
web pix on March 25, 2008 at 2:32 pm
Thanks a lot….it clears my doubts
[Reply]
astravie on March 31, 2008 at 11:17 am
Thanx a lot!
I’ll be waiting for the next script, the one that will searching the database
[Reply]
rifas on April 16, 2008 at 11:45 pm
thank a lot…
it is very helpful for me to do assignment..
[Reply]
moored on April 27, 2008 at 6:38 pm
I tried you’re code and no matter what i did it would not work
[Reply]
Shah on May 5, 2008 at 6:28 am
Hi!
I need to extract data from mysql by using php….and I want as a link; so user can click to see details of that link (more info)
can u give me a hand pls!!!!!
[Reply]
Phil on May 17, 2008 at 7:06 am
hello
Thanks for the tips, but why do firefox & ie both return this parse error:
“syntax error, unexpected ‘;’ in /home/gypsy/public_html/update.php on line 10″
? please help
[Reply]
Phil on May 17, 2008 at 9:30 am
ok dont worry, figured it out, I think I am on a slightly newer version of php or something, because changing my syntax slightly fixed the error.
instead of
echo “updated with: ” .variable. ;
I wrote
“updated with: “, variable ;
[Reply]
sayed Mujahed Hussaini on May 24, 2008 at 2:10 am
Thank you very much
[Reply]
sundar on June 12, 2008 at 1:58 am
hi
i want set a update and view buton
[Reply]
sanae on June 16, 2008 at 10:35 am
if you please help me! i am a student and i have web project
if i have a page in html with checkbox and i want to select one or more
pieces how can i write the php page to add the selected pieces to the invoice!
with my thanks
[Reply]
Mike Maguire on June 17, 2008 at 7:18 pm
@ sanae
There is an easy way to do this. I am going to do a tutorial on this that will post next week some time. For starters you would need to make all the checkboxes be in an array.
eg:
Box 1
Box 2
Box 3
You receiving file should then contain a for next loop that will take each box and if they were checked and if they were to run a query to enter them into the database like so:
foreach($cats as $key => $value) {
if ($value > 0) {
$sql = sprintf(“insert INTO value_table(row1,rrow2) VALUES(‘%s’,'%s’);”,
$value, $old_no);
mysql_query($sql);
}
}
That should do what you need to do. Let us know if you have issues and thanks for the great tutorial idea.
[Reply]
Mike Maguire on June 17, 2008 at 7:22 pm
(HTML not allowed in comments) Here is what Box1, Box2, and Box3 should be.
input type=’checkbox’ name=’boxes[]‘ value=’1′ />Box 1
input type=’checkbox’ name=’boxes[]‘ value=’2′ />Box 2
input type=’checkbox’ name=’boxes[]‘ value=’3′ />Box 3
[Reply]
Junaid Shabbir on June 27, 2008 at 10:45 am
Nice tutorial, syntax highlight really helps in understanding the code
[Reply]
long4hort on June 28, 2008 at 10:00 am
nice tutorial
[Reply]
IJ on June 30, 2008 at 10:01 am
I tried it and it did not update…not sure why.
I typed the exact thing you have
[Reply]
IJ on June 30, 2008 at 10:12 am
Here is my code:
when ran, it gives the error “error updating database”
Please help!!
html file
————–
Members Search
Enter Member Information:
ID:
First Name:
Last Name:
Phone Number:
Php file
————-
$fname = $_POST['FirstName'];
$lname = $_POST['LastName'];
$phone = $_POST['PhoneNumber'];
mysql_connect(“localhost”, “bookorama”, “bookorama123″) or die (‘Error: no db connection ‘ . mysql_error());
mysql_select_db(“test”);
$query=”INSERT INTO members (id, firstname, lname, phone)VALUES (‘NULL’, ‘”.$fname.”‘, ‘”.$lname.”‘, ‘”.$phone.”‘)”;
mysql_query($query) or die (‘error updating database’);
echo “database was updated with: ” .$fname.” “.$lname.” “.$phone;
// close connection
mysql_close();
[Reply]
John Ward on June 30, 2008 at 2:01 pm
@IJ
Can you give us the exact error message? That will make troubleshooting much easier.
[Reply]
IJ on July 2, 2008 at 10:09 pm
@John
the error is :
error updating database
[Reply]
Mahadia Tunga on July 16, 2008 at 12:26 am
your way is the best way of teaching for people who need to learn faster.
[Reply]
mahadia on July 19, 2008 at 6:45 am
hi!
when i submit the form a blank page appear and nothing is being updated in mysql database,where could i be wrong
thanx!
[Reply]
ian on July 23, 2008 at 3:57 am
tnx but i didnt get it
[Reply]
fil mcrackin on July 28, 2008 at 2:20 am
keep getting error database not updated, any suggestions?
Here’s my code, seems right?
[Reply]
paul on July 30, 2008 at 5:49 am
Thanks for this simple article about inserting to database
[Reply]
Ritesh on July 30, 2008 at 6:46 am
Nice code.
It works very well.
[Reply]
JyRnZa on August 7, 2008 at 1:16 am
a big help
[Reply]
Charles on August 7, 2008 at 12:03 pm
Great article, one more thing can u plz show me how to use a login form to get data from mysql…. would be of immense help….thanx yet again…!
[Reply]
Charles on August 7, 2008 at 1:32 pm
oh, oh?! it does not return Fname, but shows lname and PHON… deleted everything and started again from the very beginning still d same… please help me u can reply to my mail addy…
[Reply]
Smith on August 8, 2008 at 3:38 am
Where can i download the whole code?????
[Reply]
joel on August 14, 2008 at 3:28 am
pliz guy, I wanted to register members but when I clicked at submit button it displays a blank page.my code is:
[Reply]
Christian on August 31, 2008 at 2:03 am
I am trying this out and getting a blank page too. My form is at:
http://www.tccnotary.com/newclients.php
Right now my script is only attempting to write the submitted order date (the first field) to the database. Once I know that works I can work on the other fields. My script, insert.php, is:
[Reply]
Christian on August 31, 2008 at 2:03 am
$orderDate = $_POST['orderDate'];
mysql_connect (“localhost”, “tcc”, “cameronTom”) or die (‘Error: ‘ . mysql_error ());
mysql_select_db (“neworder”);
$query=”INSERT INTO clientsopennew (orderID, orderDate)VALUES (‘NULL’,'”$orderDate.”‘)”;
mysql_query($query) or die (‘Error updating database’);
echo “Database updated with: ” .$orderDate ;
[Reply]
Christian on September 4, 2008 at 2:43 am
Anyone? Anyone?
[Reply]
Martijn on September 9, 2008 at 10:54 am
Can anyone help why this is not working. The database is not updated.
All help is more than welcome.
Thanks
$connectionID=mysql_connect(‘localhost’,'test’,”);
$dbname=mysql_select_db(‘testdb’);
if($action==”INS”)
{
$Poule1 = $_POST['Poule1'];
$Poule2 = $_POST['Poule2'];
$datumtijd = $_POST['datumtijd'];
$team = $_POST['team'];
$thuis = $_POST['thuis'];
$uit = $_POST['uit'];
$Locid = $_POST['Locid'];
$scheidsr1 = $_POST['scheidsr1'];
$scheidsr2 = $_POST['scheidsr2'];
$tafel = $_POST['tafel'];
$klok = $_POST['klok'];
$sec = $_POST['sec'];
$zaalw = $_POST['zaalw'];
$query=”INSERT INTO NS_wedstrijden (Poule1, Poule2, datumtijd, team, thuis, uit, Locid, scheidsr1, scheidsr2, tafel, klok, sec, zaalw) VALUES (‘”.$Poule1.”‘, ‘”.$Poule2.”‘, ‘”.$datumtijd.”‘, ‘”.$team.”‘, ‘”.$thuis.”‘, ‘”.$uit.”‘, ‘”.$Locid.”‘, ‘”.$scheidsr1.”‘, ‘”.$scheidsr2.”‘, ‘”.$tafel.”‘, ‘”.$klok.”‘, ‘”.$sec.”‘, ‘”.$zaalw.”‘)”;
$result = mysql_db_query(“Wedstrijd”,$query,$connectionID) or die (“Error updating database” . mysql_error() . “\n$query\n”);
[Reply]
Christian on September 9, 2008 at 8:57 pm
All the helpers appear to have left.
[Reply]
John Ward on September 9, 2008 at 9:05 pm
The code looks like it should work.
[Reply]
Christian on September 11, 2008 at 3:37 pm
Do you mean Martijn’s code or my code? Or both?
[Reply]
Chase on September 12, 2008 at 9:03 pm
:Martijn:
Try something more along the lines of this coding instead, if you prefer to use the mysql_db_query command.
<?php
$connectionID = mysql_connect (‘localhost’, ‘test’, ‘password’);
$dbname = mysql_select_db(‘testdb’);
mysql_connect ($connectionID)
or die (“Could not connect to the MySQL server.”);
$query = “INSERT INTO NS_wedstrijden (Poule1, Poule2, datumtijd, team, thuis, uit, Locid, scheidsr1, scheidsr2, tafel, klok, sec, zaalw) VALUES (‘”.$Poule1.”‘, ‘”.$Poule2.”‘, ‘”.$datumtijd.”‘, ‘”.$team.”‘, ‘”.$thuis.”‘, ‘”.$uit.”‘, ‘”.$Locid.”‘, ‘”.$scheidsr1.”‘, ‘”.$scheidsr2.”‘, ‘”.$tafel.”‘, ‘”.$klok.”‘, ‘”.$sec.”‘, ‘”.$zaalw.”‘)”;
$result = mysql_db_query ($dbname, $query)
or die (“Query ‘$query’ failed with error message: \”" . mysql_error () . ‘”‘);
// Display the data returned by the query
while ($temp = mysql_fetch_row ($mysql_result)) {
echo $temp[0], ”;
}
?>
[Reply]
Sasha on September 20, 2008 at 7:54 am
Hi there,
I’m desperatly looking for help so hope you guys could really help me out.
I’d need something very simple in which a user can insert data to the DB (like this) and then have a search field per one of the fields (example name) and have everyone of that name pop out.
How would this be done?
Thanks!
[Reply]
Mike Maguire on September 21, 2008 at 10:05 pm
Sasha:
Check out this tutorial that I wrote a while ago:
http://teamtutorials.com/photoshop-tutorials/web-graphics/sql-select-based-on-text-inserted-into-a-text-box
I think it is what you are looking for. Thanks.
[Reply]
Christian on September 30, 2008 at 2:41 pm
Still no answer for my question.
[Reply]
John Ward on September 30, 2008 at 3:17 pm
Christian, try to echo your sql variable after you create it. Seems it is not creating a valid update.
[Reply]
John Ward on September 30, 2008 at 3:23 pm
Try either of these:
$query = ‘INSERT INTO clientsopennew (orderID, orderDate)VALUES (NULL,”$orderDate”)’;
$query = “INSERT INTO clientsopennew (orderID, orderDate)VALUES (NULL,’”.$orderdate.”‘)”;
[Reply]
Christian on September 30, 2008 at 3:59 pm
Okay, I have an update and clarification. When I use:
the database does get populated. But when I use:
The database does not get populated and a blank screen appears.
[Reply]
Christian on October 2, 2008 at 4:20 pm
Thanks, John, for the response. Okay, I basically have it working now. You can fill out all the fields and it’ll populate the database. Only two problems remain (and they are minor compared to what I was facing before but still important):
1. If the user uses a character such as an apostrophe it prevents the database from populating.
2. It’s not populating the product field, which is the only field in this form that utilizes radio buttons.
[Reply]
John Ward on October 2, 2008 at 4:28 pm
Christina look up sanitizing database inputs. This will gt you started http://xkcd.com/327/ . Not sure about the radio buttons, echo the query and see if the value is being sent.
[Reply]
Christian on October 2, 2008 at 6:04 pm
“sanitizing database inputs”
Okay, got it. Thanks . . . and funny cartoon.
[Reply]
Sanjeev on October 7, 2008 at 4:03 am
this is sanjeev
i have written that code but i am not able to update data in my sql ,
i am getting the error.
Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\sandeep\update.php on line 9
pls help me
[Reply]
Thabiso Chizwe on October 10, 2008 at 4:50 am
when i click submit the whole contents of my php file are displayed in the html page
here is my script
<?php
$Title= $_POST['Title'];
$FirstName= $_POST['FirstName'];
$Surname= $_POST['Surname'];
$JobTitle= $_POST['JobTitle'];
$Company=$_POST['Company'];
$Department= $_POST['Department'];
$Office= $_POST['Office'];
$BusinessPhone= $_POST['BusinessPhone'];
$HomePhone= $_POST['HomePhone'];
$Fax= $_POST['Fax'];
$Cell =$_POST['Cell'];
$Email = $_POST['Email'];
$WebPageAddress= $_POST['WebPageAddress'];
$PhysicalAddress= $_POST['PhysicalAddress'];
$MailingAddress= $_POST['MailingAddress'];
$Birthday= $_POST['Birthday'];
$month= $_POST['month'];
$year = $_POST['year'];
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (“Error connecting to MySQL”);
mysql_select_db($dbname, $conn) or die (“Could not open database”);
$query=”INSERT INTO contacts(Title,FirstName,Surname,JobTitle,Company,Department,Office,BusinessPhone,HomePhone,Fax,Cell,Email,WebPageAddress,PhysicalAddress,MailingAddress,Birthday,month,year)VALUES(‘”.$Title”‘, ‘”$FirstName”‘,’”$Surname”‘,’”$JobTitle”‘,’”$Company’”,’”.$Department’”,’”.$Office”‘,’”.$BussinessPhone’”,’”.$HomePhone’”,’”.$Fax”‘,’”$Cell”‘,’”.$Email”‘,’”.$WebPageAddress”‘,’”.$PhysicalAddress”‘,’”.$MailingAddress”‘,’”.$Birthday”‘,’”.$month”‘,’”.$year”‘)”;
mysql_query($query);
echo “Record Addedclick hereto return to contacts”;
$result = mysql_query($query);
mysql_close($db1);
mysql_close($conn);
echo “”;
?>
[Reply]
Amir on October 20, 2008 at 3:49 pm
Hi
I need help please.
I keep trying and get the messege: Error Updating Database.
Any suggestions?
Many thanks in advance.
Amir
The codes:
form:
First Name:
Last Name:
Phone-Numbe:
update:
table:
<?php
// Connects to Database
mysql_connect(“localhost”, “xxx”, “xxx”) or die(mysql_error());
mysql_select_db(“friends”) or die(mysql_error());
//collects data from “friends” table
$data = mysql_query (“select * from tablename “) or die (mysql_error(Error));
//puts the “tablename” info into the $info_array
$info=mysql_fetch_array($data);
//print out the contents of the entry
Print “”;
Print “”;
Print “Family Name:”.$info['FName'].”";
Print “Last Name:”.$info['LName'].”";
Print “Phone No.:”.$info['PHON'].”";
Print “”;
?>
[Reply]
Henry on October 22, 2008 at 6:32 am
Please can you kindly send the query for insserting into the database using php? because i tried the one written here but the report that I got was that there was an error in line 7 which I tried all tha I could but it still dosent work.
[Reply]
Henry on October 22, 2008 at 6:36 am
I will be Very greatful if someone can kindly help solve my TRASH
Thanks
[Reply]
Henry on October 22, 2008 at 7:02 am
Please is there a web site or page that I can download the whole code????????????????????????
[Reply]
John Ward on October 22, 2008 at 9:50 am
Please post lines 6 and 7 from your code. Most likely you forgot a semicolon.
[Reply]
John Ward on October 22, 2008 at 9:51 am
Also these comments are getting pretty long. Maybe we should launch a forum for these types of questions?
[Reply]
John Ward on October 22, 2008 at 10:26 am
Thiboso are you saving these files with a .php extension and is php running on your server??
[Reply]
Henry on October 22, 2008 at 10:31 am
Please take a good look at this query that I wrote.
Is there anything missing?? Yet I still recieve this (Parse error: parse error, unexpected ‘;’ in C:\wamp\www\root\update.php on line 7).
Please I need your help Here …thanks so Far
[Reply]
John Ward on October 22, 2008 at 12:07 pm
I don’t see the code you posted, but that error message is telling you exactly what is wrong. Unexpected semicolon, which means you have an extra one or you forgot something else in the line before it. If you post lines 6 &7 I will tell you what is wrong with them.
[Reply]
John Ward on October 22, 2008 at 12:10 pm
Amir there is no update statement in the code you posted. The code you posted cannot result in the error you are stating.
[Reply]
Amir on October 25, 2008 at 5:33 am
Hi All
Thank you.
Got my mistake and fixed it.
Working now.
Many thanks!!
And I think a forum for that sort of questions would be very helpfull.
Amir
[Reply]
Alee on November 6, 2008 at 7:20 am
very nice and useful example gud work keep it up …
[Reply]
Priya on November 24, 2008 at 3:18 am
Hi,
Very helpful site.
I have a problem .. could any ine pls help me.
I’m using php,MySql.
In my code there is a checkbox. I want to update that checkbox value in the database.. whether it is checked or not. How to capture that value in the database.
[Reply]
Paul on November 27, 2008 at 12:53 am
I cannot seem to get the database to update or post. Please Help. Here’s my code.
[
<?php
//Verrify Session
session_start();
if(!session_is_registered(myusername)){
header("location:index.php?id=accessdenied");
}
// Rest of Page
require_once ("functions.php");
connect();
mysql_select_db("news")or die("cannot select DB");
// Table Selection - Via URL
$table = $_GET['table'];
// Defining The Form Data
$form_subject = $_GET['subject'];
$form_date = $_GET['date'];
$form_column = $_GET['column'];
$form_preview_post = $_GET['preview_post'];
$form_full_post = $_GET['full_post'];
// Defining Who It Was Posted By
$session_name = $_SESSION['myusername'];
$sql=”INSERT INTO `$table`(`subject`, `date`, `category`, `preview`, `post`)VALUES(`$form_subject`, `$form_date`, `$form_column`, `$form_preview_post`, `$form_full_post`)”;
mysql_db_query($sql);
/*
if($result){
echo “Successful”;
echo “”;
echo “Back to main page“;
}
else {
echo “ERROR”;
}*/
?>
]
[Reply]
k0s on December 1, 2008 at 11:29 am
Hi,
perfect tutorial
thank you,..
a small advanced question.. i would like to fill out “radiobuttons names” with categorys which should be read out from a database and insert values like names description etc into the given and by radiobutton selected category.
could you point me to a similar tutorial ?
thank you very much!
have a nice day
[Reply]
Patrick on December 7, 2008 at 9:01 pm
Hey I am having the same problem as Amir, I keep getting the “die” message “error updating database”.
I’m guessing mismatched column names with the database? but I’ve double checked about a zillion times lol. sorry to be a pain…
Thanks for your help.
[Reply]
Patrick on December 7, 2008 at 9:15 pm
sorry! i got it working! yay
stupid commas…
[Reply]
ashish on December 28, 2008 at 4:12 pm
hi..thanks for the code..while i m clicking on ‘Update database’ button, the output is
$Fname=$_Post['Fname']; $Lname=$_POST[['Lname']; mysql_connect(“localhost”,”abcd”,”1234″) or die(‘Error’ .mysql_error()); mysql_select_db(“test1″); $query=”INSERT INTO test1(ID,Fname,Lname) VALUES (‘NULL’,'”.$Fname.”‘, ‘”.$LName”)”; mysql_query($query)or die (‘Error updating database’); echo “Database Updated with: “.Fname.” “.LName.; mysql_close();
My code for update.php( i m using the same code as mentioned above: -
Untitled Document
$Fname=$_Post['Fname'];
$Lname=$_POST[['Lname'];
mysql_connect(“localhost”,”abcd”,”1234″) or die(‘Error’ .mysql_error());
mysql_select_db(“test1″);
$query=”INSERT INTO test1(ID,Fname,Lname) VALUES (‘NULL’,'”.$Fname.”‘, ‘”.$LName”)”;
mysql_query($query)or die (‘Error updating database’);
echo “Database Updated with: “.Fname.” “.LName.;
mysql_close();
[Reply]
shakir on January 26, 2009 at 2:40 pm
how to display the data in a table from the database using select query
[Reply]
Shalom on February 18, 2009 at 10:28 am
The code you palced really help. I also wanted to know How you merge several List/menu options into one when writting php code. Lets say u have a drop down list for day another one for month and year. But the database entry is a single entry.
[Reply]
Jack on February 19, 2009 at 2:29 am
I’m just trying to add one record on my database. Unfortunatley it just says ‘Error updating database’ everytime I try to add a valid record. Here is my code. Please help. Very Urgent.
<?php
$country_name = $_POST['country_name'];
// Initiating a MySQL connection
$db_host = “localhost”;
$db_username = “testuser”;
$db_passwd = “testpass”;
$db= mysql_connect($db_host, $db_username, $db_passwd) or die (“Could not connect to database”);
echo “Connection established.”;
// Connecting to database
$db_name = “country”;
mysql_select_db(“$db_name”) or die (“Could not select the database gurung”);
echo “Database country is selected.”;
$query=”INSERT INTO country (countryID, country_name) VALUES (‘NULL’, ‘”.$country_name”‘)”;
mysql_query($query) or die (‘Error Updating database’);
echo “Database Updated With: ” .$country_name. “”;
?>
[Reply]
John Ward on February 19, 2009 at 6:02 am
Jack. I lied in the tutorial above. You don’t have to use . if you use double quote it will echo the variable. Try this:
$query=”INSERT INTO country (countryID, country_name) VALUES (‘NULL’, ‘$country_name’)”;
[Reply]
John Ward on February 19, 2009 at 6:03 am
Or if you want to do it the other way:
$query=”INSERT INTO country (countryID, country_name) VALUES (‘NULL’, ‘”.$country_name.”‘)”;
You forget a period
[Reply]
Jack on February 19, 2009 at 9:17 pm
John, thanks for the reply. I tried removing the double quote in $country_name but it still comes with ‘Error updating database’ error. When you mentioned “You forget a period”. What do you mean by that. The $query you wrote in your second comment is same as the one I wrote! Please help.
Many thanks, Jack.
[Reply]
Jack on February 20, 2009 at 12:12 am
Hey folks,
If anyone of you out there is struggling, use the following code:
This code works perfect. Put your thumbs up.
Cheers,
Jack
[Reply]
Convert a MySQL date field using PHP Functions | Team Tutorials on February 20, 2009 at 3:16 am
[...] Creating a Form that will Search a MySQL Database [...]
vivek kumar on February 28, 2009 at 3:06 pm
sir,what you did above doesn’t work for me……………
nothing is entered in my data base
please help me
its urgent…….
reply soon
[Reply]
sivagami on March 3, 2009 at 2:39 am
<?php
// Connects to your Database
$host=”localhost”; //Host Name
$username = ” root”; //mysql user name
$password =” sivagami”; //mysql password
$db_name =”tms” ;//database name
$tbl_name =”employee” ; //Table Name
mysql_connect(“localhost”, “root”, “sivagami”) or die(mysql_error());
mysql_select_db(“tms”) or die(mysql_error());
$emp_id = $_POST['emp_id'];
$emp_name = $_POST['emp_name'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$date_of_birth = $_POST['date_of_birth'];
$date_of_join = $_POST['date_of_join'];
$designation = $_POST['designation'];
$query =”INSERT INTO $tbl_name (emp_id, emp_name,address,phone,date_of_birth,date_of_join,designation) VALUES ( ‘”.$emp_id.”‘, ‘”.$emp_name.”‘,’ “.$address.”‘,’”.$phone.”‘,’”.$date_of_birth.”‘, ‘”.$date_of_join.”‘,’”.$designation.”‘ )”) or die(mysql_error());
$result = mysql_query($query) or die(‘Error updating database’);
if($result)
{
echo “successfull”;
echo “”;
}
else {
echo “ERROR”;
}
mysql_close();
?>
is this correct or not. i doesn’t work properly. i am not able to insert data to table through forms in php
please anybody help me.
[Reply]
John Ward on March 3, 2009 at 2:19 pm
Why are you trying to add the die() function to the $query VARIABLE.
Also if you are using php 5 there is no need for concatenation of a string if you use double quotes (meaning no need to use “.” just simple put the $variable in like below) I wrote this a long time ago and have learned a lot since. Maybe I will write some kind of updated version if I get a chance.
Anyway try this and if it doesn’t work you are going to have to figure it out. This isn’t a code writing service, though I could probably make a pretty penny if I charged for it
<?php
// Connects to your Database
$host=”localhost”; //Host Name
$username = ” root”; //mysql user name
$password =” sivagami”; //mysql password $db_name =”tms” ;//database name $tbl_name =”employee” ; //Table Name
mysql_connect(“localhost”, “root”, “sivagami”) or die(mysql_error());
mysql_select_db(“tms”) or die(mysql_error());
$emp_id = $_POST['emp_id'];
$emp_name = $_POST['emp_name'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$date_of_birth = $_POST['date_of_birth']; $date_of_join = $_POST['date_of_join']; $designation = $_POST['designation'];
$query =”INSERT INTO $tbl_name (emp_id, emp_name,address,phone,date_of_birth,date_of_join,designation) VALUES ( ‘$emp_id’, ‘$emp_name’,'$address’,'$phone’,'$date_of_birth’, ‘$date_of_join’,'$designation’)”;
$result = mysql_query($query) or die(‘Error updating database’);
if($result){
echo “successfull”;
echo “”;
}
else {
echo “ERROR”;
}
mysql_close();
?>
Also in your code I don’t think mysql_close() is actually doing anything. You need to set a variable equal to your connect and then close it. Something like $conn = mysql_connect(whatever you want here); mysql_close($conn);
If the code outputs an error try to Google it. If it doesn’t out put anything echo $query to verify it is valid.
[Reply]
Charles Scott on March 3, 2009 at 2:48 pm
Works perfectly. Thank you
[Reply]
sivagami on March 5, 2009 at 1:58 am
i have a poblem in inserting data into table. i am puting dateof birth as select oprion as month, year,date. the user select this and post to table. but i create only date_of birth field as date data type. hoe i insert these there input into one field in table. please anybosy help me. the following coding only use. is ther eany error suggesstion please reply me.
[Reply]
sivagami on March 5, 2009 at 2:07 am
Thanks mr.john ward. i try as you said. i have further confusion i am putting date of birth as select option in form user enter three inout date,month,year. but i am using dateof birth as single field in mysql table. now how i put my date into table. the following code only i tried. but it also doesn’t work. what to do sir.
[Reply]
John Ward on March 6, 2009 at 6:09 am
sivgavin you hav three fields day month year, just format them into a date before you insert it into the database. $date = $_POST[''year"].”/”.$_POST_['month''].”/”.$_POST['day'] or whatever format you want ot use. THen insert $date.
[Reply]
Editing MySQL Data Using PHP | Team Tutorials on March 13, 2009 at 1:03 pm
[...] If you haven’t taken a look at the past tutorials you may want to: How to Access a MySQL Database Using PHP Inserting Data Into a MySQL Database using PHP [...]
sivagami on March 14, 2009 at 12:20 pm
how i pass my dropdown menu & radiobutton selected item into database mysql . please reply me . i am in deadline of my final year project work. i am a student.
[Reply]
John Ward on March 15, 2009 at 8:50 pm
sivagami it sounds like you need to read the tutorial again. I tell you exactly how to do this with an input box. Set the name on your drop down box and that will be the variable passed.
[Reply]
sivagami on March 16, 2009 at 4:09 am
thanks sir. it works correctly. sorry i am poor in php. thats why i am querying here. i am using separate function for getting date month and year. that’s why i am finding very difficult. here is my coding.
function createYears($start_year, $end_year, $id=’year_select’, $selected=null)
{
/*** the current year ***/
$selected = is_null($selected) ? date(‘Y’) : $selected;
/*** range of years ***/
$r = range($start_year, $end_year);
/*** create the select ***/
$select1 = ”;
foreach( $r as $year )
{
$select1.= “$year\n”;
}
$select1 .= ”;
return $select1;
}
from this which one is id of select option. either year_select or return value select1.
[Reply]
Rod on March 23, 2009 at 5:33 pm
hey there!
everything was working proper until the update.php part or the 3rd part!
it works half way thou,
it send info to the info to the server, but only the field, not the info shows either on the server or in the update.php
example name: john
on my server and .php file will show name: “empty or blank”
that start to happen i was trying to fix the update.php file, i went to server and add two more names as in the beginning of the tutorial and then when i used the database.php file to see if updates the only filed showing was the phone number , first and last name was “black”
what went wrong?
[Reply]
Rod on March 23, 2009 at 5:35 pm
ah also when it updates the info below will show blank!
Database Updated With: “blank”
[Reply]
John Ward on March 23, 2009 at 7:38 pm
Seems like your variables aren’t getting passed. Echo your update statement and see if it is correct.
[Reply]
Rod on March 23, 2009 at 11:11 pm
by the way how do i echo my update statement ?
[Reply]
John Ward on March 24, 2009 at 3:38 am
$query=”INSERT INTO TestTable (ID, FNAME, LNAME, PHON)VALUES (‘NULL’,'”.$FNAME.”‘,’”.$LNAME.”‘,’”.$PHON.”‘)”;
mysql_query($query) or die (‘Error Upadating Database’);
echo “Database Updated With: “.$FNAME.” “.$LNAME.” “.$PHON;
echo $query;
You probably aren’t passing the variables correctly. Are you using the get or post method?
[Reply]
Rod on March 24, 2009 at 11:04 am
hey john,
i find out what was wrong with it!
$FNAME = $_POST['FNAME'];
$LNAME = $_POST['LNAME'];
$PHON = $_POST['PHON'];
i typed post instead POST ops!
but sitll not completely right! its not passing the phone data! it does not show any error , just dont add to “Database Updated With: “.$FNAME.” “.$LNAME.” “.$PHON; either the database itself
i know it was a post before with similar problem not sure if was a solution for it! i’ll go back there and read again!
also i add
echo $query;
to my code and it didnt worked to well!
i’m postin my whole update.php file so you can take a look!
update
[Reply]
Rod on March 24, 2009 at 11:05 am
update
[Reply]
Rod on March 24, 2009 at 11:06 am
[Reply]
Rod on March 24, 2009 at 6:51 pm
Hey John,
thankx so much! it works perfectly now,
just for future developers i will add this,
my code wasnt working first, instead
POST
i typed
post
second!
on my form.php i mistyped again,
instead PHON i typed FHON;
problem solved now! thanks John code is great!
now moving to Log in part…hehe
[Reply]
Rod on March 24, 2009 at 11:09 pm
Hey john.
me again!
one more question, how do i display my data in row and colomn like this
mysql> DESCRIBE employee_data;
+——–+——————+——+—–+———+—————-+
| Field | Type | Null | Key | Default | Extra |
+——–+——————+——+—–+———+—————-+
| emp_id | int(10) unsigned | | PRI | 0 | auto_increment |
| f_name | varchar(20) | YES | | NULL | |
| l_name | varchar(20) | YES | | NULL | |
| title | varchar(30) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
| yos | int(11) | YES | | NULL | |
| salary | int(11) | YES | | NULL | |
| perks | int(11) | YES | | NULL | |
| email | varchar(60) | YES | | NULL | |
+——–+——————+——+—–+———+—————-+
[Reply]
John Ward on March 25, 2009 at 1:31 am
<table>
<tr>
<th>field 1</th>
<th>filed 2</th>
<tr>
<?php while $row = mysql_fetch_array($query){
?>
<tr>
<td>
<?php echo $row['field1'];?>
</td>
<td>
<php echo $row['field2'];>
</td>
</tr>
<?php } ?>
</table>
[Reply]
Rod on March 25, 2009 at 11:55 am
Thanks Johne once again!
so that is how my code should looks like adding that to my tutorial?
mysql_error());
mysql_select_db (“necrose66″);
//build query
$query = mysql_query(“SELECT * FROM TestTable”);
// display results
?>
Name
Last
<?php while $row = mysql_fetch_array($query)) { echo ” ID: ” .$row['ID']. ” First Name: “.$row['FNAME']. ” Last Name: “.$row['LNAME'].” Phome: “.$row['PHON'].” “;}
?>
<?php echo $row['FNAME'];?>
[Reply]
jason1 on March 26, 2009 at 6:34 pm
I did this, but i get
No Database Selected. as my error.
What could the problem be? I have checked my PHPmyAdmin and the correct db_xxxxx is there, as is the table.
I checked the process log in phpmyadmin as well, and it shows database ‘none’ in the ‘Kill’ process.
[Reply]
Jay K on April 7, 2009 at 12:26 pm
Hi Guys, Great tutorial, however keep coming up with an error:
The following is for update.php but i have used filename newcustomer.php
Parse error: parse error on line 11 (begins with $query=”INSERT INTO)
[Reply]
Jay K on April 7, 2009 at 12:27 pm
Hi Guys, Great tutorial, however keep coming up with an error:
The following is for update.php but i have used filename newcustomer.php
Parse error: parse error on line 11 (begins with $query=”INSERT INTO)
[Reply]
Jay K on April 7, 2009 at 12:59 pm
Dont worry…. got it sorted!
[Reply]
Cory James on April 9, 2009 at 11:45 pm
Hi Guys, I need a little help.
I am trying to do something “simple” that is collect emails for an e-bulletin signup with the form post method in flash to write to a mysql database using php.
MYSQL version is 5.0.32
PHP Version is 5.2.6
I am using Action Script 2.0 in Flash
Here is my php:
And here is my actionscript:
function sendEmail(email)
{
var _loc1 = new LoadVars();
_loc1.email = email;
_loc1.onLoad = function (ok)
{
submit_btn.enabled = true;
};
_loc1.sendAndLoad(“http://realityla.com/form.php”, _loc1, “POST”);
gotoAndStop(2);
} // End of the function
stop ();
userPath = email_txt;
userPath.onSetFocus = function ()
{
userPath.text = “”;
};
submit_btn.onRelease = function ()
{
indexOfAt = email_txt.text.indexOf(“@”);
lastIndexOfDot = email_txt.text.lastIndexOf(“.”);
if (indexOfAt != -1 && lastIndexOfDot != -1)
{
if (lastIndexOfDot < indexOfAt)
{
message.text = “please verify your email.”;
}
else
{
var _loc2 = email_txt.text;
this.enabled = false;
sendEmail(_loc2);
} // end else if
}
else
{
message.text = “please enter correct email address”;
} // end else if
};
MYSQL version is 5.0.32
PHP Version is 5.2.6
I am using Action Script 2.0 in Flash
Maybe I am just tired, but it’s not working. Help please!!!
[Reply]
Cory James on April 9, 2009 at 11:48 pm
Sorry, here is my php, geesh….
Email Post
[Reply]
Cory James on April 9, 2009 at 11:49 pm
// Connects to your Database
$host=”mysql.realityla.com”; //Host Name
$username = ”coryjames”; //mysql user name
$password =”mark1045”; //mysql password $db_name =”tms” ;//database name $tbl_name =”employee” ; //Table Name
mysql_connect(”mysql.realityla.com”, “coryjames”, “mark1045”) or die(mysql_error());
mysql_select_db(”ebulletin”) or die(mysql_error());
$email = $_POST['email'];
$query =”INSERT INTO $email (email) VALUES (‘$email’)”;
$result = mysql_query($query) or die(’Error updating database’);
if($result){
echo “successfull”;
echo “”;
}
else {
echo “ERROR”;
}
mysql_close();
?>
[Reply]
leo on April 15, 2009 at 3:08 am
Hi
is there any way that i can create user by assigning privilleges by just clicking on the check boxes {check boxes for assigning privilleges}
i can create the database with textboxes but don’t have an idea about the check boxes
Help needed!
[Reply]
Daniel on April 16, 2009 at 10:28 am
I’m trying to write data and time using PHP but am not having any luck. This is the code I use:
$sql = “update contacts set ” . “address=’$address’, ” . “address2= ‘$address2′,” . “city= ‘$city’,” . “state= ‘$state’,” . “zip= ‘$zip’,” . “country= ‘$country’,” . “officephone= ‘$officephone’,” . “homephone= ‘$homephone’,” . “fax = ‘$fax’” . “whensubmitted= NOW(),” . “WHERE id LIKE ‘$recordid’ “;
I get an error with the whensubmitted= NOW() command.
Can anyone help?
[Reply]
John Ward on April 16, 2009 at 10:37 am
$sql = “update contacts set address=’$address’, address2= ‘$address2′, city= ‘$city’, state= ‘$state’, zip= ‘$zip’,country= ‘$country’, officephone= ‘$officephone’, homephone= ‘$homephone’, fax = ‘$fax’, whensubmitted= NOW() WHERE id LIKE ‘$recordid’ ;
there was no comma before when submit. Other than that I’m not sure, Post the error next.
[Reply]
soumya on May 29, 2009 at 12:29 pm
hi! everyone i have made a register page in php which will collect data in a form from user and store it in mysql db .My prob is that on clicking the submit button i get a blank page n a blank record is created in db .
i hav checked the code so many times but to no gud please help me iam a newbie.iam posting the code below:<?php
if(isset($_POST['user'])&&isset($_POST['pass']))
{
if(strlen($_POST['user'])<4)
echo”Username Must Be More Than 4 Characters.”;
elseif(strlen($_POST['pass'])<6)
echo”password must be more than 6 characters.”;
elseif($_POST['user']==$_POST['pass'])
echo”username and password cannot be same”;
else
{
include(“register.php”);
$firstname=$_POST['fname'];
$lastname=$_POST['lname'];
$username=mysql_real_escape_string($_POST['user']);
$password=$_POST['pass'];
$sex=$_POST['sex'];
$occupation=$_POST['occupation'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$phno=$_POST['phno'];
$emailid=$_POST['email'];
$comment=$_POST['comment'];
$sqlcheckforduplicate=”SELECT user FROM userinfo WHERE user=’$username’;”;
if(mysql_num_rows(mysql_query($sqlcheckforduplicate))==0)
{
$sqlreguser=”INSERT INTO userinfo(firstname,lastname,user,pass,sex,occupation,city,state,country,phno,eid,comment)VALUES(‘”.$firstname.”‘,’”.$lastname.”‘,’”.$username.”‘,’”.$password.”‘,’”.$sex.”‘,’”.$occupation.”‘,’”.$city.”‘,’”.$state.”‘,’”.$country.”‘,’”.$phno.”‘,’”.$emailid.”‘,’”.$comment.”‘);”);
$query= mysql_query($sqlreguser) or die(“error in query:$sqlreguser”.mysql_error());
$dbh=”register”;
mysql_close($dbh);
echo”$query”;
if($query)
{
echo”You are Registered and can now Login”;
$formusername=$username;
header(“location:home.php”);
}
}
else
{
echo”The username you have choosen is already taken.please try another one.”;
$formusername=$username;
}
}
}
else
{
echo”You could not be registered because of missing data.”;
}
?>
[Reply]
JC on June 17, 2009 at 6:08 am
This is the code that I have used:
However whenever I submit my form I always get the ‘error updating database’ message.
Anyone any ideas as to what I’m doing wrong?
Thanks in advance!!!!!!!
[Reply]
Maldave on July 8, 2009 at 4:57 pm
Hi,
I was wondering if there is a way to merge the php code and the form into 1 single php code ? The reason why I ask is that I want to put the update dabase funtion into a php block for smf/tinyportal. Is this doable ?
Thank you ^^
[Reply]
John Ward on July 8, 2009 at 7:20 pm
Maldave,
I’m not going to give you the code to do that, but I can give you the basic concept. You will learn more if you figure it out on your own. Basically you set the page up to check the variables you pass in the form (as post variables). So if they are not set, echo the form to enter the data else update the database with whatever that database is set to. Ok here is somewhat of an example. Let’s say the only variable you are pass is called $item.
//echo header info, etc
if (!isset($_POST['item'])){
echo “form to enter item. form action should point back to the same form and method should be post”;
}else{
//update database
}
[Reply]
Sunny on July 12, 2009 at 12:41 pm
Well !!!
Very good post …………….
Please please Please post it’s sequels too……….
[Reply]
Harman Malhi on August 6, 2009 at 10:49 am
Its of great use, this website really help me a lot.
i think every body should use this website for reference.
[Reply]
haritha on August 7, 2009 at 8:10 am
Hi,
I have a doubt in uploading image to database and also in retriew. Plz send any example or any reference site
Thank you
[Reply]
web on August 30, 2009 at 6:22 am
how do you insert date into mysql
[Reply]
NDEREBEZA PIERRE BENIT on September 9, 2009 at 4:16 am
very fine !
[Reply]
sajith on September 20, 2009 at 10:56 am
Thanks thanks a lot.
[Reply]
AJ on October 13, 2009 at 1:44 pm
Hi – I am totally new to PHP. I am taking an on-line class and have an assignment to create a form with a customer number and current meter reading. Once the user hits ‘submit’ I add this data to my table. Problem is I am getting a “Null values not allowe in column or variable” error. There is a date field and another text field I am not filling. Do I need to put something in the other two fields? Any help would be appreciated.
[Reply]
John Ward on October 14, 2009 at 1:21 am
Yes you need ot enter data in the other fields. Either that or change the database to allow null values in those columns.
[Reply]
RANIEL on October 24, 2009 at 5:37 am
the ECHO STATEMENT is WRONG………………BULL SHET!!!!!
this is the right ECHO statement just Copy and paste!
echo “Database Updated Width: “.$Fname.”,”.$Lname.”,”.$Phon;
I am also an idiot.
[Reply]
John Ward on October 24, 2009 at 2:27 pm
Raniel, there is nothing wrong with the original echo statement. All you did was add commas instead of a blank space. Congrats, you are awesome.
[Reply]
Paras on November 1, 2009 at 8:05 pm
It didnt worked out i m still struck in inserting data in sql table using php……..
[Reply]
Clay on November 12, 2009 at 4:22 am
F’ ya! I found everything I needed on this site tonight!
[Reply]
E. Tung'ande on November 19, 2009 at 12:47 pm
I have a table in the database which records the grades a student has scored. I need the rows from this table to be like columns on the output. Please help Iam stack.
The table is like this
Student_ID Course_code Assessment_grade End_of_semester Avg
So what i need is to take the Course_code field contents and output them as fields. and the averages to be under their respective courses.
for example
Student_ID ICT2301 ICT2302 ICT2303
BICTQW90 67 67 89
[Reply]
Writing to database? - x10Hosting Community on November 24, 2009 at 7:55 pm
[...] added for testing, but I cannot add new values into the database… I am following this tutorial: http://teamtutorials.com/web-develop…base-using-php Here is my code (Password removed of course): PHP Code: [...]
Simon on January 8, 2010 at 5:48 am
Fonud this really very usefull however when I add info and hit the submit button to test it comes up with “error updating database” Im guessing this is something to do with my database?
Can anyone help?
Thank you
[Reply]
tinaweena on January 8, 2010 at 11:47 am
i tried about 10 sites before i could figure out what was wrong with my code. your site helped me figure it out. thx
[Reply]
lori on January 14, 2010 at 12:49 am
i cannot figure out what im doing wrong here.. i keep getting error updating database.. please help
[Reply]
lori on January 14, 2010 at 12:50 am
// my code
//
[Reply]
lori on January 14, 2010 at 12:51 am
well code isnt posting the link is http://lddenterprise.com/test/test.php
[Reply]
nice on January 15, 2010 at 5:57 pm
have database update error too
[Reply]
Meanpoog on January 21, 2010 at 9:50 pm
Thanks very much!!
[Reply]
Amin Dad Shah on February 3, 2010 at 3:20 am
Dears,
i need the way how to insert images & video clips into mysql database & then to retrieve the images & video clips on an html page in separate tags. Please if someone can help me please help me out.
Thankx in advance.
[Reply]
mutitu on February 15, 2010 at 11:23 am
hi i am having a problem with retrieving data from the database using a php code will someone send me a trial code that i can use
[Reply]
RickyG on February 22, 2010 at 4:43 am
Thanks for the tutorial. Learned a lot! Next thing I want to learn is how to email the data from the form and at the same time put it in the database. Do you have a sample of this in php?
[Reply]
Arun on February 22, 2010 at 8:54 am
very helpfull….Thanks very much!!
[Reply]
RickyG on February 22, 2010 at 11:06 am
I’m trying to put make the date look like 2010/02/22. But this error keeps popping up.
Warning: Division by zero in /home3/oneworo2/public_html/update.php on line 5
Warning: Division by zero in /home3/oneworo2/public_html/update.php on line 5
Thank you Ricardo. One of our staff will contact you to finalize your booking on 201020. For inquiries, please note your booking reference number: . You can contact us at 00971 4 3372010.
This is the code I use.
<?php
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Phone = $_POST['Phone'];
$TourDate = $_POST['year'].”/”.$_POST_['month'].”/”.$_POST['day'];
$Adults = $_POST['Adults'];
$Children = $_POST['Children'];
$Tours = $_POST['Tours'];
$Others = $_POST['Others'];
$Comments = $_POST['Comments'];
[Reply]
Mike Maguire on February 22, 2010 at 7:16 pm
RickyG,
Not sure what you are doing wrong…How are you setting those values in the previous form? This code works; try this to see if it works for you;
//Creates the form for input
<form method=”post” action=”index.php”>
<input type=”text” name=”year”></input>
<input type=”text” name=”month”></input>
<input type=”text” name=”day”></input>
<input type=”submit” value=”submit”></input>
</form>
//echos the values if they are present
< ?php
if(isset($_POST['year']) && isset($_POST['month']) && isset($_POST['day']))
{
$TourDate = $_POST['year']."/".$_POST['month']."/".$_POST['day'];
echo $TourDate;
}
?>
[Reply]
budget on February 28, 2010 at 10:10 pm
thank you for sharing, this is just what i was looking for.
[Reply]
RickyG on March 3, 2010 at 4:14 am
Mike Maguire,
The date worked like a charm! Thanks!
Is it also possible for you to come up with a how-to article on checkboxes in webforms and how to put the data in mysql and display it using the echo command. i’m not really a programmer so I don’t know if the process I’m asking is correct.
Thanks for your articles!!!!
[Reply]
PHP Tutorials » Using PHP to update a database on March 4, 2010 at 6:12 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « Tutorials on March 4, 2010 at 11:54 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Jeremy on March 4, 2010 at 9:55 pm
Hi! This script is excatly what i need; however, it doesn’t work for me.. i get a 500 Internal Server Error!! (i replaced all my hosting/db info with ****) here’s my save_data.php code:
<?php
$TicketID = $_POST['TicketID'];
$TicketType = $_POST['TicketType'];
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$DateTicketBought = $_POST['DateTicketBought'];
$Location = $_POST['Location'];
$Events = $_POST['Events'];
$Arena = $_POST['Arena'];
mysqli_connect ("********", "*******", "********") or die ("Unable to connect, Sorry. Try again later.")
mysqli_select_db ("20010722009-1")
$query="INSERT INTO r2m_tickets (TicketID, FirstName, LastName, DateTicketBought, Location, Events, Arena)VALUES ('".$TicketID."', '".$FirstName."', '".$LastName."', '".$DateTicketBought."', '".$Location."', '".$Events."', '".$Arena."')";
mysqli_query($query) or die ('Error Updating Database. Try Again Later');
echo "Successful! Database updated with the following information: “.$TicketID.” “.$FirstName.” “.$LastName.” “.$DateTicketBought.” “.$Location.” “.$Events.” “.$Arena.”";
?>
Here’s my form.php code:
Update Database
Update info in Database ‘*********’, Table ‘******’
Ticket ID:
Ticket Type:
First Name:
Last Name:
Date Ticket Was Bought
Location:
Event(s):
Arena(s):
[Reply]
john on March 5, 2010 at 11:03 pm
Easy, but very complex to understand
[Reply]
JuineP on March 11, 2010 at 9:08 pm
this was very helpful thanks. straight forward for a beginer like me to follow
[Reply]
Using PHP to update a database || Tutorials on March 12, 2010 at 11:31 pm
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
PHP Code » Blog Archive » Using PHP to update a database on March 17, 2010 at 9:09 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
PHP Code : Using PHP to update a database on March 17, 2010 at 9:10 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « Computer Help Tutorials and Tips on March 17, 2010 at 9:11 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
phpcode » Using PHP to update a database on March 17, 2010 at 9:15 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Tutorials » Blog Archive » Using PHP to update a database on March 17, 2010 at 9:18 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Tutorials » Using PHP to update a database on March 17, 2010 at 9:25 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
programmingandcomputertutorials on March 17, 2010 at 9:36 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Computer Help Tutorials and Tips » Blog Archive » Using PHP to update a database on March 17, 2010 at 9:37 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database | PHP Code on March 17, 2010 at 9:41 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database | Tutorials on March 17, 2010 at 9:43 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Balıkesir Üniversitesi Tutorials on March 17, 2010 at 9:58 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
PHP Code » Using PHP to update a database on March 17, 2010 at 10:01 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
CW Connect — Blog — Using PHP to update a database on March 17, 2010 at 10:02 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « phpcode on March 17, 2010 at 10:03 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Programming and Computer Tutorials » Using PHP to update a database on March 17, 2010 at 10:11 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
» Using PHP to update a database on March 17, 2010 at 10:12 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database on March 17, 2010 at 10:13 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « computerhelptutorialsandtips on March 17, 2010 at 10:16 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
tutorials on March 17, 2010 at 10:24 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Learn Computer Tutorials » Using PHP to update a database on March 17, 2010 at 10:24 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
phpcode › Using PHP to update a database on March 17, 2010 at 10:26 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Tutorials » Using PHP to update a database :: iBlog on March 17, 2010 at 10:35 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Computer Help Tutorials and Tips » Using PHP to update a database on March 17, 2010 at 10:37 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « Programming and Computer Tutorials on March 17, 2010 at 10:52 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Booned — Blog — Using PHP to update a database on March 17, 2010 at 10:57 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « Learn Computer Tutorials on March 17, 2010 at 10:58 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Learn Computer Tutorials » Blog Archive » Using PHP to update a database on March 17, 2010 at 11:05 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
programmingandcomputertutorials » Blog Archive » Using PHP to update a database on March 17, 2010 at 11:06 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « computerhelp on March 17, 2010 at 11:12 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database – phpcode on March 17, 2010 at 11:15 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database @ PHP Code on March 17, 2010 at 11:28 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « learncomputertutorials on March 17, 2010 at 11:39 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
tutorials › Using PHP to update a database on March 17, 2010 at 11:40 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
phpcode » Blog Archive » Using PHP to update a database on March 17, 2010 at 11:42 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
» Using PHP to update a database tutorials on March 17, 2010 at 11:46 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Programming and Computer Tutorials » Blog Archive » Using PHP to update a database on March 17, 2010 at 11:47 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Tutorials » Archiwa bloga » Using PHP to update a database on March 17, 2010 at 1:10 pm
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database - Learn Computer Tutorials on March 17, 2010 at 1:27 pm
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
learncomputertutorials on March 19, 2010 at 2:54 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database on March 19, 2010 at 2:59 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Computer Help Tutorials and Tips » Blog Archive » Using PHP to update a database on March 19, 2010 at 2:59 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
programmingandcomputertutorials » Blog Archive » Using PHP to update a database on March 19, 2010 at 3:00 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « Tutorials on March 19, 2010 at 3:01 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « Learn Computer Tutorials on March 19, 2010 at 3:02 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Learn Computer Tutorials » Using PHP to update a database on March 19, 2010 at 3:02 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Balıkesir Üniversitesi Tutorials on March 19, 2010 at 3:03 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
tutorials on March 19, 2010 at 3:04 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « PHP Code on March 19, 2010 at 3:09 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
PHP Code » Using PHP to update a database :: iBlog on March 19, 2010 at 3:12 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
CW Connect — Blog — Using PHP to update a database on March 19, 2010 at 3:13 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Learn Computer Tutorials » Blog Archive » Using PHP to update a database on March 19, 2010 at 3:14 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Tutorials » Archiwa bloga » Using PHP to update a database on March 19, 2010 at 3:18 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Programming and Computer Tutorials - Using PHP to update a database on March 19, 2010 at 3:19 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
tutorials › Using PHP to update a database on March 19, 2010 at 3:25 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
phpcode » Using PHP to update a database on March 19, 2010 at 3:29 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Tutorials » Using PHP to update a database on March 19, 2010 at 3:32 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « phpcode on March 19, 2010 at 3:33 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « Computer Help Tutorials and Tips on March 19, 2010 at 3:35 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « learncomputertutorials on March 19, 2010 at 3:36 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
» Using PHP to update a database learncomputertutorials on March 19, 2010 at 3:38 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Booned — Blog — Using PHP to update a database on March 19, 2010 at 3:39 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Tutorials » Blog Archive » Using PHP to update a database on March 19, 2010 at 3:40 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Tutorials » Using PHP to update a database :: iBlog on March 19, 2010 at 3:42 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Programming and Computer Tutorials » Using PHP to update a database on March 19, 2010 at 3:50 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « Programming and Computer Tutorials on March 19, 2010 at 3:51 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Computer Help Tutorials and Tips » Using PHP to update a database on March 19, 2010 at 3:52 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
PHP Code » Using PHP to update a database on March 19, 2010 at 3:53 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
PHP Code : Using PHP to update a database on March 19, 2010 at 3:53 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database @ PHP Code on March 19, 2010 at 3:53 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
programmingandcomputertutorials on March 19, 2010 at 3:57 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
» Using PHP to update a database on March 19, 2010 at 4:01 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « computerhelptutorialsandtips on March 19, 2010 at 10:25 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Sacen on March 21, 2010 at 5:17 am
Hi Thanks for the tutorial.
I having the same problem alots of people having on the top. Enter data to the form return blank page and data not updating. Here is my code :
Please help, Thanks in advance
[Reply]
Sacen on March 21, 2010 at 5:18 am
[Reply]
mehmet on March 31, 2010 at 7:48 am
i can insert data in mysql by php but i want add two releation table with same id fore example user will have two table firstli he add information in a table from a form after that he can add any information in second table in different time.how can i use same id in two table andthats id can be unique for thats users?
[Reply]
Using PHP to update a database « PHP Code on March 31, 2010 at 8:12 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database « PHP Tutorials on March 31, 2010 at 12:40 pm
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Colin on March 31, 2010 at 4:01 pm
There is an error on line 11 and after a few hours i would like someone else help please
[Reply]
Colin on March 31, 2010 at 4:08 pm
[Reply]
Muhammad Akseer on April 1, 2010 at 5:30 am
It is vert helpful website for problem solving
thanks,
[Reply]
mehmet on April 1, 2010 at 9:39 am
anyone can help me to insert data in tables from different forms to different tables with same id?
[Reply]
rafael on April 3, 2010 at 4:17 am
Nice tutorial!
really helped me!!
thanks a lot!!
[Reply]
RickyG on April 4, 2010 at 2:45 am
I was trying to insert data from a form but it is not inserting the entry to the database.
Here’s the code
$Tours = $_POST['Tours'];
if (is_array($Tours)) {
foreach ($Tours as $key=>$val);
$content = $content . count($Tours);
for ($i=0;$i<count($Tours);$i++) {
$content = $content . "$Tours[$i]\n";
}
}
I made Tours a set with 4 selections but the entry is just blank. When i changed the type of Tours into a varchar, the word array is in the database not the selections made from the form.
I use the code above to display the selection and there's a number which appears before the selections like below. How do i get rid of the number?
4FirstChoice SecondChoice ThirdChoice FourthChoice
[Reply]
PHP Code » Blog Archive » Using PHP to update a database on April 5, 2010 at 8:18 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on PHP Tutorial: Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
Using PHP to update a database – Tutorials on April 6, 2010 at 3:26 am
[...] DBMS engines. It is very simple to insert data into MySQL databases. Check out this tutorial on Using PHP to insert data into a MySQL database. This tutorial is great for beginners. Once you get the hand of it you will want to look for a more [...]
rose on April 9, 2010 at 8:45 am
hello
i have a student regstration in groupes
i want to ensure if that student who write his information to insert is already exist in any groupe or not
if he exist display a form of the groupes to change his groupe to any group he wants
i need your help plz
[Reply]
Suchi on April 12, 2010 at 9:20 am
hi i did a form with select, which need to choose multiple options, but when i connect the php code to database the selected options were not been displayed…. the column itself is not accepted whereas othr fields get submitted. kindly help me to insert datas into database for php using tag, multiple options.I am a beginner.
[Reply]
Suchi on April 12, 2010 at 9:21 am
hi i did a form with select tag, which need to choose multiple options, but when i connect the php code to database the selected options were not been displayed…. the column itself is not accepted whereas othr fields get submitted. kindly help me to insert datas into database for php using tag, multiple options.I am a beginner.
[Reply]
Irtesam on April 17, 2010 at 3:30 pm
v nice posts…
its really helpful
[Reply]
jcalvin on April 20, 2010 at 9:16 pm
Hey, John.
I followed your tutorial, and everything was perfect, however, after clicking submit nothing appears in mySQL database. A new row appears as though their SHOULD be the data there, but the tables cells are empty.. WHAAAAATTTT could possibly be making me want to vomit??? haha.. help me out, man..
heres my source:
[Reply]
jcalvin on April 20, 2010 at 9:17 pm
actually, heres my source:
[Reply]
nood on April 20, 2010 at 11:03 pm
there is a bug in your code.. i find it unprofessional.. because after i reload the page after submitting the form, the page seems to re-enter the same data into my database.. can u give me a solution? without involving session token? Thank you.
[Reply]
John Ward Reply:
April 20th, 2010 at 11:25 pm
This is sample code for beginners and should not be used in production. We do not use any session tokens. You can check for referral that would stop the page on reload, but since you are such a professional you can figure that one out
[Reply]
Kazmi on April 28, 2010 at 2:31 am
line 8 : mysql_connect (“localhost”, “admin”,”admin321”) or die (‘I cannot connect to the database because: ‘ . mysql_error());
ERROR: Parse error: syntax error, unexpected T_STRING in /home/onlinedo/public_html/DBUpdate.php on line 8
Can anyone please figure out what that error points to.
Thanks in advance.
[Reply]
tech7 on May 3, 2010 at 9:49 pm
Hey, Thanks for this tutorial, it is just exactly what I needed. That doesn’t happen often. Thanks a lot!!!!
[Reply]
Adewale on May 6, 2010 at 8:12 am
Thank you for the guidelines above. It is indeed helpful.
[Reply]
Richard on May 7, 2010 at 7:28 pm
Hello. I am a noob with mySQL and PHP really and have found you tutorials extremely helpful.
However, i am having trouble with the update. I have checked and double checked the form and the update files and they all seem to be ok, and i am recieving an error message (Error updating database) but it doesn’t add any information to the database at all. I was wondering if there was anything basic i may have overlooked?
Thank you for your time.
[Reply]
Victor on May 29, 2010 at 4:25 am
thanks for all the high light in this page, plz i need a little favor in here.
i designed a website that has different forms in it, like the contact page, booking page, make reservation page.
i just only want to know if it requries creating different data base for all?
[Reply]
Halim on June 2, 2010 at 12:16 am
when i run the script, this error appear
“Error updating database”.How can i trace what type of error?
[Reply]
Juan Reply:
June 26th, 2010 at 9:08 pm
If you look at the part that talks about $query, it says:
mysql_query($query) or die(“Error updating database”);
That means ‘run the variable query, and if it doesn’t go well show the text Error updating database’. Therefore, your problem is with the database.
[Reply]
Juan Reply:
June 26th, 2010 at 9:09 pm
Sorry, I meant your problem is with the $query variable. Oops.
[Reply]
Cyberster on June 2, 2010 at 5:44 pm
thank you very much ! @John Ward
[Reply]
Rics on June 3, 2010 at 10:02 am
Hi, I have just started learning PHP and MYSQL.
created three comoboxes using createdays(), createyear(), createmoths() functions in PHP. It placed the combos well on the page. Now, how do I transfer the values selected by the user in dateofbirth field of MySql table.
[Reply]
Rics on June 3, 2010 at 10:05 am
This is the part of code i have used:
Day
Month
Year
[Reply]
Rics on June 3, 2010 at 10:07 am
Oops!!! I pasted the code here, and where has it vanished? But it is showing the required thing on my page.
[Reply]
Rics on June 3, 2010 at 11:10 am
The code is here…..
<?php
function createYears($start_year, $end_year, $id='year_select', $selected=null)
{
/*** the current year ***/
$selected = is_null($selected) ? date('Y') : $selected;
/*** range of years ***/
$r = range($start_year, $end_year);
/*** create the select ***/
$select = '’;
foreach( $r as $year )
{
$select .= “$year\n”;
}
$select .= ”;
return $select;
}
function createMonths($id=’month_select’, $selected=null)
{
/*** array of months ***/
$months = array(
1=>’January’,
2=>’February’,
3=>’March’,
4=>’April’,
5=>’May’,
6=>’June’,
7=>’July’,
8=>’August’,
9=>’September’,
10=>’October’,
11=>’November’,
12=>’December’);
/*** current month ***/
$selected = is_null($selected) ? date(‘m’) : $selected;
$select = ”.”\n”;
foreach($months as $key=>$mon)
{
$select .= “$mon\n”;
}
$select .= ”;
return $select;
}
function createDays($id=’day_select’, $selected=null)
{
/*** range of days ***/
$r = range(1, 31);
/*** current day ***/
$selected = is_null($selected) ? date(‘d’) : $selected;
$select = “\n”;
foreach ($r as $day)
{
$select .= “$day\n”;
}
$select .= ”;
return $select;
}
?>
DayMonthYear
[Reply]
tom on June 5, 2010 at 8:20 pm
LOOK ELSEWHERE THIS TUTORIAL WILL JUST WASTE YOUR TIME.
well another nice try but the update.php and form.php do not work at all. I get a blank page after submission, no error and records are not updated, or inserted. I just wasted two hours of my life coping your code from pictures none the less for failure. you sould at least have made the code so it could be copy and pasted so i would have only wasted 2 minutes, not two hours.
[Reply]
frank Reply:
June 18th, 2010 at 8:46 pm
If you learnt to communicate without spelling and grammar errors while you were wasting time at school, perhaps you would have less problems with your scripts. Stop blaming others for your own obvious inadequacies.
Keep on wasting!
[Reply]
Kevin Reply:
July 13th, 2010 at 10:52 am
I think it works perfectly well try checking if your values are being stored in the variables or may be the submit button is sending the data to the correct PHP page
or there would be some error in your code I was getting the blank page as well
but after this tutorial the values were being dtored in the database
[Reply]
Alam on June 26, 2010 at 5:10 am
Clarify explanation thanks for sharing
[Reply]
Juan on June 26, 2010 at 9:06 pm
I don’t see a need to make the ‘NULL’ part for the ID, because with every new entry to the db, the ID field is incremented by one regardless if the NULL is there or not.
Also, instead of making the query variable, you could just do:
mysql_query(“INSERT INTO TestTable (ID, FName, LName, PHON)VALUES (“$FName”, “$LName”, “$PHON”)”);
I’ve used it before with that kind of code [more of less], and it still functioned well.
[Reply]
jerrylee on July 9, 2010 at 12:25 am
I am able to insert into mysql okay, and I am able to email form results okay, but how do I do both when someone inserts their info. For instance, I have a client who I put a form on their site, they want to store the info, but also be alerted with an email when it comes in. I know this is simple, but being self taught, sometimes we miss the most simple things.
[Reply]
Kevin on July 12, 2010 at 7:10 pm
This tutorial was really usefull for me Thanks a lot, I really need it
[Reply]
Jatinder Singh on July 16, 2010 at 2:21 am
Thank you so Much , gr8 work
[Reply]
shoun on July 19, 2010 at 5:15 am
I have a query regarding license manager. I am developing site, in there when user fill payment form i want to give(send) license certificate imediatly through php code. can any one help me with example?
Thanks.
Shoun
[Reply]
mohammed on July 21, 2010 at 2:10 pm
i want you to tell me how to write equation into mysql code for example:
$query=”INSERT INTO r2m_tickets (TicketID, FirstName, LastName, DateTicketBought, Location, Events, Arena)VALUES (‘”.$TicketID.”‘, ‘”.$FirstName.”‘, ‘”.$LastName.”‘, ‘”.$DateTicketBought.”‘, ‘”.$Location.”‘, ‘”.$Events.”‘, ‘”.$Arena.”‘)”;
in the above code if i have field “total salary” calculated from many field how can i add this equation field?
[Reply]
Dave on July 23, 2010 at 7:07 pm
Hi I am fairly new to MySQL and Php, I would be greatful if you could advise as to why the following is not working.
I have my form named dataentryform.php, this form is made up of textfields and List/Menu fields, action is dataentryform.php.
My connect file is working fine
However my write to dbase script is not, could you point out where I have gone wrong please, script as below.
Thanks for any help.
[Reply]
Dave on July 23, 2010 at 7:09 pm
[Reply]
Dave on July 23, 2010 at 7:09 pm
It will not lt me post my script
[Reply]
kdkd on July 25, 2010 at 12:26 pm
Way to go idiot! Publish your tutorial using images, so we can’t copy/paste the code. Then we can all make mistakes with simple character omissions and never figure it out. What a wasted of time.
[Reply]
John Ward Reply:
July 29th, 2010 at 3:19 pm
I apologize for providing you with free help… Just so you know the newer tutorials have the source code available.
[Reply]
Polo on July 28, 2010 at 4:19 pm
When clicking submit button it just show me the code in another page, why?!?!?!?!
[Reply]
Adrian on July 30, 2010 at 4:38 am
I’m a student working on making a small application page, very basic, and I put this code in word for word in html, then made the separate file in php and uploaded both of them, when you click the ‘submit’ button I get this:
“Page not found
The page you requested was not found on this web server. This could be for a variety of reasons, including:
You followed a broken or out-of-date link.
You entered the URL for the page incorrectly.
The page no longer exists.
If you followed a broken link, please inform the owner of the referring page.
If you have any queries about this error, please e-mail webmaster@this.domain.”
I looked at my html tables and they are spot on and perfect, my php script is looking fine and I just can’t get it to work, help?
[Reply]
Narinder on July 31, 2010 at 5:33 am
hello sir I am new to php. I tried you code to save data and its working only there is one problem that in my database it automatically add blank row without pressing submit button. So please tell me how stop adding rows in runtime in Mysql.
[Reply]
Peter on August 10, 2010 at 8:38 am
Hi. Done the above, whats next in the series?? Very good tutorials
[Reply]
David on August 10, 2010 at 4:45 pm
Great tutorial, thank for sharing
[Reply]
RayChuks on August 14, 2010 at 6:36 pm
That’s a nice one John, thanks a lot.
[Reply]
Wilfred Cooray on August 16, 2010 at 6:13 am
I get error message in my update.php as follows
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/jmbecoo4/public_html/testmysql/update.php on line 10
Can you help me please.
My program is as follows.
Table editing
[Reply]
vijay on August 16, 2010 at 3:31 pm
hi im also face with the wilfred’s problem
this is my code
in my form i have create like this for example temperature
and this is the my php code ,it says syntax error in $query section
[Reply]
RAHUL on September 3, 2010 at 1:01 pm
i get this error PLEASE HELP !!!
Parse error: parse error, expecting `’,” or `’;” in C:\wamp\www\update.php on line 8
and here is my code:
[Reply]
RAHUL Reply:
September 3rd, 2010 at 1:01 pm
$query=”INSERT INTO testtable (FName, LName, PHON)VALUES (‘”.$FName.”‘,’”.$LNAme.”””.$PHON.”‘)”;
echo “Database Updated with: ” .Fname.” “.LName.” “.$PHON ;
[Reply]