RBliel Posted December 19, 2019 Share Posted December 19, 2019 I am having a problem inserting information into my database. It will not create a record, no matter what I do. I have used the exact same template for two other pages, and it works fine, but for this one, it simply will not work. If I echo each variable, it will print out, but even if I reduce the insert to one field, it still will not work. Please help... Here is my code. <?php session_start(); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>WO</title> </head> <body> <?php require('connect.php'); $ID = $_POST['ID']; $CustomerFirstName = $_POST['Customer_B']; $CustomerLastName = $_POST['Customer_A']; $CustomerAddress = $_POST['Customer_C']; $CustomerCity = $_POST['Customer_D']; $CustomerState = $_POST['Customer_E']; $CustomerZipCode = $_POST['Customer_F']; $CustomerPhone = $_POST['Customer_G']; $CustomerEmail = $_POST['Customer_H']; $SCLastName = $_POST['Service_A']; $SCFirstName = $_POST['Service_B']; $SCAddress = $_POST['Service_C']; $SCCity = $_POST['Service_D']; $SCState = $_POST['Service_E']; $SCZip = $_POST['Service_F']; $SCPhone = $_POST['Service_G']; $SCEmail = $_POST['Service_H']; $DateRequested = date('Y-m-d', strtotime($_POST['Date_Requested'])); $DateScheduled = date('Y-m-d', strtotime($_POST['Date_Scheduled'])); $AssignedTo = $_POST['Assigned_To']; $ServiceBranch = $_POST['Service_Branch']; $Warranty = isset($_POST['Warranty'])?$_POST['Warranty']:"No"; $WorkRequested = $_POST['Work_Requested']; $sql = "INSERT INTO WorkOrder (ID, CustomerLastName, CustomerFirstName, CustomerAddress, CustomerCity, CustomerState, CustomerZip, CustomerPhone, CustomerEmail, SCLastName, SCFirstName, SCAddress, SCCity, SCState, SCZip, SCPhone, SCEmail, DateRequested, DateScheduled, Warranty, WorkRequested, ServiceBranch, AssignedTo) VALUES ('$ID', '$CustomerLastName', '$CustomerFirstName', '$CustomerAddress', '$CustomerCity', '$CustomerState', '$CustomerZipCode', '$CustomerPhone', '$CustomerEmail', '$SCLastName', '$SCFirstName', '$SCAddress', '$SCCity', '$SCState', '$SCZip', '$SCPhone', '$SCEmail', '$DateRequested', '$DateScheduled', '$Warranty', '$WorkRequested', '$ServiceBranch', '$AssignedTo')"; if ($conn->query($sql) == TRUE) { echo "<script type='text/javascript'> alert('Work Order Created'); </script>"; echo "<script type='text/javascript'> document.location = 'Main.php'; </script>"; } else { echo "<script type='text/javascript'> alert('Record Not Inserted'); </script>"; echo "<script type='text/javascript'> document.location = 'Work_Order.php'; </script>; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/309715-insert-into-problems/ Share on other sites More sharing options...
requinix Posted December 19, 2019 Share Posted December 19, 2019 My guess is that you're entering duplicate data. Something conflicting with the primary key, or a unique index. Quote Link to comment https://forums.phpfreaks.com/topic/309715-insert-into-problems/#findComment-1572674 Share on other sites More sharing options...
Barand Posted December 19, 2019 Share Posted December 19, 2019 I don't know if you are using PDO or MySqli, but whichever it is, use its error reporting functionality to find out why. Quote Link to comment https://forums.phpfreaks.com/topic/309715-insert-into-problems/#findComment-1572677 Share on other sites More sharing options...
ginerjm Posted December 19, 2019 Share Posted December 19, 2019 Since you aren't giving us any error message have you looked into the error log on your system to see if any is being reported? Do you get any message from the code that says the query did not run, or just looking at the table and not seeing your record(s)? Quote Link to comment https://forums.phpfreaks.com/topic/309715-insert-into-problems/#findComment-1572681 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.