Jump to content
emcy

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

 

B

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
 <br><hr><br>
 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>
<br>
EOD;

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?

i.e.  

<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>
</div>

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

and

<script>
  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);
  xhttp.send();
}
</script>

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

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

everylist
list1
list2
list3
list4
list5
list6
list7
list8
list9
list10
list11

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?

 

THanks

B

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

B

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 :)

B

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

×