Hi All..
While putting data into database from form if i refresh the php form a blank data will be added into database ... How can i remove that bug???
Here is my code.... -
-
<?php
-
$con = mysql_connect("localhost","root","rootwdp");
-
if (!$con)
-
{
-
die('Could not connect: ' . mysql_error());
-
}
-
mysql_select_db("sample", $con);
-
$sql="INSERT INTO usttable (usr_login,usr_password,usr_name,usr_email)
-
VALUE ('$_POST[fname]','$_POST[password]','$_POST[fname]','$_POST[email]')";
-
if (!mysql_query($sql,$con))
-
{
-
die('Error: ' . mysql_error());
-
}
-
mysql_close($con)
-
?>
-
4 1724
Apply validations before you insert the data to the database. -
<?php
-
-
//redirect to the form page if not submitted
-
if (!isset($_POST['submit']))
-
header ("Location:login_form.php");//which ever page is submitting to this script.
-
-
//if any of the parameter is missing.
-
if (!isset($_POST[fname]) || !isset($_POST[email]) || !isset($_POST[password]))
-
die ("Invalid parameters");
-
-
-
//---- your code ---
-
$con = mysql_connect("localhost","root","rootwdp");
-
if (!$con)
-
{
-
die('Could not connect: ' . mysql_error());
-
}
-
mysql_select_db("sample", $con);
-
$sql="INSERT INTO usttable (usr_login,usr_password,usr_name,usr_email)
-
VALUE ('$_POST[fname]','$_POST[password]','$_POST[fname]','$_POST[email]')";
-
if (!mysql_query($sql,$con))
-
{
-
die('Error: ' . mysql_error());
-
}
-
mysql_close($con)
-
?>
-
And make sure you add name="submit" to the submit button.
I would suggest you to do the same validations in PHP before you insert data, which you do in JavaScript onsubmit of form (if you are doing any).
thanks for the tips...
i have the same problem to.....
^_^
hi hsriat
thanks its working........
You are welcome... :)
I'm glad that one reply helped both of you.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: perplexed |
last post by:
How do you convert a user inputted date to a unix timestamp before
insterting it into your database? I have a form, with a textfield for
a date that the user inputs in the format mm-dd-yyyy and...
|
by: Murtix Van Basten |
last post by:
HI all,
I am trying to migrate a database from mysql to mssql2k. I use myODBC to
connect to mysql server to pull the database from DTS and insert in to sql
server. But in mysql server, there is...
|
by: Materialised |
last post by:
Hello everyone,
I am having a issue inserting values into a MYSQL table, and for the life of
me, I can figure out why. I know the connection is successful, however I am
getting errors.
The...
|
by: hfk0 |
last post by:
Hi,
I'm new to ASP.net, SQL Server and visual studio.net, and I'm having
problem inserting and storing data from a web form to a SQL database.
I created a simple ASP.NET web form, a simple SQL...
|
by: Nate12o6 |
last post by:
Mabee you guys can help me with this.
I have a form with enctype="multipart/form-data" that has a textarea in
it as well as file upload. The text area is for a description of the
file.
If...
|
by: farukcse |
last post by:
Dear Sir,
i am facing a encoding problem with MySQL data base and phpMyAdmin.
i developed a form . From wher user can insert the Car plate No. to the MySQL database.Both of the php file for...
|
by: Ravigandha |
last post by:
Hello everybody,
My question is how to insert special characters and symbols in Mysql5 database and how to retrieve them from database in php.
Here i am inserting some data from a form,by post...
|
by: len |
last post by:
Hi All
I have started a little pet project to learn python and MySQL. The
project involves figuring out all the combinations for a 5 number
lottery and storing the data in a MySQL file.
The...
|
by: Bunty |
last post by:
I want to insert values in the database.If i insert values one by one
then it works till 4 or 5 fields then after it gives error.In my
database there are more than 20 field.Pls help me.
|
by: liberty1 |
last post by:
Hi everyone. I appreciate your effort at helping newbies like me. I have the following problems and will appreciate urgent help.
PROBLEM NUMBER 1:
Using PHP and MySQL, I am able to upload...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
| |