Jump to content

unable to insert data from form


xcoderx

Recommended Posts

whats wrong in this that i get error failed to insert?

 

<html>
<head>
<title>Add New MySQL User</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
if(isset($_POST['add']))
{
if(! $conn=mysql_connect("localhost", "root", "demo"))
    {
        die("Could't connect to database server..");
    }
    mysql_select_db("online_application",$conn) or die(mysql_error());

$user_name = $_POST['user_name'];
$password = $_POST['password'];
$f_name = $_POST['f_name'];
$l_name = $_POST['l_name'];
$email = $_POST['email'];
$date = $_POST['date'];

$query = "INSERT INTO users (user_name, password, f_name, l_name, email, date) VALUES ('$user_name', PASSWORD('$password'), '$f_name', '$l_name', '$email', '$date', 'Y', 'Y', 'Y')";
mysql_query($query) or die('Error, insert query failed');

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');

echo "New MySQL user added";
}
else
{
?>
<form method="POST">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr> 
<td width="100">Username</td>
<td><input name="user_name" type="text" id="user_name"></td>
</tr>
<tr> 
<td width="100">Password</td>
<td><input name="password" type="text" id="password"></td>
</tr>
<tr> 
<td width="100">First Name</td>
<td><input name="f_name" type="text" id="f_name"></td>
</tr>
<tr> 
<td width="100">Last Name</td>
<td><input name="l_name" type="text" id="l_name"></td>
</tr>
<tr> 
<td width="100">Email</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr> 
<td width="100">Date</td>
<td><input name="date" type="text" id="date"></td>
</tr>
<tr> 
<td width="100"> </td>
<td> </td>
</tr>
<tr> 
<td width="100"> </td>
<td><input name="add" type="submit" id="add" value="Add New User"></td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>

 

i am not trying to add new mysql user just trying to insert value from form to exsisting table in database

Link to comment
https://forums.phpfreaks.com/topic/202382-unable-to-insert-data-from-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.