Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server HTML
Hi,
 
I have an html form that accepts user info(Name, Contact Number) I need to store them into the sql server table.
 
How can I store them? There is no code behind,no asp page, nothing. Just an html page and an sql server.
 
this is the HTML form.
 
I would like to know whether php instead of html is useful for this or not.
 
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="insert_ac.html">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="3">Insert Data Into mySQL Database </td>
</tr>
<tr>
<td width="71">Name</td>
<td width="6">:</td>
<td width="301"><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Lastname</td>
<td>:</td>
<td><input name="lastname" type="text" id="lastname"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
Posted 27-Nov-12 4:57am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

There is no either/or here: to do what you want, you must use both HTML and PHP.
 
The primary function of HTML is to structure a document and describe how it will be displayed. A secondary function is to allow the user to input data, which HTML will deliver back to the server. It cannot actually do anything with the data.
 
Storing, retrieving or otherwise manipulating data requires a programming language of some kind. The choice of language is depends on whether you want to do your processing in the browser (which is typically done with JavaScript) or on a remote server (where you can use PHP, ASP, C#, VB or some other language.) To provide feedback, however, you must be able to generate an HTML document which is delivered to and displayed by the user's browser.
  Permalink  
Comments
Member 9380535 at 27-Nov-12 10:27am
   
I used this html/php pages.
(insert.php)
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="insert_ac.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="3">Insert Data Into mySQL Database </td>
</tr>
<tr>
<td width="71">Name</td>
<td width="6">:</td>
<td width="301"><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Lastname</td>
<td>:</td>
<td><input name="lastname" type="text" id="lastname"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
 
and (insert_ac.php) ....
 

 
$host="ert"; // Host name
$username="remote"; // Mysql username
$password="password"; // Mysql password
$db_name="test"; // Database name
$tbl_name="test_mysql"; // Table name
 
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
 
// Get values from form
$name=$_POST['name'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
 
// Insert data into mysql
$sql="INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')";
$result=mysql_query($sql);
 
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "Back to main page";
}
else {
echo "ERROR";
}
?>
 
// close connection
mysql_close();
?>
 

Gives some error.( can't store data into sql)
Member 9380535 at 27-Nov-12 10:28am
   
(insert_ac.php)
 
 
$host="ert"; // Host name
$username="remote"; // Mysql username
$password="password"; // Mysql password
$db_name="test"; // Database name
$tbl_name="test_mysql"; // Table name
 
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
 
// Get values from form
$name=$_POST['name'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
 
// Insert data into mysql
$sql="INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')";
$result=mysql_query($sql);
 
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "Back to main page";
}
else {
echo "ERROR";
}
?>
 
// close connection
mysql_close();
?>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 285
1 Zoltán Zörgő 170
2 OriginalGriff 140
3 Sergey Alexandrovich Kryukov 120
4 Maciej Los 115
0 OriginalGriff 7,740
1 DamithSL 5,769
2 Sergey Alexandrovich Kryukov 5,424
3 Maciej Los 5,076
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100