0

this is my code for form i want the data entered by user should be saved in mysql...using wamp..any solution plzz..please rewrite the code and paste it. ................................................................................

</head>
<body>

<form action="form.php" method="post">

    Project_Manager:<input type="text" name="ProjectManager">
<br />

    Email_Address:<input type="text" name="EmailAddress">
<br />

    Company_Name:<input type="text" name="CompanyName">
<br />

    Company_Street_Address:<input type="text" name="CompanyStreetAddress">
<br />

    Company_Suit:<input type="text" name="CompanySuit">
<br />

    City:<input type="text" name="City">
<br />

    State:<input type="text" name="State">
<br />

    Zip_code:<input type="text" name="Zipcode">
<br />

    Company_Phone:<input type="text" name="CompanyPhone">
<br />

    Billing_Name:<input type="text" name="BillingName">
<br />

    Billing_Company_Street_Address:<input type="text" name="BillingCompanyStreetAddress">
<br />

    Billing_Company_Suite:<input type="text" name="BillingCompanySuite">
<br />

    Billing_City:<input type="text" name="BillingCity">
<br />

    Billing_State:<input type="text" name="BillingState">
<br />

    Billing_Zip_Code:<input type="text" name="BillingZipCode">
<br />

    Billing_Phone:<input type="text" name="BillingPhone">
<br />


    <input type="submit" value="submit">

    </form>



<?php

    if(isset($_POST['submit'])){

    $con = mysql_connect("localhost","root","");
    if(!$con){
         die('Could not connect: ' . mysql_error());
    }

mysql_select_db("ecc1",$con);   


$sql = "INSERT INTO client(
    Project_Manager,
    Email_Address, 
    Company_Name, 
    Company_Street_Address, 
    Company_Suit, 
    City, 
    State, 
    Zip_code, 
    Company_Phone, 
    Billing_Name, 
    Billing_Company_Street_Address, 
    Billing_Company_Suite, 
    Billing_City, 
    Billing_State, 
    Billing_Zip_Code, 
    Billing_Phone
)
    VALUES( '$_POST[ProjectManager]',
            '$_POST[EmailAddress]',
            '$_POST[CompanyName]',
            '$_POST[CompanyStreetAddress]',
            '$_POST[CompanySuit]',
            '$_POST[City]',
            '$_POST[State]',
            '$_POST[Zipcode]',
            '$_POST[CompanyPhone]',
            '$_POST[BillingName]',
            '$_POST[BillingCompanyStreetAddress]',
            '$_POST[BillingCompanySuite]',
            '$_POST[BillingCity ]',
            '$_POST[BillingState]',
            '$_POST[BillingZipCode]',
            '$_POST[BillingPhone]',
            )";

mysql_query($sql,$con);
mysql_close($con);
    }

?>

</body>

</html>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Jeet Patel
  • 11
  • 6

3 Answers3

0

Most likely your test for if the form has submitted is failing:

if(isset($_POST['submit'])){
    // this is probably false
}

if you added name="submit" to your submit button you might get the result you expect.

<input type="submit" name="submit" value="submit">
Boice
  • 156
  • 1
  • 7
  • You should attempt to find out where it is not working by printing to the page at certain points. after if(isset($_POST['submit'])){ echo "Form Submitted."; and then after the query echo mysql_error(); this may help give you an idea of where it is failing, then we can better answer your question or you might answer it yourself that way... – Boice Mar 19 '17 at 06:08
0

Well, for starters you're using the deprecated mysql_* extension, which will no longer work on new versions of PHP, second of all, you're using MySQLi standards when querying the databse.

Your whole script should look like this, instead:

HTML:

<input type="submit" value="true" name="submit"> <!-- set the name of submit button to "submit" so your if statement works !-->

PHP:

$conn = new mysqli('localhost', 'root', '', 'ecc1'); // use mysqli instead of mysql. mysql is deprecated

if(isset($_POST['submit'])){
    $sql = "INSERT INTO client(
        Project_Manager,
        Email_Address, 
        Company_Name, 
        Company_Street_Address, 
        Company_Suit, 
        City, 
        State, 
        Zip_code, 
        Company_Phone, 
        Billing_Name, 
        Billing_Company_Street_Address, 
        Billing_Company_Suite, 
        Billing_City, 
        Billing_State, 
        Billing_Zip_Code, 
        Billing_Phone) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; // your sql
    $stmt = $conn->prepare($sql); // to protect against sql injection
    $stmt->bind_param("ssssssiisssssii", $_POST['ProjectManager'], $_POST'[EmailAddress'], $_POST['CompanyName'], $_POST['CompanyStreetAddress'], $_POST['CompanySuit'], $_POST['City'], $_POST['State'], $_POST['Zipcode'], $_POST['CompanyPhone'],  $_POST['BillingName'], $_POST['BillingCompanyStreetAddress'], $_POST['BillingCompanySuite'], $_POST['BillingCity'], $_POST['BillingState'], $_POST['BillingZipCode'], $_POST['BillingPhone']); // set all the values of the row columns

    if($stmt->execute()){ // if the query is successful
        die("Query Successful"); // output success message
    }
}

Now, assuming I have done everything correctly (including counting out the plethora of post data you have), the query should execute, and you should get the message:

Query Successful

Please note: With "ssssssiisssssii", s means string, and i means integer.

If anything goes wrong, or you get any errors, leave it in the comments.

To find out more about prepared statements and MySQLi itself, have a look at the PHP manual: http://php.net/manual/en/mysqli.prepare.php

GROVER.
  • 4,071
  • 2
  • 19
  • 66
0
<?php

$sql = "INSERT INTO client(
    Project_Manager,
    Email_Address, 
    Company_Name, 
    Company_Street_Address, 
    Company_Suit, 
    City, 
    State, 
    Zip_code, 
    Company_Phone, 
    Billing_Name, 
    Billing_Company_Street_Address, 
    Billing_Company_Suite, 
    Billing_City, 
    Billing_State, 
    Billing_Zip_Code, 
    Billing_Phone
)
    VALUES( '{$_POST['ProjectManager']}',
            '{$_POST['EmailAddress']}',
            '{$_POST['CompanyName']}',
            '{$_POST['CompanyStreetAddress']}',
            '{$_POST['CompanySuit']}',
            '{$_POST['City']}',
            '{$_POST['State']}',
            '{$_POST['Zipcode']}',
            '{$_POST['CompanyPhone']}',
            '{$_POST['BillingName']}',
            '{$_POST['BillingCompanyStreetAddress']}',
            '{$_POST['BillingCompanySuite']}',
            '{$_POST['BillingCity']}',
            '{$_POST['BillingState']}',
            '{$_POST['BillingZipCode']}',
            '{$_POST['BillingPhone']}',
            )";

mysql_query($sql,$con);
mysql_close($con);
    }

?>