Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2011
    Posts
    119
    Thanks
    43
    Thanked 0 Times in 0 Posts

    Inserting Data into database by form submission

    Hi
    The following code is not working & I am getting this error-
    Parse error: syntax error, unexpected T_STRING in D:\wamp\www\1\form2.php on line 20
    PHP Code:
    <?php
    $host
    ="localhost";
    $user="root";
    $password="";
    $con=mysql_connect($host,$user,$password);
    if(!
    $con)
    {
    die(
    'Error:'.mysql_error());
    }
    mysql_select_db('emp',$con)
    or die(
    'Error'.mysql_error());

    if(
    $_POST['sub']=="Insert")
    {
     
    $name=$_POST['nm'];
     
    $address=$_POST['tar'];
     
    $gender=$_POST['gen'];
     
    $location=$_POST['loc'];
    }
     
    $ins=INSERT INTO 'emp'.'record'('id','name','address','gender','location'VALUES (NULL,"$name","$address","$gender","$location");

    $result=mysql_query($ins,$con);
     if(!
    $result)
        {
         die(
    'Error:'.mysql_error());
        }
        
    ?>
    FYI,My form page code is as follows-
    Code:
    <HTML>
    <HEAD>
    	<TITLE>form1.php</TITLE>
    </HEAD>
    <BODY>
    <h1 align="center">Employee Details</h1>
    <table align="center"  border=1 width=400 height=500>
    
    <form method="POST" action="form2.php">
    
    <tr>
    <td>Name:-</td> 
    <td><input type=text name="nm" ></td>
    </tr>
    
    <tr>
    <td>Address:-</td>
    <td><textarea cols="16" rows="4" name="tar"  ></textarea></td>
    </tr>
    
    <tr>
    <td>Gender:-</td> 
    <td>
    <input type="radio" name="gen" value="Male">Male <input type="radio" name="gen"  value="Female" >Female
    </td>
    </tr>
    
    <tr>
    <td>Location:-</td>
    <td>&nbsp;&nbsp;<select name="loc">
    <option value="NYork">New York</option>
    <option value="New Jersey">New Jersey</option>
    <option value="London">London</option>
    </select>
    </td>
    </tr>
    
    <tr >
    <td>
    <INPUT  TYPE="submit"  name="sub" value="Insert">
    </td>
    </tr>
    </TABLE>
    </FORM>
    </BODY>
    </HTML>
    Please tell me where is the mistake?

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,417
    Thanks
    68
    Thanked 102 Times in 101 Posts
    It's something on the insert $ins line. I believe its a problem with the concatation, with the table names. But try this.

    PHP Code:
    $ins=("INSERT INTO 'emp'.'record'('id','name','address','gender','location') VALUES (NULL,"$name","$address","$gender","$location""); 
    Been a sign maker for 7 years. My business:
    American Made Signs

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    PHP Code:
    $ins="INSERT INTO emp.record(name,address,gender,location) VALUES ('$name','$address','$gender','$location')"
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    ippo (05-04-2012)

  • #4
    Regular Coder
    Join Date
    Jun 2011
    Posts
    119
    Thanks
    43
    Thanked 0 Times in 0 Posts
    Thanks @ abdura.The problem is solved


  •  

    Posting Permissions

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