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 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up help please what's worng this php code

    hi all friends
    i code in php for a multipage registration form like
    first page :first name, last name
    2nd pagearental details
    .
    .
    last will submit all data to mysql database
    the code is here by page but after last page that will submit data to database got a problem.
    the problem is


    Code:
    Error: You have an error in your SQL syntax; check the manual that  corresponds to your MySQL server version for the right syntax to use  near '='shalah',                 email_addres=  'uddin',                 membership_' at line 2
    here code for all page

    PHP Code:
    page1:
    <form method="post" action="page2.php">
    First Name:<input type="text" name="first_name" /><br>
    Last Name:<input type="text" name="last_name"  /><br>
    <input type="submit" name="submit" />
    </form> 

    page2:

    <?php
    $fname
    =$_POST['first_name'];
    $lname=$_POST['last_name'];
    ?>
    <html>
    <head></head>
    <body>
    <form method="post" action="page3.php">
    <input type="hidden" name="first_name" value="<?php echo $fname;?>" />
    <input type="hidden" name="last_name" value="<?php echo $lname;?>" />
    Education:<input type="text" name="education" /><br>
    School:<input type="text" name="school" /><br>
    <input type="submit" name="submit" />
    </form>
    </body>
    </html>

    page3:

    <?php
    $fname
    =$_POST['first_name'];
    $lname=$_POST['last_name'];
    $education=$_POST['education'];
    $school=$_POST['school'];
    ?>
    <html>
    <head></head>
    <body>
    <form method="post" action="page4.php">
    <input type="hidden" name="first_name" value="<?php echo $fname;?>" />
    <input type="hidden" name="last_name" value="<?php echo $lname;?>" />
    <input type="hidden" name="education" value="<?php echo $education;?>" />
    <input type="hidden" name="school" value="<?php echo $school;?>" />
    Experience:<input type="text" name="experience" /><br>
    <input type="submit" name="submit" />
    </form>
    </body>
    </html>

    page4:

    <?php
    $fname
    =$_POST['first_name'];
    $lname=$_POST['last_name'];
    $education=$_POST['education'];
    $school=$_POST['school'];
    $expe=$_POST['experiance'];
    //let's create the query
    $insert_query "insert into subscriptions (
                    name='$fname',
                    email_addres=  '$lname',
                    membership_type= '$education',
                    terms_and_conditions='$school',
                    name_on_card='$expe')"
    ;
    //let's run the query
    $connect=mysql_connect("localhost","root","");
    if(!
    $connect)
    {
    die(
    'Could not connect: ' mysql_error());
    }
        
    mysql_select_db("reg",$connect);
    if (!
    mysql_query($insert_query,$connect))
      {
      die(
    'Error: ' mysql_error());
      }
    echo 
    "1 record added";

    mysql_close($con);
    ?>
    please anybody help me to fix this.
    thanks in advance

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Like the error says, your SQL syntax is wrong. You can't insert values like that - follow this:
    http://www.w3schools.com/php/php_mysql_insert.asp


  •  

    Posting Permissions

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