config.php
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'Persons';
?>
opendb.php
<?php
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname);
?>
closedb.php
<?php
mysql_close($conn);
?>
insert.php
<?php
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$age=$_POST['age'];
$phpto=$_POST['photo'];
include 'config.php';
include 'opendb.php';
$sql="INSERT INTO Persons (FirstName, LastName, Age, Photo)
VALUES('$firstname','$lastname','$age','$photo')";
if (!mysql_query($sql,$conn))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
include 'closedb.php';
?>
person.php
<html>
<body>
<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname" /><br/>
Lastname: <input type="text" name="lastname" /><br/>
Age: <input type="text" name="age" /><br/>
photo : <input type="file" name="photo"><br/>
<input type="submit" />
</form>
</body>
</html>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'Persons';
?>
opendb.php
<?php
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname);
?>
closedb.php
<?php
mysql_close($conn);
?>
insert.php
<?php
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$age=$_POST['age'];
$phpto=$_POST['photo'];
include 'config.php';
include 'opendb.php';
$sql="INSERT INTO Persons (FirstName, LastName, Age, Photo)
VALUES('$firstname','$lastname','$age','$photo')";
if (!mysql_query($sql,$conn))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
include 'closedb.php';
?>
person.php
<html>
<body>
<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname" /><br/>
Lastname: <input type="text" name="lastname" /><br/>
Age: <input type="text" name="age" /><br/>
photo : <input type="file" name="photo"><br/>
<input type="submit" />
</form>
</body>
</html>
No comments:
Post a Comment