Jump to content

mike3075

Members
  • Content Count

    11
  • Joined

  • Last visited

Community Reputation

0 Neutral

About mike3075

  • Rank
    Member
  1. Thank all of you that responded so quickly. For now, I just used the code from another form instead of using the function to populate the select box so I could get the form up and running. It's bulk but it works for now. When I gain more experience and knowledge I will go back and work on it. Again, thanks to everyone for the advice and suggestions!
  2. mac_gyver, to be honest with you your 2nd paragraph went over my head. I have a select box on another form that works fine <select class="myselectbox" name="varposition" id="varposition" tabindex="5"><option value="" selected disabled>Select one...</option><option value="Chaperone" <?php if (isset($varposition) && $varposition == "Chaperone") echo "selected" ?>>Chaperone</option><option value="Class Monitor" <?php if (isset($varposition) && $varposition == "Class Monitor") echo "selected" ?>>Class Monitor</option></select> I suppose I could modify it for each state, but I has hoping there would be an easier way
  3. Thank you both for the quick response. I tried changing the While statement in the function to following, but it didn't work. It still did the same thing. while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) { $rec = $row['name']; echo "<option value = " . $row['name']. " if (isset($varfatherbirthstate) && $varfatherbirthstate == " . $row['name']. ") echo 'selected' >" . $row['name']. "</option>"; } Please forgive me if I'm way off on this. I am still fairly new to PHP
  4. I have a select box on a form that is populated with the following function: function getStates(){ // OPEN CONNECTION TO MYSQL ON LOCALHOST $dbhost = 'localhost' ; $username = 'root' ; $password = '' ; $conn = mysqli_connect("$dbhost", "$username", "$password"); if (!$conn) { die('Could not connect: ' . mysqli_error()); } mysqli_select_db($conn, "mydb"); $retval = mysqli_query($conn, "SELECT * FROM tblstates") or die("Error: " . mysqli_error($conn)); echo "<option value=''>Select one...</option>"; while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) { $rec = $row['name']; echo "<option value = " . $row['name']. ">"; echo $row['name']; echo "</option>"; } } On the form I have several text boxes and the following select box: <div class="formfieldgroup"> <label class="label">Birth State/Country: <span class="required">&#149;</span></label> <select class="fatherbirthstate" name="varfatherbirthstate" tabindex="9"><?=getStates()?></select> <span class="form-error2"><?= $varfatherbirthstateErr ?></span> </div> TESTING: I intentionally leave a text box blank so I will get an error and I make sure to make a selection from the select box. PROBLEM: When the form is submitted, the select box doesn't retain the value selected and is reset to "Select one..." QUESTION: How do I go about retaining the selected value when the form errors?
  5. Here is the code I have to process a contact form: <?php // DEFINE VARIABLE AND SET EMPTY VALUES $varfnameErr = $varlnameErr = $varemailErr = $varphoneErr = $varmessageErr = ""; $varfname = $varlname = $varemail = $varphone = $varmessage = $varipaddress = $formerror = $success = ""; $varfnameErr = $_REQUEST['varfnameErr'] ; $varlnameErr = $_REQUEST['varlnameErr'] ; $varemailErr = $_REQUEST['varemailErr'] ; $varphoneErr = $_REQUEST['varphoneErr'] ; $varmessageErr = $_REQUEST['varmessageErr'] ; $varfname = $_REQUEST['varfname'] ; $varlname = $_REQUEST['varlname'] ; $varemail = $_REQUEST['varemail'] ; $varphone = $_REQUEST['varphone'] ; $varmessage = $_REQUEST['varmessage'] ; $varipaddress = $_REQUEST['varipaddress'] ; $message = '<html><body>'; $message .= '<p>Form submitted by: ' .$varfname. ' ' .$varlname. '</p>'; $message .= '<p>Email: ' .$varemail. '</p>'; $message .= '<p>Phone Number: ' .$varphone. '</p>'; $message .= '<p>Message: ' .$varmessage. '</p>'; $message .= '<p>IP Address: ' .$varipaddress. '</p>'; $message .= '</body></html>'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require $_SERVER['DOCUMENT_ROOT'] . '/mail/Exception.php'; require $_SERVER['DOCUMENT_ROOT'] . '/mail/PHPMailer.php'; require $_SERVER['DOCUMENT_ROOT'] . '/mail/SMTP.php'; $mail = new PHPMailer; $mail->isSMTP(); $mail->SMTPDebug = 2; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages $mail->Host = "HostIsBlueHost"; // use $mail->Host = gethostbyname('smtp.gmail.com'); // if your network does not support SMTP over IPv6 $mail->Port = 21; // TLS only $mail->SMTPSecure = 'tls'; // ssl is deprecated $mail->SMTPAuth = true; $mail->Username = 'info@aacroofing.org'; // email $mail->Password = 'PasswordWasHere'; // password $mail->setFrom($varemail); // From email and name $mail->addAddress('test@gmail.com'); // to email and name $mail->Subject = 'Contact Us Form Submission'; $mail->msgHTML($message); //$mail->msgHTML(file_get_contents('contents.html'), __DIR__); //Read an HTML message body from an external file, convert referenced images to embedded, $mail->AltBody = 'HTML messaging not supported'; // If html emails is not supported by the receiver, show this body //$mail->addAttachment('images/phpmailer_mini.png'); //Attach an image file $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); if(!$mail->send()){ echo "Mailer Error: " . $mail->ErrorInfo; }else{ $success = "<p class='success'>Message sent! Thank you!</br>IP Address: " .$varipaddress. " recorded</p>"; $varfname = $varlname = $varemail = $varphone = $varmessage = ""; } ?> When the form is completed and submitted this is the error that I get. I have no idea what this means. If someone understands the error, could you please give me a clue? 2020-03-08 19:48:46 SERVER -> CLIENT: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------220-You are user number 1 of 150 allowed.220-Local time is now 13:48. Server port: 21.220-IPv6 connections are also welcome on this server.220 You will be disconnected after 15 minutes of inactivity. 2020-03-08 19:48:46 CLIENT -> SERVER: EHLO aacroofing.org 2020-03-08 19:48:46 SERVER -> CLIENT: 530 You aren't logged in 2020-03-08 19:48:46 SMTP ERROR: EHLO command failed: 530 You aren't logged in 2020-03-08 19:48:46 CLIENT -> SERVER: HELO aacroofing.org 2020-03-08 19:48:46 SERVER -> CLIENT: 530 You aren't logged in 2020-03-08 19:48:46 SMTP ERROR: HELO command failed: 530 You aren't logged in 2020-03-08 19:48:46 CLIENT -> SERVER: STARTTLS 2020-03-08 19:48:46 SERVER -> CLIENT: 530 You aren't logged in 2020-03-08 19:48:46 SMTP ERROR: STARTTLS command failed: 530 You aren't logged in SMTP Error: Could not connect to SMTP host. 2020-03-08 19:48:46 CLIENT -> SERVER: QUIT 2020-03-08 19:48:46 SERVER -> CLIENT: 221-Goodbye. You uploaded 0 and downloaded 0 kbytes.221 Logout. SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
  6. Ginerjm, that worked! Thank you very much! requinix, I will create a test page using PHPMailer. Thank you both for your suggestions!
  7. It's not. I will change it and see what happens. Thank you
  8. Thank you for the quick response. I will give it a shot
  9. I really need some help. I am very new to PHP and I've been stuck for a couple of days. I created a contact form and everything seems to be working correctly, except the mail is showing it's sent, but I never receive an email in my Inbox or Spam folder. Can someone please review my code? Here is the PHP: <?php // DEFINE VARIABLE AND SET EMPTY VALUES $varfnameErr = $varlnameErr = $varemailErr = $varphoneErr = $varpositionErr = ""; $varfname = $varlname = $varemail = $varphone = $varposition = $success = ""; //FORM SUBMITTED WITH POST METHOD if ($_SERVER["REQUEST_METHOD"] == "POST") { //VALIDATE FIRST NAME if (empty($_POST["varfname"])) { $varfnameErr = "First Name is required"; } else { $varfname = test_input($_POST["varfname"]); // MAKE SURE FIRST NAME ONLY CONTAINS LETTERS AND WHITE SPACE if (!preg_match("/^[a-zA-Z ]*$/",$varfname)) { $varfnameErr = "Only letters and white space are allowed"; } } //VALIDATE LAST NAME if (empty($_POST["varlname"])) { $varlnameErr = "Last Name is required"; } else { $varlname = test_input($_POST["varlname"]); // MAKE SURE LAST NAME ONLY CONTAINS LETTERS AND WHITE SPACE if (!preg_match("/^[a-zA-Z ]*$/",$varlname)) { $varlnameErr = "Only letters and white space are allowed"; } } //VALIDATE EMAIL ADDRESS if (empty($_POST["varemail"])) { $varemailErr = "Email Address is required"; } else { $varemail = test_input($_POST["varemail"]); // MAKE SURE EMAIL ADDRESS IS FORMATTED CORRECTLY if (!filter_var($varemail, FILTER_VALIDATE_EMAIL)) { $varemailErr = "Invalid email address format"; } } //VALIDATE PHONE NUMBER if (empty($_POST["varphone"])) { $varphoneErr = "Phone number is required"; } else { $varphone = test_input($_POST["varphone"]); // MAKE SURE PHONE NUMBER IS IN CORRECT FORMAT if (!preg_match("/^(\d[\s-]?)?[\(\[\s-]{0,2}?\d{3}[\)\]\s-]{0,2}?\d{3}[\s-]?\d{4}$/i",$varphone)) { $varphoneErr = "Invalid telephone format"; } } //VALIDATE POSITION if (empty($_POST["varposition"])) { $varpositionErr = "Position is required"; } else { $varposition = test_input($_POST["varposition"]); } //IF ALL DATA IS CORRECT if ($varfnameErr == '' and $varlnameErr == '' and $varemailErr == '' and $varphoneErr == '' and $varpositionErr == '') { $message_body = ''; unset($_POST['submit']); //THIS IS JUST FOR TESTING PURPOSES $message_body = $varfname; //foreach ($_POST as $key => $value) { // $message_body .= "$key: $value\n"; //} $to = 'mygmail@gmail.com'; $subject = 'Volunteer Form Submission'; $message = wordwrap($message_body, 70); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= "From: " . $varemail . "\r\n"; $subject = 'Volunteer Form Submission'; $to = 'mygmail@gmail.com'; $result = mail($to, $subject, $message, $headers); //THIS RETURNS "1" print $result; //IF ALL DATA IS CORRECT MAKE SURE EMAIL WAS SENT if (mail($to, $subject, $message, $headers)) { $success = "Message sent. Thank you contacting us! We will reply as soon as possible."; $varfname = $varlname = $varemail = $varphone = $varposition = ""; } else { $success = "Something went wrong!"; } } } //STRIP UNWANTED CHARACTERS FROM VARIABLES function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> Here is the HTML: <div class="row regformrow"> <div class="coffee-span-12 regformcolumn"> <div class="subgrid regformsubgrid"> <div class="row regformsubgridheaderrow"> <div class="coffee-span-12 regformsubgridheadercolumn"> <h4 class="regformsubgridheadertitle">Volunteer Form</h4> </div> </div> <div class="row regformsubgridrow"> <form class="form-container regformsubgridformcontainer" action=<?= $_SERVER['PHP_SELF']; ?> method="post"> <div class="coffee-span-4 coffee-972-span-6 coffee-458-span-12 regformsubgridcolumn1"> <div class="container regformsubgridcontainer1"> <label class="label form-label-all"><span style="font-style:italic;color:#FF5454;">* Required Fields</span></label></br> <div class="formfieldgroup"> <input class="fname" name="varfname" type="text" tabindex="1" placeholder="First Name" value="<?= $varfname; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varfnameErr ?></span> </div> <div class="formfieldgroup"> <input class="lname" name="varlname" type="text" tabindex="2" placeholder="Last Name" value="<?= $varlname; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varlnameErr ?></span> </div> <div class="formfieldgroup"> <input class="email" name="varemail" type="text" tabindex="2" placeholder="Email Address" value="<?= $varemail; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varemailErr ?></span> </div> <div class="formfieldgroup"> <input class="phone" name="varphone" type="text" tabindex="2" placeholder="Telephone Number" value="<?= $varphone; ?>"><span class="requiredfield"> *</span> <span class="form-error"><?= $varphoneErr ?></span> </div> <div class="formfieldgroup"> <select class="select selectbox" name="varposition" id="varposition" tabindex="5"><option value="">Select one...</option><option value="Chaperone">Chaperone</option><option value="Class Monitor">Class Monitor</option><option value="Parking Attendant">Parking Attendant</option><option value="Party Coordinator">Party Coordinator</option><option value="Teacher Aid">Teacher Aid</option></select><span class="requiredfield"> *</span> <span class="form-error"><?= $varpositionErr ?></span> </div> <div class="formfieldgroup"> <input class="test" name="test" type="text" tabindex="6" placeholder="If you are human, leave this field blank" value=""> </div> <div class="formfieldgroup"> <button type="submit" class="button-submit-1" name="submit" tabindex="7" data-submit="...Sendng">Submit</button> </div> <div class="formfieldgroup"> <div class="success"><?= $success; ?></div> </div> </div> </div> </form> </div> </div> </div> </div>
  10. I have only been working with PHP for about a week, so please be patient. I need to convert the following ASP Classic code to PHP. I have the SQL partially working. <label>Select a bulletin:</label> <select> <option value="">Select One</option> <?php $servername = "localhost"; $username = "username"; $password = "password"; $conn = new mysqli($servername, $username, $password); if (!$conn) { die('Could not connect: ' . mysql_error()); } $sql = "SELECT bulletinid, bulletindate, bulletinlink, bulletintext FROM tblbulletins"; mysql_select_db(MyDB); $retrieved = mysql_query( $sql, $conn ); if(! $retrieved ) { die('Could not get data: ' . mysql_error()); } while($row = mysql_fetch_array($retrieved, MYSQL_ASSOC)) { $bullentinid = $row['bulletinid']; $bullentindate = $row['bulletindate']; $bullentinlink = $row['bulletinlink']; echo $link; } mysql_close($conn); ?> </select> The records that are retrieved are: | 01 | 05/01/19 - 05/07/19 | link 1 | <embed src="bul/05-01.pdf#"> | | 02 | 05/08/19 - 05/14/19 | link 2 | <embed src="bul/05-08.pdf#"> | | 03 | 05/15/19 - 05/21/19 | link 3 | <embed src="bul/05-15.pdf#"> | The problem I'm having is converting line 10 in ASP Classic to PHP: 01. <% Function bulletins %> 02. <% sSQL = "SELECT bulletinid, bulletindate, bulletinlink, bulletintext FROM tblbulletins ORDER BY bulletinid" %> 03. <% Set oRecordSet = adoCon.Execute(sSQL) %> 04. <% If Not oRecordSet.EOF Then %> 05. <% arrayResult1 = oRecordSet.GetRows() %> 06. <% End If %> 07. <% Set oRecordSet = Nothing %> 08. <% iRowNumber1 = ubound(arrayResult1,2) %> 09. <% For iCounter1= 0 to iRowNumber1 %> 10. <% Response.Write ("<option value="pg01.php?mode=view&ID=<%=arrayResult1(0,iCounter1)%>"><% = arrayResult1(1,iCounter1) %></option>") 11. <% Next %> 12. <% End Function %> 13. <% 'arrayResult1(0,iCounter1) = bulletinid %> 14. <% 'arrayResult1(1,iCounter1) = bulletindate %> 15. <% 'arrayResult1(2,iCounter1) = bulletinlink %> 16. <% 'arrayResult1(3,iCounter1) = bulletintext %> 17. <label>Select bulletin:</label> 18. <select> 19. <% Call bulletins %> 20. </select> Once the link was clicked, it would open pg01.php to the specific saint that was selected. Here is the ASP Classic code on pg01.asp that needs to be converted to PHP: <% IF Request.querystring("mode") = "view" THEN %> <% Session("bulletinid") = Request.querystring("ID") %> <% bulletinID = Clng(Session("bulletinID")) %> <% sSQL = "SELECT * FROM tblbulletins WHERE bulletinid = " & bulletinID %> <% Set oRecordSet = adoCon.Execute(sSQL) %> <% IF Not oRecordSet.EOF THEN %> <% arrayResult = oRecordSet.GetRows() %> <% END IF %> <% END IF %> <% Set oRecordSet = Nothing %> <div class="main"> <h4><% =arrayResult(1,0) %></h4> <p><%=arrResultSet(4,0)%></p> </div>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.