Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

problem in insert command

General discussions related to php

Moderators: macek, egami, gesf

problem in insert command

Postby maideen » Mon Apr 07, 2014 2:42 am

hi
I am new in php. I could not insert the data into mysql table. and there is no error prompt Below is my code. Pls help me.

Code: Select all
<?php
include_once '../inc/header.php';
if (isset($_POST['submit']) && $_POST['submit']  != "" )
    {
        $name = $_POST["name"];
        $address = $_POST["address"];
        $tel = $_POST["tel"];
        $fax = $_POST["fax"];
        $email = $_POST["email"];
        $website = $_POST["website"];
        $type = $_POST["type"];   
   
        try
            {
                $sql="INSERT INTO bk_customer (id,name,address,tel,fax,email,type,website)
                      VALUES ('$name','$address','$tel','$fax','$email','$website','$type')";
                $result = mysqli_query($con,$sql) ;
               
           
            exit();
            }
        catch (Exception $ex)
            {
               echo $e->getMessage() . "\n";
               file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
               exit();           
            }
     }
mysqli_close($con);
?>
maideen
New php-forum User
New php-forum User
 
Posts: 27
Joined: Mon Mar 07, 2011 11:38 pm

Re: problem in insert command

Postby adicooldude » Mon Apr 07, 2014 10:25 am

hi,
1) check your database column names with the ones your using .
2) try echoing the insert query and manually run the query in database .
adicooldude
New php-forum User
New php-forum User
 
Posts: 10
Joined: Mon Apr 07, 2014 2:26 am

Re: problem in insert command

Postby maideen » Tue Apr 08, 2014 5:26 am

hi adicooldude

I have echoed. It is fine. But the below error

It is echoed. it is fine
500 Kinney 661.64 af blandit.mattis@nonleoVivamus.ca www.mujveqthwgg.oys supplier


Warning: mysqli_query(): Couldn't fetch mysqli in
C:\xampp\htdocs\bkstore\customer\add_data.php on line 59

pls help me.

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

Re: problem in insert command

Postby seandisanti » Tue Apr 08, 2014 7:08 pm

1, can do both of your checks by checking like this:
Code: Select all
if (!empty($_POST['submit']))
 


2, you're combining a couple of ideas that don't work well together, specifically mysqli library and pdo. A mysqli function will never result in a PDOException. Without seeing how you're creating your database connection, it would be impossible to tell you which way to proceed specific to your situation.

All of that aside, you're on the right track with PDO and should channel your effort into using the PDO approach whether you decide to go with a procedural or object oriented approach. http://www.youtube.com/watch?v=dF8hoPj-1bc is a quick video demonstrating an object oriented implementation of PDO by Jesse Boyer, the founder of jream.com. It's 11 minutes or so long, but will save you hours of troubleshooting.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP 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.