...

View Full Version : Insert problem



Kev0121
03-13-2009, 01:09 AM
Trying to insert data into my database from a submitted form

heres my code



<?php
include 'connection.php';
?>
<html>
<head>
<title> Insert Data Form </title>
</head>
<body>
<form name="insert_data" action="">
<table>
<tr>
<td> Name : <input type="text" name="name" /> </td>
</tr>
<tr>
<td> Age : <input type="text" name="age" /> </td>
</tr>
<tr>
<td> City : <input type="text" name="city" /> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Done" /> </td>
</table>
</form>
</body>

<?php
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$age = $_POST['age'];
$city = $_POST['city'];

$insert = "INSERT INTO `test`
(
`name`,
`age`,
`city`
) VALUES(
'$name',
'$age',
'$city')";

$insert_data = mysql_query($insert) or die(mysql_erorr());
}

?>


Kevin

rangana
03-13-2009, 03:43 AM
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$age = $_POST['age'];
$city = $_POST['city'];

$insert = "INSERT INTO test (name,age,city) VALUES('$name','$age','$city')";

$insert_data = mysql_query($insert) or die(mysql_erorr());
}

_Aerospace_Eng_
03-13-2009, 05:31 AM
Okay so what is happening? Are you getting errors or is it just a blank page? Your query can be on more than one line if you like. It doesn't need to be on one line. Spelling does go a long way though.


$insert_data = mysql_query($insert) or die(mysql_erorr());

Also I suggest you look into preventing mysql injection.

Kev0121
03-13-2009, 03:56 PM
I found out the reason, my form was missing a method="post" thanks anyway

Kevin



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum