0

Here's the PHP code:

<?php
  $servername = "***";
  $username = "*****";
  $password = "*****";
  $database = "*****";

try {
  $conn = new PDO('mysql:host='.$servername.';dbname='.$database, $username, $password);
  console.log('yes!');
}
catch(PDOException $e) {
  print "Error!:" . $e->getMessage(). "<br/>";
  die();
}

if (isset($_POST['submit']))
{
//$name = $_POST['name'];
//$day = $_POST['day']; 
//$acctName = $_POST['acctName'];
//$acctType = $_POST['acctType'];
//$location = $_POST['location'];
//$prospect = $_POST['prospect'];
//$notes = $_POST['notes'];

$name = 'sally sue';
$day = 'monday';
$acctName = 'Account Uno';
$acctType = 'Cold Call';
$location = 'Location';
$prospect = 'Prospect';
$notes = 'These are notes! Notey notey notes';

$order = "INSERT INTO `schedule`(`id`, `name`, `day`, `acctName`, `acctType`, `location`, `prospect`, `notes`) VALUES ('$name', '$day', '$acctName', '$acctType', '$location', '$prospect', '$notes')";
$stmt = $conn->prepare($order);
$stmt->execute();
}
?>

Here's the deal. I have an HTML form that I use jQuery to grab the variables, and AJAX to post the form to this PHP file. I feel confident that everything is fine up to the point where it gets to the PHP file.

I commented out the POST variables and hard-coded my own to make it a little simpler. I'm not getting a 500 Internal Server Error. I've ran my code through a PHP syntax validator (and fixed a billion errors haha). Obviously I'm still doing something wrong, but I cannot find it for the life of me. I'm hoping that someone here has some insight?

EDIT: Also, the username, password, database, and table name are ALL correct. I've double checked them several times. The only thing I'm not sure of is the server name, which is 'localhost' since the DB is on the same server as this web page.

EDIT 2: I've changed the MySql insert statement back to the original, which had the back ticks. I copied it straight from phpMyAdmin console on the server which it resides. It was that way originally, but I changed it due to desperation. It still is not updating my database. Any further ideas?

Thanks in advance!

perkface
  • 113
  • 2
  • 10
  • Have you checked the error logs? – Jay Blanchard Apr 14 '16 at 18:28
  • I do not have immediate, direct access to the error logs (I don't think). Unless I can get them with just a browser and FTP access? – perkface Apr 14 '16 at 18:28
  • wrong Identifier Qualifiers http://dev.mysql.com/doc/refman/5.7/en/identifier-qualifiers.html and http://php.net/manual/en/pdo.error-handling.php would have thrown you something about it – Funk Forty Niner Apr 14 '16 at 18:28
  • Wrong escaping on column names (backticks, not quotes), missing quotes on strings in the data being written. This also is not how prepared statements are meant to be used. http://php.net/manual/en/pdo.prepared-statements.php – chris85 Apr 14 '16 at 18:37
  • So, I reverted my insert statement back to the original (copied from phpMyAdmin), and this is not the issue. I should have specified that I changed that line out of desperation, and was second-guessing myself. It still is not updating the table. Any further ideas? – perkface Apr 14 '16 at 18:50
  • 1
    @perkface delete your other question http://stackoverflow.com/q/36653256/ and I'll reopen this one. Next time, ping the person who closed it, being me and stating to the person who closed it that you've done an edit. I only saw that because I noticed your other question. So, please... next time, ping ;-) now delete the other one, thanks. Edit: To "ping" means you use the @ symbol followed by the members name. – Funk Forty Niner Apr 15 '16 at 17:23
  • You now have `id` in your insert's field list, which appears extraneous and was not there in earlier edits of your question. Is this contributing to the problem, by now? – Thernys Apr 15 '16 at 18:05
  • Also, does your insert actually work if you run it manually in PhpMyAdmin or otherwise, using your test values? – Thernys Apr 15 '16 at 18:18
  • The id is automatically generated my SQL when the insert happens, I wasn't sure whether to include it or not. Also, yes, the insert statement works when inputted manually. I actually copied it from PhpMyAdmin with the "Create PHP Code" link it provides. I am working with a coworker on a different approach using an older, simpler example utilizing all PHP pages. It's very promising. I will post my solution once we have it figured out. Thank you all for your input. – perkface Apr 18 '16 at 18:39

0 Answers0