How to Sending Data to a Database php

How to Sending Data to a Database php

Save Data to a Database by php


The process of adding information to a table is similar
 to creating the table itself in terms of which functions
 you use, but the SQL query will be different.

$Query = "INSERT into $TableName values
 ('value1', 'value2', 'value3', etc.)";
mysql_db_query ("DatabaseName", $Query,
 $Link);


The query begins with INSERT into $TableName values. Then, within the parentheses, the value for each column should be put within single quotation marks with each value separated by a comma. There must be exactly as many values listed as there are columns in the table or else the query will not work! Then the query is submitted to the MySQL using mysql_db_query().



To demonstrate this, you'll use an HTML form that takes the user's first name, last name, E-mail address, and comments. The PHP script that handles this form will put the submitted information into the database.

To enter data into a database from an HTML form:

Create a new HTML document in your text editor that will create the HTML form.

Code the standard HTML header

<HTML><HEAD><TITLE>HTMLForm
 </TITLE><BODY>

Create a form.

<FORM ACTION="HandleForm.php"
 METHOD=POST>

Code for four text inputs.

First Name <INPUT TYPE=TEXT
 NAME="Array[FirstName]"
 SIZE=20><BR>
 Last Name <INPUT TYPE=TEXT
 NAME="Array[LastName]" SIZE=40><BR>
 E-mail Address <INPUT TYPE=TEXT
 NAME="Array[Email]" SIZE=60><BR>
 Comments <TEXTAREA
 NAME="Array[Comments]" ROWS=5
 COLS=40></TEXTAREA><BR>

You can make your form more attractive than this one but be sure to make note of your input variable names, which you'll need in the HandleForm.php page.

Add the submit button, close the form, and close the HTML page.

<INPUT TYPE=SUBMIT NAME="SUBMIT"
 VALUE="Submit!"
</FORM>
</BODY>
</HTML>

Save the page as form.html and upload it to the server.

Now you will write the HandleForm.php page, which takes the data generated by the form and puts it into the database.

Create a new PHP document in your text editor.







Related Posts:
  • php.ini Basics After you have compiled or installed PHP, you can still change its behavior with the php.ini file. On Linux/UNIX systems, the default location for this file is /usr/local/php/lib or the lib subdirectory of the PHP installati… Read More
  • File uploaded code-with-validation-PHP  PHP File uploaded code-with-IMAGE EXTENSION Validation <?php  session_start(); include "include/connection.php"; include "include/functions.php"; $userId=$_SESSION['userId']; if(!isse… Read More
  • PHP-simple Form Since you'll need a place for the user to enter a search query, let's begin by building a form to handle the user's input. Every form must have these basic components:The submission type defined with the met… Read More
  • PHP-Session Security Because a session may contain sensitive information, you need to treat the session as a possible security hole. Session security is necessary to create and implement a session. If someone is listening in or snoop… Read More
  • Advanced Database Job PHP PHP supports the following databases in one form or another: MySQL— www.mysql.com mSQL— www.hughes.com.au MS SQL (Microsoft SQL server; on Win32 systems only) filePro (Read only)— www.fptech.com Informix— (fr… Read More
  • Database Functions-PHP MySQL PostgreSQL MS SQL (Microsoft) Chances are good that you will have at least one of these databases available to you (very good since MySQL and PostgreSQL are available for free download). There are four… Read More
  • mysql_fetch_array-code-demo  Example-1  mysql_fetch_array  code demo <?php//error_reporting(0); session_start(); include "include/connection.php"; include "include/functions.php"; if(@$_REQUEST['act']=='… Read More
  • simple contactus page-php-code-demo  Simple contactus page-php-code-demo   with javascript validation <?php  session_start(); include "include/connection.php"; include "include/functions.php"; include "include/head… Read More
  • PHP Sessions The session_start( ) function is used to create a new session. A session is unique to the interaction between a browser and a web database application. If you use your browser to access several sites at once, you'll hav… Read More
  • php mvc tutorial for beginners-Model-View-Controller In most PHP web applications, you won’t have a strict MVC setup. In fact, it’s quite a lot of work to go full-on MVC with PHP. Getting a web project off the ground can be cumbersome and technically demanding, especially … Read More
  • php job in kolkata Learn web design & development with sitepoint tutorials, courses and books -  html5, css3, javascript, php, mobile app development, responsive web design.  In-depth tanking class/job analysis - tutorials and … Read More
  • PHP-Associative Array When you are building an ordinary array, the array function requires the data, but doesn't require you to specify the indices. It automatically generates the index of each element by grabbing the next available intege… Read More
  • PHP-Database-Basics-DB-Arrays Adding MySQL to PHP and combining the applications for your dynamic web site is a great start. But, it helps tremendously to structure your database right. We'll give you a solid understanding of both database de… Read More
  • PHP registration form-code-demo PHP registration form-code-demo <?php//error_reporting(0); session_start(); include "include/connection.php"; include "include/functions.php"; $fname=''; $lname=''; $dob=''; … Read More
  • php include file-dem-code PHP include file-dem-code <?php include "include/connection.php"; include "include/functions.php"; ?> -----------------------------> <?php  session_start();/* if(@$_REQUEST['userId']!='') … Read More