SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    error inserting values

    hi.
    i have written this code to add contact details but it says error inserting values.
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     
    <title>Add Contact Details</title>
    <style type="text/css">
    html,body {
                margin: 0px;
    }
    .text {
            color: green;
    }
    table{
                border: 1px solid black;
                border-collapse: collapse;
                background-color: #d6e5f4;
                width: 700px;

                
    }
    th{
                border: 1px solid black;
                padding: 5px 5px 5px 5px;
                width: 200px;
                font-size: 15px;
                font-family: Georgia, serif;
                color: brown;
                
    }
    td{
                border: 1px solid black;
                padding: 5px 5px 5px 15px;
                text-align: left;
    }
    table .iptd {
                  padding: 5px 5px 5px 5px;
                  border: 2px dashed black;
                  border-color: purple;
                  width: 250px;
    }
    .txtarea {
               border: 3px solid #cccccc;
               padding: 7px;
               font-family: Georgia, serif;
               color: black;
    }
    .img {
               border: 3px solid #cccccc;
               padding: 7px;
               width: 350px;
    }
    .error {
        font-size: 20px;
        color: brown;
    }
    .heading {
              font-family:  fantasy;
              font-size: 30px;
              text-align: center;
              color: #8B0000;      
              border: 2px solid black;
    }
    </style>
    </head>

    <body>
    <?php 
     
    if(isset($_POST['contactadd']))
       {
        
    $fname $_POST['fname'];
        
    $lname $_POST['lname'];
        
    $homead $_POST['homead'];
        
    $offad $_POST['offad'];
        
    $llno $_POST['llno'];
        
    $mobno1 $_POST['mobno1'];
        
    $mobno2 $_POST['mobno2'];
        
    $email $_POST['email'];
        
    $image $_FILES['image']['name'];
        
    $description $_POST['description'];
        
        
        if( (!empty(
    $fname)) && (!empty($lname)) &&(!empty($homead)) && (!empty($offad)) && (!empty($llno)) && 
           (!empty(
    $mobno1)) && (!empty($mobno2)) && (!empty($email)) && (!empty($image)) && (!empty($description)))
           
           
                           {
                             
    $dbc mysqli_connect('localhost','username','password','addcontact')
                                     or die(
    'Error Connecting to Mysql');
                                     
                             
    $query "INSERT INTO contactlist VALUES('$fname','$lname','$homead',$offad','$llno','$mobno1','$mobno2','$email','$image','$description')";
                             
    mysqli_query($dbc,$query)
                               or die(
    'Error Inserting Values');
                             
    mysqli_close($dbc);
                           }
        else
           {
            echo 
    '<center><p class="error">Some of the data entered is wrong or incomplete</p></center>';
           }
       }
    ?>
       <center>
         <form action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" method="post"> 
                <table>
                    <tr>
                       <td class="heading"><b>ADD CONTACT TO DATABASE</b></td>
                    </tr>
                </table>
              <table>
                    <tr>
                       <th><em>FIRST NAME:</em></th>
                       <td><input type="text" name="fname" class="iptd" value="<?php if(!empty($fname)) echo $fname?>" /></td>
                    </tr>
                    <tr>
                       <th><em>LAST NAME:</em></th>
                       <td><input type="text" name="lname" class="iptd"  value="<?php if(!empty($lname)) echo $lname?>" /></td>
                    </tr>
                    <tr>
                      <th rowspan="2"><em>ADDRESS</em></th>
                       <td class="text">RESIDENCE:<br /><textarea  class="txtarea" cols="60" rows="18" name="homead"><?php if(!empty($homead)) echo $homead?></textarea></td>
                    </tr>
                    <tr>
                      <td class="text">OFFICE:<br /><textarea  class="txtarea" cols="60" rows="18" name="offad"><?php if(!empty($offad)) echo $offad?></textarea></td>
                    </tr>
                    <tr>
                      <th rowspan="3"><em>TELEPHONE NO'S:</em></th>
                       <td class="text">LANDLINE:<br /><input type="text"  class="iptd" name="llno" value="<?php if(!empty($llno)) echo $llno?>" /></td>
                    </tr>
                    <tr>
                       <td class="text">MOBILE NO 1:<br /><input type="text"  class="iptd" name="mobno1" value="<?php if(!empty($mobno1)) echo $mobno1?>" /></td>
                    </tr>
                    <tr>
                       <td class="text">MOBILE NO 2:<br /><input type="text"  class="iptd" name="mobno2" value="<?php if(!empty($mobno2)) echo $mobno2?>" /></td>
                    </tr>
                    <tr>
                      <th><em>EMAIL-ID:</em></th>
                      <td><input type="text" name="email" class="iptd" value="<?php if(!empty($email)) echo $email?>" /></td>
                    </tr>
                    <tr>
                       <th><em>UPLOAD IMAGE:</em></th>
                       <td><input type="file" class="img" name="image" alt="picture" /></td>
                    </tr>
                    <tr>
                      <th><em>RELATION<br /></em>(OR)<br /><em>DESCRIPTION:</em><br />( Say a Few words about this person)</th>
                      <td><textarea rows="12" cols="40" name="description" class="txtarea"><?php if(!empty($description)) echo $description?></textarea></td>
                    </tr>
                    <tr>
                      <th></th>
                      <td><input type="submit" name="contactadd" value="ADD CONTACT" /></td>
                    </tr>
                    
              </table>
              
         
         
         
         </form>
       </center>


    </body>
    </html>

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by narendrav View Post
    it says error inserting values.
    And that isn't very useful, is it?
    Just for debugging purposes, change this line
    PHP Code:
    mysqli_query($dbc,$query)
                               or die(
    'Error Inserting Values'); 
    in
    PHP Code:
    mysqli_query($dbc,$query)
                               or die(
    'Error Inserting Values ' mysqli_error() . ' in query $query'); 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •