Jump to content
  • Announcements

    • boen_robot

      Guidelines and Netiquette   03/28/2017

      Posting Problems:   Having problems posting your topic? Read through this: To join, you agree to our terms and conditions and fill out and submit a registration form. An activation email will be sent to your email adress, so you'll need to verify your account. After that the account has to be validated by one of the moderators. This will mean that it can take up to a day to be activated. A couple of things to remember to ensure approval: Don't use an email address in one of those $2 four character .com domains eg. xyds.com. These will be deleted and the domain added to the banned list. Don't use an email address that is within a domain with a bad reputation for spam. A Google search is run on every email address and email domain. Don't sign up with an email address that doesn't exist, doesn't work or requires the sender to answer a quiz before their email can get to you. Put your country and or state and city in the signup form. Blank forms will go to the botton of the "to do" list. And make sure that your email address and your country match, saying you're from Alabama and using a .ru email address is not going to get you activated. After a membership is activated the first few posts will be monitored. Posting spam or unapproved topics described in the agreement results in an immediate ban. The email provider and the IP addresses associated with the account will be banned and all posts will be deleted. These strict measures have been deemed necessary to hinder spam. Sorry for any inconvenience this causes, but it's not liable to change. If, after reading this, you still can't post and don't understand why, contact one of the Moderators listed here.   Topic Guidelines   Including the following information can expedite an accurate response from board members: Must be a Specific Problem or Question related to web design and development Include Code in Question (wrap with   for small blocks of code and for longer blocks   ) Include Code Author Include Extra Notes/Modifications/Attempts Include web link to page/file when possible Content Guidelines   You may not post, upload, link to, or email any Content that contains, promotes, gives instruction about, or provides prohibited Content. Prohibited Content includes any Content that breaks any local, state, county, national or international law. Prohibited Content also includes: No direct or indirect advertising or websites, forums, products, services No hijacking of posts (do not post your question in someone elses) Content that infringes upon any rights [ex. MP3s and ROMs] (including, but not limited to, copyrights and trademarks) Abusive, threatening, defamatory, racist, or obscene Viruses or any other harmful computer software False Information or libel Spam, chain letters, or Pyramid schemes Gambling or Illicit drugs Terrorism Hacking or cheating for internet/online games Warez, Roms, CD-Keys, Cracks, Passwords, or Serial Numbers Pornography, nudity, or sexual material of any kind Excessive profanity Invasive of privacy or impersonation of any person/entity Hacking materials or information Posting Tips   There are more BBcodes than there are buttons for on the reply menu. To get the full list, click "BB Code Help" underneath the clickable smilie face menu. Use   for small snippets of code Use   for lengthy snippets of code Use   if your snippet is HTML (optional) Use   if your snippet is SQL (optional) Rules of Conduct   Be nice. There's no need for calling someone stupid if they ask an 'easy' question. Keep your avatars and signatures absolutely child friendly. We have a younger audience on this forum. Keep your language appropriate for the same reason above. Do not PM moderators for help on the forum. Post on the topic, or create a new one.   Spam:   Recently, as you have all without doubt noticed, we have had lots of spam and advertisement on the forum. Therefore, we'd like to alert you as to what to do when you have found any of the aforementioned annoying messages: it. Immediately. Give a clear reason, please, if the advertising is not evident. DO NOT POST! Report, let the post stay as is, and we will get to it, meanwhile if you continue to post as normal in the other threads, it won't be on the top so long. Refrain from PMing the member. This won't help at all, as they are most likely spambots anyway. Thank you.       Images in signatures:   After thinking of users on dial-up, we have decided to enforce the following rules regarding signatures. Please pay heed to them. Respecting these rules is respecting the members on this forum with dial-up. Signature rules: No animated images AT ALL. No matter the amount of animation. Maximum image widthxheight: 300x150 Maximum image (file) size: 15kb Use calm colors. Do not use highly contrasting images in your signature, as this can get really annoying when seeing several posts from one member in the same thread. The same prohibited content goes for images as for posts. Lastly, use common sense. No lengthy signatures please. Save us some scrolling. Thank you.       Links in signatures:   Please understand that w3schools.com only exists because of voluntary work and is barely supported by the advertising littered throughout the tutorials and the forum. So, please, stop advertising other sites. DO not post links that drive traffic away from the w3schools domain - especially to a site that offers similar if not identical information. Please help support the site by keeping individuals on it. Thank you. Here are some guidelines as to what you can put in your signature: w3schools links --> allowed w3.org links --> allowed browser links --> allowed html editor links --> allowed personal sites --> allowed tutorial sites competing with w3schools --> NOT allowed sites completely irrelevant to webprogramming and this forum --> NOT allowed   Thanks for understanding, and for taking the time to read this. ~W3Schools Modstaff~

Empty records created in mysqli via my php script from html form.

Recommended Posts

I suppose the field that stores the phone number is text string type field also? IF it is all numeric only then use a numeric type! Anything else should use a text type field instead.

Share this post

Link to post
Share on other sites

Wow! Cool ! You just "up-sold" me on having to learn AJAX now too LOL!!!  Thanks.. I think ?!?!?!?!

So Far I have the page looking right on the user's side.

The hover drop down button looks pretty

However when I hit submit I get and error message: 

Fatal error: Cannot redeclare test_input() (previously declared in /homepages/42/d547303762/htdocs/w/contactus.php:121) in /homepages/42/d547303762/htdocs/w/contactus.php on line 258


SO.. I will look into AJAX and javascript. THanks


Share this post

Link to post
Share on other sites

You must have this function declared twice somewhere, it can't be declared multiple times, even it is on a external php page that is included into another that declares it also, it will treat it as being previously declared.

Share this post

Link to post
Share on other sites

ok.. Just changed the phone number field to "Varchar" since it gave me an error message when I tried to change it to text. I'm guessing that's a similar thing like "text", and it will still be stripped of unwanted characters by the php function before insertion.

Edited by emcy

Share this post

Link to post
Share on other sites

OK.. looks like I have tons more work to do on this... am going into research mode on w3schools forum to learn about AJAX and declaring the function twice in a php form. 

Thanks.. will check back in soon... Hope you all have a great day



Share this post

Link to post
Share on other sites

Seriously, when people suggest learning and using prepared statements that's not really an idle suggestion.  Your code won't work if people enter certain characters on the form, and it's vulnerable to attack.  If you want to continue learning the bad way to use a database, and write code that contains the #1 attack vector used to attack websites, so that later you have to forget all of that and re-learn the right way that's up to you, but it seems like it makes sense to just learn the right way to start with.

Share this post

Link to post
Share on other sites

HI OK .. am processing.. ....

I have a php page which contains my form.

at one point I have this piece of code.......

if (empty($_POST["join_mailing_list"])) {
    $join_mailing_listErr = "requires a yes or no";
	  $passed = false;
  } else {
    $join_mailing_list = test_input($_POST["join_mailing_list"]);

$first_nameErr = $last_nameErr = $phone_numberErr = $addressErr = $cityErr = $stateErr = $zipErr = $countryErr = $email_addressErr = $commentsErr = $everylistErr = $list1Err = $list2Err = $list3Err = $list4Err = $list5Err = $list6Err = $list7Err = $list8Err = $list9Err = $list10Err = $list11Err = "";

$first_name = $last_name = $phone_number = $address = $city = $state = $zip = $country = $email_address = $comments = $everylist = $list1 = $list2 = $list3 = $list4 = $list5 = $list6 = $list7 = $list8 = $list9 = $list10 = $list11 = "";

 if ($_SERVER["REQUEST_METHOD"] == "POST") { // if connected to the server successfully and it requests info or is ready to receive the info....
$passed = true;
$everylist = test_input($_POST["everylist"]);
$list1 = test_input($_POST["list1"]);
$list2 = test_input($_POST["list2"]);
$list3 = test_input($_POST["list3"]);
$list4 = test_input($_POST["list4"]);
$list5 = test_input($_POST["list5"]);
$list6 = test_input($_POST["list6"]);
$list7 = test_input($_POST["list7"]);
$list8 = test_input($_POST["list8"]);
$list9 = test_input($_POST["list9"]);
$list10 = test_input($_POST["list10"]);
$list11 = test_input($_POST["list11"]);

if ($passed) {

$mysqli = "INSERT INTO mailinglist (first_name, last_name, phone_number, address, city, state, zip, country, email_address, comments, everylist, list1, list2, list3, list4, list5, list6, list7, list8, list9, list10, list11)
 VALUES ('$first_name','$last_name','$phone_number','$address','$city','$state','$zip','$country','$email_address', '$comments','$everylist','$list1','$list2','$list3','$list4','$list5','$list6','$list7','$list8','$list9','$list10','$list11])";

if (mysqli_query($connect, $mysqli)) {
    echo "New record created successfully";
 } else {
    echo "Error: " . $mysqli . "<br>" . mysqli_error($connect);

$email = "info@mygmail.com";
 $emailSubject = "Inquiry from the contact page with Newsletter signup";

 // define what the headers of the email should say
 $headers = "From:$email_address\r\n";
 $headers = "Content-type: text/html\r\n";

 // define what the body of the email should say and look like
 $body = <<<EOD
 First Name : $first_name <br>
 Last Name : $last_name <br>
 Phone Number : $phone_number <br>
 Address : $address <br>
 City : $city <br>
 State : $state <br>
 Zip : $zip <br>
 Country : $country <br>
 Email Address : $email_address <br>
 Comments : $comments <br>
 You have subscribed to the following Newsletters :  // how do I show which ones here?<br>

echo "<h2>Thank you your message was received successfully. Here is a copy of what you sent us:</h2>";
 echo "First Name: " . $first_name . "<br>";
 echo "Last Name: " . $last_name . "<br>";
 echo "Phone Number: " . $phone_number . "<br>";
 echo "Address: " . $address . "<br>";
 echo "City: " . $city . "<br>";
 echo "State: " . $state . "<br>";
 echo "Zip Code: " . $zip . "<br>";
 echo "Country: " . $country . "<br>";
 echo "Email Address: " . $email_address . "<br>";
 echo "Comments: " . $comments . "<br>";
 echo "Joined The following Mailing lists: " . // $how do I show which ones here?;

$first_name = $last_name = $phone_number = $address = $city = $state = $zip = $country = $email_address = $comments = $everylist = $list1 = $list2 = $list3 = $list4 = $list5 = $list6 = $list7 = $list8 = $list9 = $list10 = $list11 = "";
//$mailinglistdatabase = //$first_name','$last_name','$phone_number','$address','$city','$state','$zip','$country','$email_address', //$comments','one',two','three','four'

// The form's html code would go in here?
 // define variables as per what the user has entered on the page I thought, but am told I don't need these so will try to go without. :)
 // $first_name = $_POST['first_name'];
 // $last_name = $_POST['last_name'];
 // $phone_number = $_POST['phone_number'];
 // $address = $_POST['address'];
 // $city = $_POST['city'];
 // $state = $_POST['state'];
 // $zip = $_POST['zip'];
 // $email_address = $_POST['email_address'];
 // $country = $_POST['country'];
 // $comments = $_POST['comments'];
 // $join_mailing_list = $_POST['join_mailing_list'];
 // $name=$_POST['name'];

Do I insert the AJAX as below in place of the above coding?


<div id="mailinglists">
  <h2>Signup for our mailinglists</h2>
  <button type="button" onclick="loadDoc()">show a selection for them to click on and open the boxes</button>

where loadDoc opens a file called "mailinglist" which is the .txt file?


  function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
     document.getElementById("demo").innerHTML = this.responseText;
  xhttp.open("GET", "mailinglist.txt", true);

(do I need to change GET to POST for security reasons?)

and mailinglist.txt is an xml file that looks like this:?


But how do I get the pretty little check boxes for the user to click them open if this is a text file?  Do I need to make it a little php file of it's own to execute at the same time the greater php file executes on submit?  thanks

Share this post

Link to post
Share on other sites

If you're just going to put the contents of the file on the page then it would make sense to have that file contain all of the HTML code to display the checkboxes and whatever else you want.

Share this post

Link to post
Share on other sites

Hi, No, This is what I want to do but haven't found a way to do it with AJAX yet...

1. when a user gets to the point of selecting yes or no for the mailing list.....

     a. if he clicks the "yes" radio button, it will drop down a box where he can select from a number of mailing lists (checkboxes), and that information gets held onto until he clicks"submit" for the entire form

2. Once he clicks submit on the form page, the information goes to these places:

  a. an email of the information goes to me

  b. an email copy of the info goes to the user

  c. all the information with each mailing list selected goes into the mailinglist database

  d. all the information with just a yes/no for the mailinglist question goes to the contactform database

  e. all the info the user entered and the mailinglists he selected gets printed on his browser window with a "success" message

I tried to figure it out in AJAX, but... I can't see how to create the checkboxes in there .  It seems like its more for static information, not interactivity.

other ideas? or did I miss something?




Share this post

Link to post
Share on other sites

I'm wondering why you're using ajax at all.  Why is it necessary to send an ajax request at all to display the checkboxes?  Why not start with that information on the page already, just hidden, and when they click the button it shows the other content?  Why add ajax as a requirement for that?  But, even if you do want to use ajax, I don't see what problem you're having.  Like I said above, it would make sense to have the checkbox file on your server just contain all of the HTML code, so you send the ajax request, get that code, and put it on the page.  You said "no" to that, so why?  That's the easiest way to do that, so why "no?"  Do you just want to make things more complex than they need to be?  And then what if they click the Yes button, but then later click the No button, what do you want to do with the list?  Without ajax all you would need to do is hide that element again, so again, I don't know why you think you need to use ajax for this.  Everything that happens when the form is submitted can be done with PHP on the server, that is separate from building the form.  

Share this post

Link to post
Share on other sites

HI, in the interest of this post about the contact form not being mixed up with my mailing list hover button/radio button issue.. how do I move my mailinglist topic question and your responses for it to another post?  Thanks


Share this post

Link to post
Share on other sites

Dear ModeraterJustsomeguy, I would like to humbly request that the latter portion of this initial contact form page issue, about the mailinglist issue, be moved to a new topic.  Would you please, kindly consider moving it over?   I feel concerned about the two issues mixing in your search field, and the forum page getting tooooooo long and confusing for other info seekers.  Thank you for taking the time and I hope you have a wonderful day :)   (thanks tons for the help :)


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now