Jump to content

Recommended Posts

I am submitting a form to a mysql database. I have four different tables in the database. I can submit the form to the database but the data for each table does not go in there own tables. I already have the tables in the database. Here is code. Can someone see anything I can do to get the data into there own tables? Thanks!

 

<html>

<head>

</head>

<body>

 

<?php

/* grabs the POST variables and puts them into variables that we can use */

$BuyerFirstName=$_POST['BuyerFirstName'];

$BuyerLastName=$_POST['BuyerLastName'];

$BuyerPhone=$_POST['BuyerPhone'];

$BuyerSSN=$_POST['BuyerSSN'];

$BuyerDOB=$_POST['BuyerDOB'];

$BuyerEmail=$_POST['BuyerEmail'];

$BuyerReEnterEmail=$_POST['BuyerReEnterEmail'];

$BuyerAddress=$_POST['BuyerAddress'];

$BuyerCity=$_POST['BuyerCity'];

$BuyerState=$_POST['BuyerState'];

$BuyerZip=$_POST['BuyerZip'];

$BuyerEmployerName=$_POST['BuyerEmployerName'];

$BuyerEmployerAddress=$_POST['BuyerEmployerAddress'];

$BuyerEmployerCity=$_POST['BuyerEmployerCity'];

$BuyerEmployerState=$_POST['BuyerEmployerState'];

$BuyerEmployerZip=$_POST['BuyerEmployerZip'];

$BuyerYearsEmployed=$_POST['BuyerYearsEmployed'];

$BuyerMonthlyIncome=$_POST['BuyerMonthlyIncome'];

$BuyerOtherIncome=$_POST['BuyerOtherIncome'];

$CoBuyerFirstName=$_POST['CoBuyerFirstName'];

$CoBuyerLastName=$_POST['CoBuyerLastName'];

$CoBuyerPhone=$_POST['CoBuyerPhone'];

$CoBuyerSSN=$_POST['CoBuyerSSN'];

$CoBuyerDOB=$_POST['CoBuyerDOB'];

$CoBuyerEmail=$_POST['CoBuyerEmail'];

$CoBuyerReEnterEmail=$_POST['CoBuyerReEnterEmail'];

$CoBuyerAddress=$_POST['CoBuyerAddress'];

$CoBuyerCity=$_POST['CoBuyerCity'];

$CoBuyerState=$_POST['CoBuyerState'];

$CoBuyerZip=$_POST['CoBuyerZip'];

$CoBuyerEmployerName=$_POST['CoBuyerEmployerName'];

$CoBuyerEmployerAddress=$_POST['CoBuyerEmployerAddress'];

$CoBuyerEmployerCity=$_POST['CoBuyerEmployerCity'];

$CoBuyerEmployerState=$_POST['CoBuyerEmployerState'];

$CoBuyerEmployerZip=$_POST['CoBuyerEmployerZip'];

$CoBuyerYearsEmployed=$_POST['CoBuyerYearsEmployed'];

$CoBuyerMonthlyIncome=$_POST['CoBuyerMonthlyIncome'];

$CoBuyerOtherIncome=$_POST['CoBuyerOtherIncome'];

$VehicleInfoYear=$_POST['VehicleInfoYear'];

$VehicleInfoMake=$_POST['VehicleInfoMake'];

$VehicleInfoModel=$_POST['VehicleInfoModel'];

$VehicleInfoColor=$_POST['VehicleInfoColor'];

$VehicleInfoEquipment=$_POST['VehicleInfoEquipment'];

$VehicleInfoComments=$_POST['VehicleInfoComments'];

$TradeInYear=$_POST['TradeInYear'];

$TradeInMake=$_POST['TradeInMake'];

$TradeInModel=$_POST['TradeInModel'];

$TradeInColor=$_POST['TradeInColor'];

$TradeInMiles=$_POST['TradeInMiles'];

$TradeInCondition=$_POST['TradeInCondition'];

$TradeInEquipment=$_POST['TradeInEquipment'];

 

//---------VALIDATION-------->

    if($BuyerFirstName){//----> CHECK input

        }

        else{

            $error.="Please, go back and fill out your first name<br>\n";//----> ERROR if no input

            }

 

    if($BuyerLastName){//----> CHECK input

        }

        else{

            $error.="Please, go back and fill out your last name<br>\n";//----> ERROR if no input

            }

 

    if($BuyerEmail){//----> CHECK input

        }

        else{

            $error.="Please, go back and fill out your e-mail address<br>\n";//----> ERROR if no input

            }

 

    if($BuyerReEnterEmail){//----> CHECK input

        }

        else{

            $error.="Please, go back and re-enter your e-mail address<br>\n";//----> ERROR if no input

            }

   

    if($BuyerSSN){//----> CHECK input

        }

        else{

            $error.="Please, go back and fill out your social security number<br>\n";//----> ERROR if no input

            }

 

      if($BuyerDOB){//----> CHECK input

        }

        else{

            $error.="Please, go back and fill out your date of birth<br>\n";//----> ERROR if no input

            }

 

    if($BuyerPhone){//----> CHECK input

        }

        else{

            $error.="Please, go back and fill out your phone number with area code<br>\n";//----> ERROR if no input

            }

 

    if($BuyerAddress){//----> CHECK input

        }

        else{

            $error.="Please, go back and fill out your mailing street address<br>\n";//----> ERROR if no input

            }

 

    if($BuyerCity){//----> CHECK input

        }

        else{

            $error.="Please, go back and fill out your city name<br>\n";//----> ERROR if no input

            }

 

    if($BuyerZip){//----> CHECK input

        }

        else{

            $error.="Please, go back and fill out your zip code<br>\n";//----> ERROR if no input

            }

 

    if($BuyerState){//----> CHECK input

        }

        else{

            $error.="Please, go back and select your state<br>\n";//----> ERROR if no input

            }

//-------->ERROR FREE??

    if($error==""){

        echo "Thank you for your Credit Application! A receipt of your submission will be e-mailed to you almost immediately.";

//----------------------------------

$mailContent="--------CONTACT--------\n"

            ."First Name: ".$BuyerFirstName."\n"

            ."Last Name: ".$BuyerLastName."\n"

            ."E-mail: ".$BuyerEmail."\n"

            ."Phone: ".$BuyerPhone."\n\n--------ADDRESS--------\n"

            ."Street Address: ".$address."\n"

            ."City: ".$city."\n"

            ."State: ".$state."\n"

            ."Zip Code: ".$zipCode."\n";

           

//----------------------------------

$toAddress="sales@donsautoupholstery.com"; /* change this! */

$subject="Consumer World Group Consumer Profile"; /* change this! */

$recipientSubject="MyWebSite.com's Contact Form"; /* change this! */

$receiptMessage = "Thank you ".$firstName." for inquiring about MyWebSite.com's Products!\n\n\nHere is what you submitted to us:\n\n"

            ."--------CONTACT--------\n"

            ."First Name: ".$BuyerFirstName."\n"

            ."Last Name: ".$BuyerLastName."\n"

            ."E-mail: ".$BuyerEmail."\n"

            ."Phone: ".$BuyerPhone."\n\n--------ADDRESS--------\n"

            ."Street Address: ".$address."\n"

            ."City: ".$city."\n"

            ."State: ".$state."\n"

            ."Zip Code: ".$zipCode."\n";

//----------------------------------

mail($email, $subject, $receiptMessage,"From:$toAddress");

//----------------------------------

mail($toAddress,$recipientSubject,$mailContent,"From:$email");

//--->echo $mailContent;

 

////////////////////////////////////////  CONNECT TO MYSQL DB  ////////////////////

// OPEN CONNECTION --->

$connection=mysql_connect("localhost","username", "password") or die("Unable to connect!"); /* change this! */

 

mysql_select_db("letst5_cwg") or die("Unable to select database!"); /* change this! */

 

//  EXECUTE QUERY --->

$query="INSERT INTO BuyerInfo (

              BuyerFirstName,

              BuyerLastName,

              BuyerPhone,

              BuyerSSN,

              BuyerDOB,

              BuyerEmail,

              BuyerReEnterEmail,

              BuyerAddress,

              BuyerCity,

              BuyerState,

              BuyerZip,

              BuyerEmployerName,

              BuyerEmployerAddress,

              BuyerEmployerCity,

              BuyerEmployerState,

              BuyerEmployerZip,

              BuyerYearsEmployed,

              BuyerMonthlyIncome,

              BuyerOtherIncome)

        VALUES(

            '".$BuyerFirstName."',

            '".$BuyerLastName."',

            '".$BuyerPhone."',

            '".$BuyerSSN."',

            '".$BuyerDOB."',

            '".$BuyerEmail."',

            '".$BuyerReEnterEmail."',

            '".$BuyerAddress."',

            '".$BuyerCity."',

            '".$BuyerState."',

            '".$BuyerZip."',

            '".$BuyerEmployerName."',

            '".$BuyerEmployerAddress."',

            '".$BuyerEmployerCity."',

            '".$BuyerEmployerState."',

            '".$BuyerEmployerZip."',

            '".$BuyerYearsEmployed."',

            '".$BuyerMonthlyIncome."',

            '".$BuyerOtherIncome."')";

 

$query="INSERT INTO CoBuyerInfo (

              CoBuyerFirstName,

              CoBuyerLastName,

              CoBuyerPhone,

              CoBuyerSSN,

              CoBuyerDOB,

              CoBuyerEmail,

              CoBuyerReEnterEmail,

              CoBuyerAddress,

              CoBuyerCity,

              CoBuyerState,

              CoBuyerZip,

              CoBuyerEmployerName,

              CoBuyerEmployerAddress,

              CoBuyerEmployerCity,

              CoBuyerEmployerState,

              CoBuyerEmployerZip,

              CoBuyerYearsEmployed,

              CoBuyerMonthlyIncome,

              CoBuyerOtherIncome)

        VALUES(

            '".$CoBuyerFirstName."',

            '".$CoBuyerLastName."',

            '".$CoBuyerPhone."',

            '".$CoBuyerSSN."',

            '".$CoBuyerDOB."',

            '".$CoBuyerEmail."',

            '".$CoBuyerReEnterEmail."',

            '".$CoBuyerAddress."',

            '".$CoBuyerCity."',

            '".$CoBuyerState."',

            '".$CoBuyerZip."',

            '".$CoBuyerEmployerName."',

            '".$CoBuyerEmployerAddress."',

            '".$CoBuyerEmployerCity."',

            '".$CoBuyerEmployerState."',

            '".$CoBuyerEmployerZip."',

            '".$CoBuyerYearsEmployed."',

            '".$CoBuyerMonthlyIncome."',

            '".$CoBuyerOtherIncome."')";

 

$query="INSERT INTO TradeInInfo (

              TradeInYear,

              TradeInMake,

              TradeInModel,

              TradeInColor,

              TradeInMiles,

              TradeInCondition,

              TradeInEquipment)

        VALUES(

            '".$TradeInYear."',

            '".$TradeInMake."',

            '".$TradeInModel."',

            '".$TradeInColor."',

            '".$TradeInMiles."',

            '".$TradeInCondition."',

            '".$TradeInEquipment."')";

 

$query="INSERT INTO VehicleInfo (

              VehicleInfoYear,

              VehicleInfoMake,

              VehicleInfoModel,

              VehicleInfoColor,

              VehicleInfoEquipment,

              VehicleInfoComments)

        VALUES(

            '".$VehicleInfoYear."',

            '".$VehicleInfoMake."',

            '".$VehicleInfoModel."',

            '".$VehicleInfoColor."',

            '".$VehicleInfoEquipment."',

            '".$VehicleInfoComments."')";

 

//////----->

$result=mysql_query($query) or die("Error in query:".mysql_error());

//if ($result)

    //echo mysql_affected_rows()." row inserted into the database effectively.";

 

//  CLOSE CONNECTION --->

mysql_close($connection);

 

///////////////////////////////////////////////////////////////////////////////////

        }

    else{

 

            print "Sorry, but the form cannot be sent until the fields indicated are filled out completely - <br>\n";

            print "$error<br>\n";

            print "<br>\n";

            print "<br>\n";

            print "Please use your \"Back\" button to return to the form to correct the omissions.  Thank you.<br>\n";

        }

 

?>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/64767-php-and-mysql-problem/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.