Jump to content

FoxfireTX

Members
  • Posts

    12
  • Joined

  • Last visited

Everything posted by FoxfireTX

  1. Justsomeguy, I'm trying to understand what you are saying. I did not start with this code, I started with things in appropriate "" but the server kept giving me errors. I was stunned with what I got back when I uploaded. As I noted previously, when I first uploaded it was clean on my localhost and in netbeans but the server would not read it. In my first variable, I now have it defined as :/ / define variables $firstname = $_POST[firstname]; I only have that because I got error messages with it in either double or single quotes. It made no sense to me as that was the way I had defined variables previously with no issues but this was the first time trying to insert data into SQL. I went so far as to check versions of php because it made no sense. But the only way it would proceed beyond the variables was by eliminating all single or double quotes in defining the variables.
  2. I was WRONG! Dsonesuk you GOT it! Forgot to change the database name, and taking out that extra space did it! Also tried it on the server and it inserted. I cannot thank you enough, as well as everyone who tried to help! Thank you, thank you!
  3. Extra space? Just tried taking that out, and still nothing but a page of warnings with this code on my localhost, did not insert the data: if (isset($_POST[firstname], $_POST[lastname], $_POST[email], $_POST[phone])) { if ($stmt = $link->prepare('INSERT INTO `volunteerstest`(`firstname`, `lastname`,`email`, `phone`) VALUES (?, ?, ?, ?)')) { $stmt->bind_param('ssss', $_POST[firstname], $_POST[lastname], $_POST[email], $_POST[phone]); if (!$stmt->execute()) { error_log('Execute failed '.$stmt->error); } else { echo 'Data successfully inserted! first name '.$_POST[firstname].' last name '.$_POST[lastname].' email '.$_POST[email].' and phone '.$_POST[phone].''; } $stmt->close(); } else { error_log('Prepare failed'.$link->error); } }
  4. So you don't think I am totally out of my mind, this is the statement I just received from the server taking that same INSERT into language down to 3 columns rather than the 4 or more: Data successfully inserted! + the data listing And the same code, taken down to three variables: if (isset($_POST[firstname], $_POST[email], $_POST[phone])) { if ($stmt = $link->prepare('INSERT INTO `volunteerstest`(`firstname`, `email`, `phone`) VALUES (?, ?, ?)')) { $stmt->bind_param('sss', $_POST[firstname], $_POST[email], $_POST[phone]); if (!$stmt->execute()) { error_log('Execute failed '.$stmt->error); } else { echo 'Data successfully inserted! first name '.$_POST[firstname].' email '.$_POST[email].' and phone '.$_POST[phone].''; } $stmt->close(); } else { error_log('Prepare failed'.$link->error); } } ?>
  5. That's where I started Saturday, and that is what would NOT run when I uploaded the pages to the server. I ended up debugging by one line at a time, and uploading again for the next line. At the moment, when I try to go from inserting 3 columns of data to 4 columns, this is the error message from the server: Parse error: syntax error, unexpected ',' in /.../volunteers3remote.php on line 124 And this is the code starting with line 124, which is the INSERT INTO section: Line 124 if (isset($_POST[firstname], ($_POST[lastname], $_POST[email], $_POST[phone])) { if ($stmt = $link->prepare('INSERT INTO `volunteerstest`(`firstname`, `lastname`, `email`, `phone`) VALUES (?, ?, ?, ?)')) { $stmt->bind_param('ssss', $_POST[firstname], ($_POST[lastname], $_POST[email], $_POST[phone]); if (!$stmt->execute()) { error_log('Execute failed '.$stmt->error); } else { echo 'Data successfully inserted! first name '.$_POST[firstname].' last name '.$_POST[lastname].' email '.$_POST[email].' and phone '.$_POST[phone].''; } $stmt->close(); } else { error_log('Prepare failed'.$link->error); } } $> If I take this down to 3 columns of data, just firstname, email and phone it runs just fine, inserts the data with the warnings about future versions. But I have 10 columns of data for this table:-)
  6. These are the page full of warnings I get in NetBeans and on my local host when I get it to run on the server: " Warning: Use of undefined constant firstname - assumed 'firstname' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\volunteers3local.php on line 130" And these are the type of messages I get on the server if I heed the warnings in NetBeans and on my localhost: "Parse error: syntax error, unexpected 'mail' (T_STRING) " and it will NOT insert the data. To get the sample that works to actually insert the data, I basically changed every " to ' and where I had the single quotes ' I deleted many of them and then it ran and actually inserted the data, at least for 3 columns:-)
  7. This is the full code that will insert data: <?php ini_set('display_errors', '1'); ?> <?php // 1. Create connection to database define('DB_NAME', ''); define('DB_USER', ''); define('DB_PASS', ''); define('DB_HOST', 'localhost'); $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); if (!$link) { die('Could not connect to database: ' . mysqli_error()); } // define variables $firstname = $_POST[firstname]; $lastname = $_POST[lastname]; $email= $_POST[email]; $zip= $_POST[zip]; $phone= $_POST[phone]; $house_party= $_POST[house_party]; $canvass= $_POST[canvass]; $phonebank= $_POST[phonebank]; $anything= $_POST[anything]; $comments= $_POST[comments]; if ($_SERVER[REQUEST_METHOD] == 'POST') if (empty($_POST[firstname])) { $nameErr = 'First name is required'; } else { $firstname = test_input($_POST[firstname]); } // check if name only contains letters and whitespace if (!preg_match('/^[a-zA-Z ]*$/',$firstname)) { $firstnameErr = 'Only letters and white space allowed'; } if ($_SERVER[REQUEST_METHOD] == 'POST') if (empty($_POST[lastname])) { $nameErr = 'Last name is required'; } else { $lastname = test_input($_POST[lastname]); } // check if name only contains letters and whitespace if (!preg_match('/^[a-zA-Z ]*$/',$lastname)) { $lastnameErr = 'Only letters and white space allowed'; } if ($_SERVER[REQUEST_METHOD] == 'POST') if (empty($_POST[email])) { $emailErr = 'Email is required'; } else { $email = test_input($_POST[email]); } // check if e-mail address is well-formed if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = 'Invalid email format'; } /* Check all form inputs using test_input function */ if ($_SERVER[REQUEST_METHOD] == 'POST') { $firstname = test_input($_POST[firstname]); $lastname = test_input($_POST[lastname]); $email = test_input($_POST[email]); $phone = test_input($_POST[phone]); $comments = test_input($_POST[comments]); } if (isset($_POST['myCheckbox'])) { $checkBoxValue = "yes"; } else { $checkBoxValue = "no"; } if(!empty($_POST['check'])) { foreach($_POST['check'] as $value) { $check_msg .= "Checked:".$value."\n"; } } if (isset($_POST[house_party])) { $anything = 'yes'; } else { $anything = 'no'; } if (isset($_POST[canvass])) { $canvass = 'yes'; } else { $canvass = 'no'; } if (isset($_POST[phonebank])) { $phonebank = 'yes'; } else { $phonebank = 'no'; } if (isset($_POST[anything])) { $anything = 'yes'; } else { $anything = 'no'; } $check = isset($_POST[check]) ? $_POST[check] : ''; function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } //inserting data into database if (isset($_POST[firstname], $_POST[email], $_POST[phone])) { if ($stmt = $link->prepare('INSERT INTO `volunteers`(`firstname`, `email`, `phone`) VALUES (?, ?, ?)')) { $stmt->bind_param('sss', $_POST[firstname], $_POST[email], $_POST[phone]); if (!$stmt->execute()) { error_log('Execute failed '.$stmt->error); } else { echo 'Data successfully inserted! first name '.$_POST[firstname].' email '.$_POST[email].' and phone '.$_POST[phone].''; } $stmt->close(); } else { error_log('Prepare failed'.$link->error); } } ?> But if I change the INSERT INTO to this I get the page full of warnings and it will not insert the data: //inserting data into database if (isset($_POST[firstname], $_POST[lastname], $_POST[email], $_POST[phone])) { if ($stmt = $link->prepare('INSERT INTO `volunteers`(`firstname`, `lastname` `email`, `phone`) VALUES (?, ?, ?, ?)')) { $stmt->bind_param('ssss', $_POST[firstname], $_POST[lastname], $_POST[email], $_POST[phone]); if (!$stmt->execute()) { error_log('Execute failed '.$stmt->error); } else { echo 'Data successfully inserted! first name '.$_POST[firstname].' last name '.$_POST[lastname].' email '.$_POST[email].' and phone '.$_POST[phone].''; } $stmt->close(); } else { error_log('Prepare failed'.$link->error); } }
  8. dsonesuk, that is where I started but it will not run that way on the server. Throws a page full of error messages. That is why I ended up debugging line by line on the server to get it to insert data. It makes zero sense to me.
  9. OK, so I went back, copied the INSERT INTO exactly from the one this working into a new doc, and went from the 10 columns of data to just the 4 required (firstname, lastname, email, phone) and adjusted the other things accordingly, but got this error message both on the server and on local host: " Parse error: syntax error, unexpected ',' in on line 124". So I then went back and stripped it down to three columns, firstname, email phone, and it inserted on my local host along with a page full of these messages, which I've come to expect to get it to write into the database on the server: Warning: Use of undefined constant firstname - assumed 'firstname' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\volunteers3local.php on line 130 but on the server side if I do as the warning suggests it will not run further. WHY would adding a 4th factor send it into error mode with making the same adjustments to the rest of the INSERT code?
  10. I should note further, we were under tight timelines initially to get the website up and running so I just used the send email function to capture the data in some way at this point. I have a niece who works with SQL every day so she has since set up the database and tables, and now the goal is to get the data to insert into the database for future use so it doesn't have to be added manually. Thanks!
  11. The warnings in netbeans relate to filtering and not accessing Global array directly. None of what it is happening when I upload to the server makes sense to me. I can run the code on the website portion of the server and it runs correctly without warnings. But when I try to insert data into a table on the SQL side, I get all kinds of warnings about single versus double quotes, etc. As I noted, I debugged the first test line by line on the server itself to finally get it to insert the data. This is the code that IS inserting data on the server now. It was clean on my localhost and netbeans when I first uploaded to the server, but I got a page of warnings on the server, which I debugged line by line to get here which now runs clean and actually inserts the data to a table. It's gotten to the point that I name them remote for the server and local for those I'm running on my local host. Where and how do I access an error log? I really appreciate any help with this. <?php ini_set('display_errors', '1'); ?> <?php define('DB_NAME', ''); define('DB_USER', ''); define('DB_PASS', ''); define('DB_HOST', 'localhost'); $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); if (!$link) { die('Could not connect to database: ' . mysqli_error()); } // define variables $name = $_POST[name]; $email= $_POST[email]; $phone= $_POST[phone]; if ($_SERVER[REQUEST_METHOD] == 'POST') if (empty($_POST[name])) { $nameErr = 'Name is required'; } else { $name = test_input($_POST[name]); } // check if name only contains letters and whitespace if ((!preg_match('/^[a-zA-Z ]*$/',$name))){ $nameErr = 'Only letters and white space allowed'; } if ($_SERVER[REQUEST_METHOD] == 'POST') if (empty($_POST[email])) { $emailErr = 'Email is required'; } else { $email = test_input($_POST[email]); } $email = test_input($_POST[email]); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = 'Invalid email format'; } if ($_SERVER[REQUEST_METHOD] == 'POST') { $name = test_input($_POST[name]); $email = test_input($_POST[email]); $phone = test_input($_POST[phone]); } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } //inserting data into database if (isset($_POST[name], $_POST[email], $_POST[phone])) { if ($stmt = $link->prepare('INSERT INTO `updatestest`(`name`, `email`, `phone`) VALUES (?, ?, ?)')) { $stmt->bind_param('sss', $_POST[name], $_POST[email], $_POST[phone]); if (!$stmt->execute()) { error_log('Execute failed '.$stmt->error); } else { echo 'Data successfully inserted! name '.$_POST[name].' email '.$_POST[email].' and phone '.$_POST[phone].''; } $stmt->close(); } else { error_log('Prepare failed'.$link->error); } } $> As an experiment this morning, I added the send email code to the bottom of the volunteers2remote.php as follows: /* message for the e-mail */ $to = 'me@att.net'; $subject = 'Volunteer from website'; $check = isset($_POST[check]) ? $_POST[check] : ''; $body = "First Name: ".$firstname ."\r\n". "Last Name: ".$lastname ."\r\n". "Email: ".$email ."\r\n". "Phone: ".$phone ."\r\n". "ZIP: ".$zip ."\r\n" . "Host a house party: ".$house_party . "\r\n" . "Canvass: ".$canvass . "\r\n" . "Phone Bank: ".$phonebank . "\r\n" . "Anything Needed: ".$anything . "\r\n" . "Comments: ".$comments ."\r\n"; // Setup headers $headers .= "Return-Path: " . $email; /* Send the message using mail() function */ mail($to, $subject, $body, $headers); I received the email just fine with all the info included, but got a blank screen in my browser, i.e., no error messages, and it it did not insert the data in the table. So I then added the same exact email code to the bottom of the sample7remote.php above which IS inserting data and again got numerous warnings which I am still debugging, primarily syntax and T string errors: And again, I got rid of the errors by changing from double quotes around the to: definition to single quotes, etc. Why the code works fine when it is not inserting into the database but throws error messages when it is inserting into the database is a mystery to me. But this is the same way it worked throughout the code when I first uploaded the sample7remote to the server on Saturday. After having it run clean through netbeans and my localhost I was stunned by a page of error messages. At this point just trying to keep my sense humor about it:-) Can't thank you enough for your help as I am just at a loss.
  12. I am new to php and am having a real problem getting it to write to SQL tables from form input. I finally managed to get a 3 column test form to insert the data into a test table, so moved on to the next test of inserting a 10 column form that includes 4 check boxes following the script of the one I got to insert. But I cannot get it to insert the data. I also have the problem that my localhost is running php 7.1 while the SQL side of the server is using php 5.6, thus the many single quotes versus double quotes or no quotes. With the first test script, I debugged line by line, and figured out if I get a bunch of warnings in netbeans and my local server but no red flags it most likely will work on the server. But this script has me at a loss. I have stripped out anything superfluous such as the thank you html, the email send portion, and debugged it line by line with the server. The connection is good, it takes a second as if it is inserting, I get zero warnings or errors at this point, but in the end it has not inserted the data into the table. I have checked and rechecked the database name, table name, columns etc and nothing. I appreciate any ideas and help from anyone here. Thanks so much! This is the form portion of the html: <form class="contact-form" role="form" action="volunteers2remote.php" method="post" onsubmit="document.getElementById('updatesButton').disabled=true; document.getElementById('updatesButton').value='Submitting, please wait...';"> <div class="form-group"> <label for="firstname" class="hidden">First Name</label> <input type="text" class="form-control" name="firstname" id="firstname" value="" required="required" placeholder="First Name"> </div> <div class="form-group"> <label for="lastname" class="hidden">Last Name</label> <input type="text" class="form-control" id="lastname" name="lastname" value="" required="required" placeholder="Last Name"> </div> <div class="form-group"> <label for="email" class="hidden">Email</label> <input type="email" class="form-control" id="email" name="email" value="" required="required" placeholder="Email"> </div> <div class="form-group"> <label for="zip" class="hidden">ZIP</label> <input type="text" class="form-control field-half-width" id="zip" name="zip" placeholder="ZIP"> </div> <div class="form-group"> <label for="phone" class="hidden">Phone</label> <input type="text" class="form-control field-half-width" id="phone" name="phone" value="" required="required" placeholder="Phone"> </div> <div class="form-inline"> I will: (uncheck those which you prefer not to do)<br> <input type="checkbox" name="house_party" class="cbox" id="house_party" placeholder="House Party" value="yes" checked><label for="party" type="text" class="special">Host a house party</label> <input type="checkbox" name="canvass" class="cbox" id="canvass" placeholder="Canvass" value="yes" checked><label for="canvass" type="text" class="special">Knock on doors</label><br> <input type="checkbox" name="phonebank" class="cbox" id="phonebank" placeholder="Phonebank" value="yes" checked><label for="phonebank" class="special">Make phone calls</label> <input type="checkbox" name="anything" value="anything" class="cbox" id="any" placeholder="Anything" value="yes" checked><label for="any" class="special">Help with anything you need</label> </div> <div class="form-group"> <label for="comments" class="hidden">Comments</label> <textarea name="comments" id="comments" class="form-control" rows="5" placeholder="Comments"></textarea> </div> <button type="submit" class="btn btn-default" value="Send" id="sendButton">Send</button> </form> <!-- volunteer-form --> This is the stripped down php: <?php ini_set('display_errors', '1'); ?> <?php deleted connection info $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); if (!$link) { die('Could not connect to database: ' . mysqli_error()); } // define variables $firstname = $_POST[firstname]; $lastname = $_POST[lastname]; $email= $_POST; $zip= $_POST[zip]; $phone= $_POST[phone]; $house_party= $_POST[house_party]; $canvass= $_POST[canvass]; $phonebank= $_POST[phonebank]; $anything= $_POST[anything]; $comments= $_POST[comments]; if ($_SERVER[REQUEST_METHOD] == 'POST') if (empty($_POST[firstname])) { $nameErr = 'First name is required'; } else { $firstname = test_input($_POST[firstname]); } // check if name only contains letters and whitespace if (!preg_match('/^[a-zA-Z ]*$/',$firstname)) { $firstnameErr = 'Only letters and white space allowed'; } if ($_SERVER[REQUEST_METHOD] == 'POST') if (empty($_POST[lastname])) { $nameErr = 'Last name is required'; } else { $lastname = test_input($_POST[lastname]); } // check if name only contains letters and whitespace if (!preg_match('/^[a-zA-Z ]*$/',$lastname)) { $lastnameErr = 'Only letters and white space allowed'; } if ($_SERVER[REQUEST_METHOD] == 'POST') if (empty($_POST)) { $emailErr = 'Email is required'; } else { $email = test_input($_POST); } // check if e-mail address is well-formed if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = 'Invalid email format'; } /* Check all form inputs using test_input function */ if ($_SERVER[REQUEST_METHOD] == 'POST') { $firstname = test_input($_POST[firstname]); $lastname = test_input($_POST[lastname]); $email = test_input($_POST); $phone = test_input($_POST[phone]); $comments = test_input($_POST[comments]); } if (isset($_POST['myCheckbox'])) { $checkBoxValue = "yes"; } else { $checkBoxValue = "no"; } if(!empty($_POST['check'])) { foreach($_POST['check'] as $value) { $check_msg .= "Checked:".$value."\n"; } } if (isset($_POST[house_party])) { $anything = 'yes'; } else { $anything = 'no'; } if (isset($_POST[canvass])) { $canvass = 'yes'; } else { $canvass = 'no'; } if (isset($_POST[phonebank])) { $anything = 'yes'; } else { $anything = 'no'; } if (isset($_POST[anything])) { $anything = 'yes'; } else { $anything = 'no'; } $check = isset($_POST[check]) ? $_POST[check] : ''; function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } //inserting data into database if (isset($_POST[firstname], $_POST[lastname], $_POST, $_POST[zip], $_POST[phone], $_POST[house_party], $_POST[canvass], $_POST[phonebank], $_POST[anything], $_POST[comments])){ if ($stmt = $link->prepare('INSERT INTO `volunteerstest`(`firstname`, `lastname`, `email`, `zip`, `phone`, `house_party`, `canvass`, `phonebank`, `anything`, `comments`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)')) { $stmt->bind_param('ssssssssss', $_POST[firstname], $_POST[lastname], $_POST, $_POST[zip], $_POST[phone], $_POST[house_party], $_POST[canvass], $_POST[phonebank], $_POST[anything], $_POST[comments]); if (!$stmt->execute()) { error_log('Execute failed '.$stmt->error); } else { echo 'Data successfully inserted! firstname '.$_POST[firstname].' lastname '.$_POST[lastname].' email '.$_POST.' ZIP '.$_POST[zip].' phone '.$_POST[phone].' house_party '.$_POST[house_party].' canvass '.$_POST[canvass].' phonebank '.$_POST[phonebank].' anything '.$_POST[anything].' and comments '.$_POST[comments].''; } $stmt->close(); } else { echo "data insertion failed"; } } ?>
×
×
  • Create New...