473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

problem occured while inserting records from form into database

hi
i m facing problem while m trying to insert a record from form into database..the empty records will be inserted.values are not inserted in it....no error is shown..
here is the html coding.......
Expand|Select|Wrap|Line Numbers
  1. <body>
  2.  <form method="POST" action="p.php">
  3. Firstname: <input type="text" name="FirstName" size="30" /><BR>  <BR>
  4. <INPUT NAME="enter" TYPE="submit" VALUE="Enter">
  5. </form>
  6.  </body>
  7.  
here is the php coding.......

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. error_reporting(5);
  3. $con = mysql_connect("localhost","root","root");
  4. if (!$con)
  5.   {
  6.   die('Could not connect: ' . mysql_error());
  7.   }
  8.  
  9. mysql_select_db("mydb", $con);
  10. $sql="INSERT INTO stuinfo (FirstName) VALUES('$FirstName')";
  11.  
  12. if (!mysql_query($sql,$con))
  13. {
  14. die ('Error: '.mysql_error());
  15. echo "Error in Record Submission";
  16. }
  17. echo "New Record Added ";
  18. mysql_close($con) ;
  19.  
  20. ?>
Jan 22 '10 #1
1 1835
Atli
5,058 Expert 4TB
Hey.

To get a value from a HTML form, we use the $_GET or $_POST arrays, depending on what you set your form's method attribute. - So in your case, you would use the $_POST array.
Expand|Select|Wrap|Line Numbers
  1. $value = $_POST['value'];
  2. echo "Your value is: $value";
  3.  
In old versions of PHP you could have just used $value directly, without having to use $_POST, but for security reasons that functionality has been removed. (See Using Register Globals)


Also, be careful about using user input in your queries. If you just put it right into the query, you open yourself up for an SQL Injection attack.
You should always run user input though mysql_real_escape_string before putting it into a query.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $value = mysql_real_escape_string($_POST['value']);
  3. $sql = "INSERT INTO `tbl`(`value`) VALUES('$value')";
  4. $result = mysql_query($sql) or die(mysql_error());
  5. ?>
  6.  
Jan 22 '10 #2

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

Similar topics

7
by: middletree | last post by:
Posted this to Access group, meant to do it here: I have what I call a composite table. Can't recall what they called it in database class, but it's where you take the PK of two different...
8
by: Bruce Stockwell | last post by:
the setup: Webservice/WinClient application/SQL server. VS.Net (visual basic) winform wizard creates a simple form with load cancel cancelall and datagrid bound to a simple Dataset with one...
11
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
0
by: le0 | last post by:
Guys, I create a simple insertion in a database using DetailsView control, when i run this page and try to insert some data, the browser returns an error like this ...
3
by: Tom McQ | last post by:
Would somebody please have a look at the following piece of code for me? It is supposed to write a single record to one table in a database and a group of related records to another table. It worked...
3
by: veerapureddy | last post by:
Hai everybody, i like to insert some records into database from html form by entering data.my problem is how can i check , whether a record is available in database about a particular...
20
by: dav3 | last post by:
Alright folks I am in need of a lil guidance/assistance here. I have a program which reads in a txt file. This txt file contains lines of the form January 3, 2007, 85.8 Now each line of the txt...
6
by: ashes | last post by:
Hi, I am creating an ecommerce website using Microsoft Visual Studio, VB.Net and MS Access 2003. I am new to VB.Net When someone wants to register on the website, they fill out a form and the...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
1
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.