2017-02-07 6 views
0

Ich habe ein Formular, mit dem ein Benutzer Daten eingeben kann. Am Ende gibt es eine Übergabeschaltfläche, die gedrückt werden kann, um die eingegebenen Daten in eine Datenbank einzugeben. Ich hatte das vor ein paar Wochen in Arbeit, musste aber einen Abstecher zu einigen anderen Projekten machen. Ich bin jetzt zurück und die Einfügung scheint nicht zu funktionieren und ich bin mir nicht sicher warum.Einfügen in Datenbank auf HTML-Formular senden

Also konzentriere ich mich hauptsächlich auf den unteren Teil des Codes mit den SQL-Anweisungen, habe aber den anderen HTML-Code für Ihre Referenz bereitgestellt. Sehen Sie irgendwelche Probleme in meinen SQL-Anweisungen?

Beachten Sie auch, dass die Seite selbst nicht geladen, wenn dieser Abschnitt von SQL-Code wird nicht auf Kommentar:

INSERT INTO Stage_Rebate_Agreements 
(
    Terms, 
    Tier, 
    `Tier Minimum`, 
    Multiplier, 
    UOM, 
    Retro, 
    Guaranteed, 
    Pay 
) 
VALUES 
(
    '$_POST[rows[0][0][term]]', 
    '$_POST[tier]', 
    '$_POST[rows[0][0][purchase_minimum]]', 
    '$_POST[rows[0][0][multiplier]]', 
    '$_POST[rows[0][0][uom]]', 
    '$_POST[rows[0][0][retro]]', 
    '$_POST[rows[0][0][guaranteed]]', 
    '$_POST[rows[0][0][paid]]' 
) 

Aber wenn es nicht kommentiert geführt wird, wird die Seite nicht aus irgendeinem Grunde laden.

Wenn wir das irgendwie beheben können, würde es sehr geschätzt werden!

<?php 
$host="xxxxxxxx"; 
    $dbName="xxxxxxxxx"; 
    $dbUser="xxxxxxx"; 
    $dbPass="xxxxxxxxxxxxx"; 
    $dbh = new PDO("sqlsrv:Server=$host;Database=$dbName", $dbUser, $dbPass); 

    $usersQuery = "SELECT MR_Name, MR_POC_N, MR_POC_E, MR_POC_P FROM Stage_Rebate_Master"; 

    $users = $dbh->query($usersQuery); 

?> 

<html> 
<body> 

    <div class="wrapper"> 

     <header> 
      <h2>test</h2> 
     </header> 

    <div class="container"> 

<form name="form1" action="confirmation.php" method="POST"> 

<!-- Vendor --> 

<section class="desc-block-left0" align="left"> 
<div> 
<div id="vendor"> 
<strong>Vendor:</strong> 
</div> 

<div class="align"> 
<select name="vendor_dropdown" id="ven" onChange="updateinput();"> 
    <option value="">Choose a Vendor</option> 
     <?php foreach($users->fetchAll() as $user): ?> 
      <option 
        data-name="<?php echo $user['MR_POC_N'];?>" 
        data-email="<?php echo $user['MR_POC_E'];?>" 
        data-phone="<?php echo $user['MR_POC_P'];?>" 
      > 
       <?php echo $user['MR_Name'];?> 
      </option> 
     <?php endforeach; ?> 
</select> 
</div> 

</div> 
</section> 

<!-- Program Name --> 

<section class="desc-block-right0"> 
<div> 
<div id="program_name"> 
<strong>Program Name:</strong><br> 
</div> 

<div class="align1"> 
<input class="textbox" type="text" id="program_name1" name="program_name" style="width: 50%"> 
</div> 

</div> 
</section> 

<!-- Program Period --> 

<section class="desc-block-left1"> 
<div> 
<div id="program_period"> 
<strong>Program Period:</strong> 
</div> 

<div class="align"> 
<input type="text" name="program_period_dropdown" id="period" value="<?php echo date("Y");?>" readonly style="width: 50px"> 
</div> 

</div> 
</section> 

<!-- Terms --> 

<section class="desc-block-right1"> 
<div> 
<div id="terms"> 
<strong>Terms:</strong><br> 
</div> 

<div class="align1"> 
<input type="text" id="year" name="term" style="width: 50px"> 
<label for="percent">%</label> 
<input type="text" id="year" name="term" style="width: 50px"> 
<label for="percent">Net</label> 
<input type="text" id="year" name="term" style="width: 50px"> 
</div> 

</div> 
</section> 

<!-- Vendor Type --> 

<section class="desc-block-left2"> 
<div> 
<div id="vendor_type"> 
<strong>Vendor Type:</strong><br> 
</div> 

<div class="align"> 
<table align="left"> 
    <tr align="center"> 
     <td><input type="radio" name="ven_type" value="Coded" id="type" checked="true"></td> 
     <td align="left">Coded</td> 
    </tr> 
    <tr align="center"> 
     <td><input type="radio" name="ven_type" value="Non-Coded" id="type"></td> 
     <td>Non-Coded</td> 
    </tr> 
</table> 
</div> 

</div> 
</section> 

<!-- Contact Information --> 

<section class="desc-block-right2" align="center"> 
<div> 
<div id="contact_info"> 
<strong>Contact Information:</strong><br> 
</div> 

<div class="align1"> 
<table align="left" id="contact"> 
<tr align="left"> 
    <th>Name</th> 
    <th>Email</th> 
    <th>Phone Number</th> 
</tr> 
    <tr> 
     <td><input type="text" id="name" class="name" name="name"></td> 
     <td><input type="email" id="email" class="email" name="email"></td> 
     <td><input type="tel" id="tel" class="tel" name="number"></td> 
     <td><input type="button" class="save" name="edit" value="Save"></td> 
    </tr> 
</table> 
</div> 

</div> 
</section> 

<!-- 400 Rebate Tables --> 
<!-- 400P --> 

<div align="center" id="border"> 
<div id="rebate_400p"> 
<strong>400P</strong><br> 
</div> 

<table id="tables" cellspacing="5"> 
    <tr align="center" class="table_titles"> 
     <td>Tier</td> 
     <td>Purchase Minimum</td> 
     <td>Multiplier</td> 
     <td>UOM</td> 
     <td>Retro</td> 
     <td>Guaranteed</td> 
     <td>Paid</td> 
     <td>Delete?</td> 
     <td>Add Row</td> 
    </tr> 
    <tr> 
      <td align="center" name="tier" id="tier">1</td> 
      <td><input type="text" class="rebate_tables" id="purchase_min" data-name="purchase_minimum" name="rows[0][0][purchase_minimum]"></td> 
      <td><input type="text" class="rebate_tables" id="multiplier" data-name="multiplier" name="rows[0][0][multiplier]"></td> 
      <td><input type="text" class="rebate_tables" id ="uom" data-name="uom" name="rows[0][0][uom]"></td> 
      <td><input type="text" class="rebate_tables" id="retro" data-name="retro" name="rows[0][0][retro]"></td> 
      <td><input type="text" class="rebate_tables" id="guaranteed" data-name="guaranteed" name="rows[0][0][guaranteed]"></td> 
      <td><input type="text" class="rebate_tables" id="paid" data-name="paid" name="rows[0][0][paid]"></td> 
      <td><input type="button" class="delRow" value="Delete" onclick="deleteRow(this)"></td> 
      <td><input type="button" class="addmoreRowsbutton" value="Add row" onclick="insRow()"></td> 
     </tr> 
</table> 

<!-- 400M --> 
<div id="rebate_400m"> 
<strong>400M</strong><br> 
</div> 

<table cellspacing="5" id="tables1" style="display: none;"> 
    <tr align="center" class="table_titles"> 
     <td>Tier</td> 
     <td>Purchase Minimum</td> 
     <td>Multiplier</td> 
     <td>UOM</td> 
     <td>Retro</td> 
     <td>Guaranteed</td> 
     <td>Paid</td> 
     <td>Delete?</td> 
     <td>Add Rows</td> 
    </tr> 
    <tr> 
      <td align="center" name="tier" id="tier1">1</td> 
      <td><input type="text" class="rebate_tables" id="purchase_min1" data-name="purchase_minimum" name="rows[1][0][purchase_minimum]"></td> 
      <td><input type="text" class="rebate_tables" id="multiplier1" data-name="multiplier" name="rows[1][0][multiplier]"></td> 
      <td><input type="text" class="rebate_tables" id ="uom1" data-name="uom" name="rows[1][0][uom]"></td> 
      <td><input type="text" class="rebate_tables" id="retro1" data-name="retro" name="rows[1][0][retro]"></td> 
      <td><input type="text" class="rebate_tables" id="guaranteed1" data-name="guaranteed" name="rows[1][0][guaranteed]"></td> 
      <td><input type="text" class="rebate_tables" id="paid1" data-name="paid" name="rows[1][0][paid]"></td> 
      <td><input type="button" class="delRow" value="Delete" onclick="deleteRow(this)"></td> 
      <td><input type="button" class="addmoreRowsbutton" value="Add row" onclick="insRow1()"></td> 
     </tr> 
</table> 
<!-- Button to display table for 400M --> 
<input type="button" name="row" value="+" onclick="show2();"/> 

<!-- 400D --> 

<div id="rebate_400d"> 
<strong>400D</strong><br> 
</div> 

<table cellspacing="5" id="tables2" style="display: none;"> 
    <tr align="center" class="table_titles"> 
     <td>Tier</td> 
     <td>Purchase Minimum</td> 
     <td>Multiplier</td> 
     <td>UOM</td> 
     <td>Retro</td> 
     <td>Guaranteed</td> 
     <td>Paid</td> 
     <td>Delete?</td> 
     <td>Add Rows</td> 
    </tr> 
    <tr> 
      <td align="center" name="tier" id="tier2">1</td> 
      <td><input type="text" class="rebate_tables" id="purchase_min2" data-name="purchase_minimum" name="rows[2][0][purchase_minimum]"></td> 
      <td><input type="text" class="rebate_tables" id="multiplier2" data-name="multiplier" name="rows[2][0][multiplier]"></td> 
      <td><input type="text" class="rebate_tables" id ="uom2" data-name="uom" name="rows[2][0][uom]"></td> 
      <td><input type="text" class="rebate_tables" id="retro2" data-name="retro" name="rows[2][0][retro]"></td> 
      <td><input type="text" class="rebate_tables" id="guaranteed2" data-name="guaranteed" name="rows[2][0][guaranteed]"></td> 
      <td><input type="text" class="rebate_tables" id="paid2" data-name="paid" name="rows[2][0][paid]"></td> 
      <td><input type="button" class="delRow" value="Delete" onclick="deleteRow(this)"></td> 
      <td><input type="button" class="addmoreRowsbutton" value="Add row" onclick="insRow2()"></td> 
     </tr> 
</table> 
<!-- Button to adisplay table for 400D --> 
<input type="button" name="row" value="+" id="plus-button" onclick="show3();"/> 
</div> 

<!-- Products --> 

<div id="align"> 
<p> 
<div id="products"> 
<strong>Products:</strong><br> 
</div> 

<input type="radio" name="product" value="All" onclick="hide();"/ checked> All 
<input type="radio" name="product" value="Category" onclick="show();"/> Category 
<input type="radio" name="product" value="Sku" onclick="hide();"/> Sku 
    <select multiple id="area" name="category" style="display: none;"> 
     <option value="Example A" align ="center">Example A</option> 
     <option value="Example B" align ="center">Example B</option> 
     <option value="Example C" align ="center">Example C</option> 
     <option value="Example D" align ="center">Example D</option> 
     <option value="Example E" align ="center">Example E</option> 
     <option value="Example F" align ="center">Example F</option> 
    </select> 
</p> 

<!-- Submit Button --> 

<br> 
<input type="submit" value="Submit" id="btn" name="submit"> 
</div> 

</form> 

    </div> 

    <div class="push"></div> 
    </div> 
    <div class="footer"> 
    <footer> 
     <h3>test</h3> 
    </footer> 
    </div> 

</body> 
</html> 


<?php 

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

    { 

    $host="xxxxxxxxxxx"; 
    $dbName="xxxxxx"; 
    $dbUser="xxxxxxxxxxxxxx"; 
    $dbPass="xxxxxxxxxx"; 

    $pdo = new PDO("sqlsrv:server=".$host.";Database=".$dbName, $dbUser, $dbPass); 

    $sql = "INSERT INTO Stage_Rebate_Master (MR_Name, MR_POC_N, MR_POC_E, MR_POC_P) VALUES ('$_POST[vendor_dropdown]','$_POST[name]','$_POST[email]','$_POST[number]')"; 

    $sql1 = "INSERT INTO Stage_Rebate_Programs (Program_Year) VALUES ('$_POST[program_period_dropdown]')"; 

    $sql2 = "INSERT INTO Stage_Rebate_Agreements (Terms, Tier, `Tier Minimum`, Multiplier, UOM, Retro, Guaranteed, Pay) VALUES ('$_POST[rows[0][0][term]]','$_POST[tier]','$_POST[rows[0][0][purchase_minimum]]','$_POST[rows[0][0][multiplier]]','$_POST[rows[0][0][uom]]','$_POST[rows[0][0][retro]]','$_POST[rows[0][0][guaranteed]]','$_POST[rows[0][0][paid]]')"; 

    $sql3 = "INSERT INTO Stage_Rebate_Programs (Program_Name) VALUES ('$_POST[program_name]')"; 

    $stmt = $pdo->prepare($sql); 
    $stmt1 = $pdo->prepare($sql1); 
    $stmt2 = $pdo->prepare($sql2); 
    $stmt3 = $pdo->prepare($sql3); 

    $result = $stmt->execute(); 
    $result1 = $stmt1->execute(); 
    $result2 = $stmt2->execute(); 
    $result3 = $stmt3->execute(); 

    echo json_encode($result); 
    echo json_encode($result1); 
    echo json_encode($result2); 
    echo json_encode($result3); 


} 

?> 
+0

ich wieder etikettierte Ihre Frage als 'MySQL' statt 'SQL Server' aufgrund der verwendeten Syntax. – Siyual

+0

Sie sind ziemlich offen für SQL-Injection ... – Naruto

+0

Sie müssen lesen, zu verstehen, und starten Sie mit parametrisierten Abfragen bevor bobby Tabellen zu Besuch kommt. http://bobby-tables.com/ –

Antwort

0

entfernen Sie das Attribut action=confirmation.php in form, als Folge davon die untere Code einreichen funktioniert nicht

<form name="form1" method="POST"> 

Das ist genug

+0

der Einsatz funktioniert jetzt .... so jetzt muss ich nur noch auf die Bestätigungsseite nach dem Klicken auf klicken – Rataiczak24

+0

Hoffe, dass Ihr Problem gelöst ist – affaz

+0

Ich muss noch in der Lage sein, auf die Seite confirmation.php nach dem Einreichen klicken Sie auf – Rataiczak24