Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

insert problem

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

insert problem

Postby maideen » Wed Feb 27, 2013 4:29 pm

hi,
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';
?>

Attachments
sp4all.rar
(18.59 KiB) Downloaded 19 times
maideen
New php-forum User
New php-forum User
 
Posts: 27
Joined: Mon Mar 07, 2011 11:38 pm

Re: insert problem

Postby seandisanti » Wed Feb 27, 2013 4:32 pm

you're preparing your statement as $sql, but exec'ing as $s
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: insert problem

Postby maideen » Wed Feb 27, 2013 4:58 pm

hi sean

i have converted $sql to $s

Pls see this
$sql = 'INSERT INTO agentmaster1 SET acode = :acode , aname = :aname';
$s = $pdo->prepare($sql);

i have attached previously all my file. Pls look into where i did wrong.

pls help me
:help:
maideen
New php-forum User
New php-forum User
 
Posts: 27
Joined: Mon Mar 07, 2011 11:38 pm

Re: insert problem

Postby seandisanti » Thu Feb 28, 2013 1:07 pm

are you getting any errors? have you tried echoing the completed query and then running the query through phpmyadmin, or directly through mysql?
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: insert problem

Postby maideen » Fri Mar 01, 2013 12:47 am

hi Sean

I did not any error on running. But I could not insert.

I have already attached my whole code.

Pls check and let me know..

maideen
maideen
New php-forum User
New php-forum User
 
Posts: 27
Joined: Mon Mar 07, 2011 11:38 pm

Re: insert problem

Postby seandisanti » Fri Mar 01, 2013 8:33 am

i don't have a copy of your database, so your insert statement will fail absolutely every time i run it. make sure to view source on the page after attempting to insert also, sometimes when errors or exceptions are not caught, you'll see them inserted into tags where the output of your function calls would have gone had they been successful. As far as going through your project to try to identify your issue without any kind of error message or database to recreate it, i'll have to pass. I am at work trying to help people between my own tasks
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.