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 to the CF scene
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problems getting more then one record inserted in DB

    I have a script to insert data I get from a form on my website that users fill out. The script works fine the first time and then when I go to submit a second form(form a different person) the data is not inserted. It will only let me enter one record. I have created a couple databases under the same user name and the work fine. This database has 10 fields and checks to make sure 2 of them are unique (name and email). I am lost as I have been killing myself over this for two days. Here is the script I am using. Can anyone please help me?

    PHP Code:
    <?php

    $host
    ="localhost"// Host name 
    $username="*********";MySQL username
    $password
    ="*********"MySQL password
    $db_name
    ="********info"// Database name 
    $tbl_name="reg"// Table name

    // Connect to server and select database.
    mysql_connect("$host""$username""$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");

    // Get values from form 
    $name=$_POST['fullname'];
    $email=$_POST['email'];
    $address=$_POST['address'];
    $city=$_POST['city'];
    $postalcode=$_POST['postalcode'];
    $phone=$_POST['phonenum'];
    $signup=$_POST['signup'];
    $position=$_POST['position'];
    $hockeylevel=$_POST['hockeylevel'];

    //Check to see if values already exist in the database
    $checkmysql_query("SELECT FullName FROM $tbl_name WHERE FullName = '$name'");
    $returned mysql_fetch_array($check);
    if(!empty(
    $returned))    {
                            
    header("Location: error-nameexists.php");
                            
    mysql_close();
                            Die();
                            }
                            else     {
                                    
    //Check to see if email exists in the database
                                    
    $check mysql_query("SELECT Email FROM $tbl_name WHERE Email = '$email'");
                                    
    $returned mysql_fetch_array($check);
                                    if(!empty(
    $returned))    {
                                                            
    header("Location: error-emailexists.php");
                                                            
    mysql_close();
                                                            Die();
                                                            }
                                                            else     {
                                                                    
    // Insert data into mysql 
                                                                    
    $sql="INSERT INTO $tbl_name(FullName, Email, Address, City, PhoneNum, PostalCode, SignUp, Position, HockeyLevel)VALUES('$name', '$email', '$address', '$city', '$phone', '$postalcode', '$signup', '$position', '$hockeylevel')";
                                                                    
    $result=mysql_query($sql);

                                                                    
    // if successfully insert data into database, displays message. 
                                                                    
    if($result)    {
                                                                                
                                                                                
    header("Location: reg-submit.php");
                                                                                
    mysql_close();
                                                                                Die();
                                                                                
                                                                                }

                                                                                else     {
                                                                                        echo 
    "ERROR";
                                                                                        }
                                                                    }
                                    }

    // close connection 
    mysql_close();
    ?>
    The error I get is the one you see at the bottom (echo "ERROR" )

    Like I said it works perfect this first time. I am using phpmyAdmin for the DB management and am new it. Anything you can think of why it does this would help. I have also tested it to see if it is connecting to the DB and it does because if I enter a name or email that is already in the DB(the only one there) then I am sent to my error-nameexists.php page. Hope this gives you a little more info.

    Nick

  • #2
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In the top of the code I submit where I declare the connection variables I have this:
    $host="localhost"; // Host name
    $username="*********";MySQL username
    $password="*********"; MySQL password
    $db_name="********info"; // Database name
    $tbl_name="reg"; // Table name
    and it actually is:

    PHP Code:
    $host="localhost"// Host name  
    $username="*********";//MySQL username 
    $password="*********"//MySQL password 
    $db_name="********info"// Database name  
    $tbl_name="reg"// Table name 
    I just erased them when I was staring my password and user info.

    Nick


  •  

    Posting Permissions

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