i am new in php just 3 weeks. I have read PHP & Mysql by Kevin. I have wrote small code. But I could not insert into table. also i have attached php files. Please help me
here index.php
- Code: Select all
<?php
include'../config/dbconnection.php';
include_once '../inc/function.inc.php';
?>
<?php
include 'view.php';
// Add New Record
if (isset($_GET['add']))
{
$pageTitle = 'New Agent';
$action = 'addform';
$name = '';
$id = '';
$button = 'Add New Agent';
include 'form.php';
exit();
if (isset($_GET['addform']))
{
try
{
$sql = 'INSERT INTO agentmaster1 SET acode = :acode , aname = :aname';
$s = $pdo->prepare($sql);
$s->bindValue(':acode', $_POST['acode']);
$s->bindValue(':aname', $_POST['aname']);
$s->execute();
}
catch (PDOException $e)
{
$error = 'Error adding submitted agent.';
include '../inc/errormsg.inc.php';
exit();
}
header('Location: .');
exit();
}
}
?>
view.php
- Code: Select all
<?php
include '../templete/header.inc.php';
?>
<h1>Manage Agents</h1>
<p><a href="?add">Add new agent</a></p>
<?php
include '../templete/footer.php';
?>
form.php
- Code: Select all
<?php
include'../templete/header.inc.php';
include_once '../inc/function.inc.php';
?>
<h1><?php htmlout($pageTitle); ?></h1>
<form action="?<?php htmlout($action); ?>" method="post">
<div>
<p><label for="code">Code
<input type="text" name="acode" id="acode"></label>
</p>
</div>
<div>
<p>
<label for="name">Agent Name
<input type="text" name="aname" id="aname" ></label>
</p>
</div>
<div>
<p>
<input type="hidden" name="action" value="<?php htmlout($id); ?>">
<input type="submit" value="<?php htmlout($button); ?>">
</p>
</div>
</form>
<?php
include'../templete/footer.php';
?>



