mike3075
Members-
Posts
18 -
Joined
-
Last visited
Profile Information
-
Gender
Male
-
Location
Texas
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
mike3075's Achievements
Member (2/5)
1
Reputation
-
Help with an update query using a$_SESSION variable
mike3075 replied to mike3075's topic in PHP Coding Help
mac_gyver & gizmola- Thank you both for all help. I apologize if I didn't fully understand your responses. I'm fairly new to php and obviously have a lot to learn. So, I went back over both threads several times and finally gasped what you were both saying. I got everything working now. Again, thank you both for all of your assistance -
I'm trying to run the following update query, but I keep getting the error message: Parse error: syntax error, unexpected string content "", expecting "-" or identifier or variable or number in C:\xampp\htdocs\myreliantservices\samplepage1reworkinclude.php on line 55 $sql1 = "UPDATE cd006ccals SET ccalcourt = $_SESSION['vartestccalcourt' . $i] WHERE ccalid = ".$key; I've tried the following without any success: ccalcourt = " . $_SESSION['vartestccalcourt' . $i] . " ccalcourt = ' . $_SESSION['vartestccalcourt' . $i] . ' ccalcourt = '$_SESSION["vartestccalcourt" . $i]' ccalcourt = '($_SESSION['vartestccalcourt' . $i])'
-
mac_gyver & gizmola- Thank you both for all the helpful suggestions and recommendations and for helping solve this issue. I got the code working after rereading both your posts. I now have the array being passed to my include page where I can start working on extracting the data from the array to run the update query
-
mac_guyer- Thank you for the quick response! I tried your suggestion. For this example lets says the ccalid = 442 <div class='ccalbox ccalcourt-textarea'><textarea class='ccalcourt-somebad' name='court[{$data['ccalid']}]'>" .$data['ccalcourt']. "</textarea></div> <div class='ccalbox ccalcourt-textarea'><textarea class='ccaljudge-somebad' name='judge[{$data['ccalid']}]'>" .$data['ccaljudge']. "</textarea></div> <div class='ccalbox ccalcourt-textarea'><textarea class='ccaladdress-somebad' name=address[{$data['ccalid']}]>" .$data['ccaladdress']. "</textarea></div> <div class='ccalbox ccalcourt-textarea'><textarea class='ccalphone-somebad' name=phone[{$data['ccalid']}] >" .$data['ccalphone']. "</textarea></div> <div class='ccalbox ccalcourt-textarea'><textarea class='ccalfax-somebad' name=fax[{$data['ccalid']}] >" .$data['ccalfax']. "</textarea></div> <div class='ccalbox ccalcourt-textarea'><textarea class='ccalnotes-somebad' name=notes[{$data['ccalid']}] >" .$data['ccalnotes']. "</textarea></div> Then run this code when the Submit button is pressed: if ($_SERVER["REQUEST_METHOD"] == "POST") { $field_names = array_keys($_POST); echo "<h2>POST Form Field Names:</h2>"; echo "<ul>"; foreach ($_POST as $fieldName => $Value) { echo "<li>" . htmlspecialchars($fieldName) . "</li>"; } echo "</ul>"; /* include 'samplepage1reworkinclude.php';*/ } It returns: POST Form Field Names: court judge address phone fax notes submit Shouldn't it return: POST Form Field Names: court442 judge442 address442 phone442 fax442 notes442 submit442
-
I have a form on my samplepage1.php page. One part of the form needs to have the name attributes named dynamically because there could 1 to 25 rows in the table that are retrieved by the query and display them. This part is working fine. When I submit the form, it goes to samplepage1viewinclude.php and it's supposed to run updates queries to update the information the user changed. I can't figure out how to dynamically declare the variables, then set the variables equal to a $_REQUEST[] value from the form and then run the update query. Being that there could be 6 to 150 variable names and form name attirbutes, depending on how rows the query returned, I thought this would be the best way to name the variables and name attributes. Any advice, suggestions or recommendations will be greatly appreciated Here is the code for samplepage1.php queries the DB, then displays the data where the user can either view the results or make changes and submit them: <?php //==============================================================================================================================// //==OPEN CONNECTION TO MYSQL ON LOCALHOST ======================================================================================// $dbhost = 'localhost' ; $username = 'some username' ; $password = 'blahblahblah' ; $conn = mysqli_connect("$dbhost", "$username", "$password"); if (!$conn) { die('Could not connect: ' . mysqli_error()); } mysqli_select_db($conn, "courtdirectory"); //==============================================================================================================================// //==DO THIS WHEN FORM IS SUBMITTED==============================================================================================// if ($_SERVER["REQUEST_METHOD"] == "POST") { if (isset($_POST['submit'])){ include('samplepage1viewinclude.php'); } } echo " <form class='form-container form' action= " .$_SERVER['PHP_SELF']. " method='post'>"; //==============================================================================================================================// // - FOR THIS EXAMPLE THERE ARE 2 ROWS IN THE CCAL TABLE WITH CCALCOUNTYID = 221 //==============================================================================================================================// //==============================================================================================================================// // - FOR EACH CCALCOUNTYID THERE COULD BE 1 TO 25 ROWS RETRIEVED DEPENDING ON THE COUNTY THAT IS WHY I USED THE FOREACH LOOPS // TO NAME THE VARAIABLES AND FORM FIELD NAMES //==============================================================================================================================// $sql1 = "SELECT * FROM cd006ccals WHERE cd006ccals.ccalcountyid = 221"; $results1 = mysqli_query($conn, $sql1); $datas = array(); if (mysqli_num_rows($results1) > 0) { while($row = $results1->fetch_assoc()) { $datas[] = $row; } } $index = 1; foreach($datas as $data) { ${"varccal".$index."id"} = $data['ccalid']; ${"varccal".$index."countyid"} = $data['ccalcountyid']; ${"varccal".$index."court"} = $data['ccalcourt']; ${"varccal".$index."judge"} = $data['ccaljudge']; ${"varccal".$index."address"} = $data['ccaladdress']; ${"varccal".$index."phone"} = $data['ccalphone']; ${"varccal".$index."fax"} = $data['ccalfax']; ${"varccal".$index."notes"} = $data['ccalnotes']; echo " <div class='ccalboxgrid'> <div class='ccalbox ccalcourt'>Court Type</div> <div class='ccalbox ccaljudge'>Judge</div> <div class='ccalbox ccaladdress'>Address</div> <div class='ccalbox ccalphone'>Phone</div> <div class='ccalbox ccalfax'>Fax</div> <div class='ccalbox ccalnotes'>Notes</div> <div class='ccalbox ccalcourt-textarea'><textarea class='ccalcourt-somebad' name=${"varccal".$index."court"} value=${"varccal".$index."court"}>${"varccal".$index."court"}</textarea></div> <div class='ccalbox ccaljudge-textarea'><textarea class='ccaljudge-somebad' name=${"varccal".$index."judge"} value=${"varccal".$index."judge"}>${"varccal".$index."judge"}</textarea></div> <div class='ccalbox ccaladdress-textarea'><textarea class='ccaladdress-somebad' name=${"varccal".$index."address"} value=${"varccal".$index."address"}>${"varccal".$index."address"}</textarea></div> <div class='ccalbox ccalphone-textarea'><textarea class='ccalphone' name=${"varccal".$index."phone"} value=${"varccal".$index."phone"}>${"varccal".$index."phone"}</textarea></div> <div class='ccalbox ccalfax-textarea'><textarea class='ccalfax' name=${"varccal".$index."fax"} value=${"varccal".$index."fax"}>${"varccal".$index."fax"}</textarea></div> <div class='ccalbox ccalnotes-textarea'><textarea class='ccalnotes' name=${"varccal".$index."notes"} value=${"varccal".$index."notes"}>${"varccal".$index."notes"}</textarea></div> </div>"; $index++; } echo " <div class='formfieldgroup'> <button type='submit' class='courtdirectory-submit' name='submit' tabindex='6' data-submit='...Sendng'>Update</button> </div>"; echo " </form>"; ?> IF the user changes any data on samplepage1.php and hits the Submit button, the sample1viewinclude.php code runs. This is where I'm getting the errors. Here is the code for saple1viewinclude.php: <?php //==============================================================================================================================// // - FOR THIS EXAMPLE THERE ARE 2 ROWS IN THE CCAL TABLE WITH CCALCOUNTYID = 100 //==============================================================================================================================// $mycountyid = $this_id = ""; /* $index = 1; echo "TEST TO SEE IF CCALCOURT VALUE IS RETURNED: " . $_REQUEST['varccal'.$index.'court']; */ //==============================================================================================================================// // HERE IS THE CODE I HAVE TRIED SO FAR, BUT I KEEP GETTING ERRORS //==============================================================================================================================// //==============================================================================================================================// // QUERYING CCAL TABLE TO GET THE NUMBER OF ROWS RETRIEVED $mycountyid = "221"; $sql1 = "SELECT * FROM cd006ccals WHERE cd006ccals.ccalcountyid = " . $mycountyid; $results1 = mysqli_query($conn, $sql1); $datas = array(); if (mysqli_num_rows($results1) > 0) { while($row = $results1->fetch_assoc()) { $datas[] = $row; } } //==============================================================================================================================// // START LOOPING THROUGH THE RESULTS TO SET VARIABLES AND GET FORM FIELD ENTRIES FROM SAMPLEPAG1.PHP; THIS ALSO SETS THE VALUE // FOR $THIS_ID TO BE USED FOR THE UPDATE QUERY //==============================================================================================================================// $index = 1; foreach($datas as $data) { $this_id = $data['ccalid']; ${"varccal".$index."id"} = ""; ${"varccal".$index."countyid"} = ""; ${"varccal".$index."court"} = ""; ${"varccal".$index."judge"} = ""; ${"varccal".$index."address"} = ""; ${"varccal".$index."phone"} = ""; ${"varccal".$index."fax"} = ""; ${"varccal".$index."notes"} = ""; //==============================================================================================================================// // THE LINES BELOW ARE WHERE THE ERRORS START //==============================================================================================================================// ${"varccal".$index."court"} = $_REQUEST['varccal'.$index.'court']; ${"varccal".$index."judge"} = $_REQUEST['varccal'.$index.'judge']; ${"varccal".$index."address"} = $_REQUEST['varccal'.$index.'address']; ${"varccal".$index."phone"} = $_REQUEST['varccal'.$index.'phone']; ${"varccal".$index."fax"} = $_REQUEST['varccal'.$index.'fax']; ${"varccal".$index."notes"} = $_REQUEST['varccal'.$index.'notes']; //==============================================================================================================================// //==============================================================================================================================// //==============================================================================================================================// /* HERE THE ERRORS I KEEP GETING FROM THE 6 LINES OF CODE ABOVE Warning: Undefined array key "varccal1court" in C:\xampp\htdocs\myreliantservices\samplepage1viewinclude.php on line 55 Warning: Undefined array key "varccal1judge" in C:\xampp\htdocs\myreliantservices\samplepage1viewinclude.php on line 56 Warning: Undefined array key "varccal1address" in C:\xampp\htdocs\myreliantservices\samplepage1viewinclude.php on line 57 Warning: Undefined array key "varccal1phone" in C:\xampp\htdocs\myreliantservices\samplepage1viewinclude.php on line 58 Warning: Undefined array key "varccal1fax" in C:\xampp\htdocs\myreliantservices\samplepage1viewinclude.php on line 59 Warning: Undefined array key "varccal1notes" in C:\xampp\htdocs\myreliantservices\samplepage1viewinclude.php on line 60 Warning: Undefined array key "varccal2court" in C:\xampp\htdocs\myreliantservices\samplepage1viewinclude.php on line 55 Warning: Undefined array key "varccal2judge" in C:\xampp\htdocs\myreliantservices\samplepage1viewinclude.php on line 56 Warning: Undefined array key "varccal2address" in C:\xampp\htdocs\myreliantservices\samplepage1viewinclude.php on line 57 Warning: Undefined array key "varccal2phone" in C:\xampp\htdocs\myreliantservices\samplepage1viewinclude.php on line 58 Warning: Undefined array key "varccal2fax" in C:\xampp\htdocs\myreliantservices\samplepage1viewinclude.php on line 59 Warning: Undefined array key "varccal2notes" in C:\xampp\htdocs\myreliantservices\samplepage1viewinclude.php on line 60 Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' ccaljudge = , ccaladdress = , ccalphone = ...' at line 2 in C:\xampp\htdocs\myreliantservices\samplepage1viewinclude.php:118 Stack trace: #0 C:\xampp\htdocs\myreliantservices\samplepage1viewinclude.php(120): mysqli->query('UPDATE ccal SET...') #1 C:\xampp\htdocs\myreliantservices\samplepage1.php(43): include('C:\\xampp\\htdocs...') #2 {main} thrown in C:\xampp\htdocs\myreliantservices\samplepage1viewinclude.php on line 120 */ //==============================================================================================================================// $sql2 = "UPDATE ccal SET ccalcourt = ${"varccal".$index."court"}, ccaljudge = ${"varccal".$index."judge"}, ccaladdress = ${"varccal".$index."address"}, ccalphone = ${"varccal".$index."phone"}, ccalfax = ${"varccal".$index."fax"}, ccalnotes = ${"varccal".$index."notes"} WHERE ccalid = ".$this_id; $index++; } //==============================================================================================================================// // END LOOP //==============================================================================================================================// //==============================================================================================================================// // DISPLAY SUCCESS OR ERROR MESSAGE WHEN EVERYTHING IS DONE RUNNING //==============================================================================================================================// //==============================================================================================================================// /* GET THE FOLLOWING ERROR BECAUSE THE VARIABLES ARE BEING SET IN THE UPDATE QUERY */ if ($conn->query($sql2) === TRUE) { $success = "<p class='success'>Record updated successfully</p>"; /* $varid = $varcounty = ""; */ } else { echo "Error updating record: " . $conn->error; } ?>
-
First, I want to thank everyone for their time, suggestions and recommendations. Here are my responses to your questions, suggestions and recommendations: requinix: The “id” is not display after I click the Update button Pixeel: I honestly didn’t give the GET and POST methods much consideration. I will correct that. I didn’t realize I left MySQL credentials in the code I posted. Thank you for catching that! ginerjm: I think there were duplicate queries and not using the results is because I was trying different things and didn’t delete or comment out the old code Thank you for cleaning update the code for me. It is way easier to read now. The reason there are 3 separate tables right now is because the rows will eventually be color coded and I didn’t feel like bothering with the CSS right now The query will eventually only generate one row Pixeel: I will remove the extra queries and insert the validation. For right now though I know there should be certain data returned from MySQL DB. This merely for testing. Once everything is working I will insert the validation I will rename the variables as I go along ginerjm: I never really thought about leaving the ‘var’ off. I always thought it was easier to find the variables if ‘var’ was in front it Ultimately, when a user changes data and clicks Update it will update the DB. I set all the inputs to ‘textarea’ just so everything would be vertically aligned to the top
-
I am stuck on this form. I can use <a href='courtdirectoryview.php?id={$row['id']}' target='_blank'> to pass the id number from courtdirectory.php to courtdirectoryview.php and all the data from the MySQL db is displayed correctly. When I make changes to test the update query and I click the Update button I get the error in the title. Line 42 is: echo "WHY DOES THE ID NUMBER NOT SHOW UP HERE WHEN THE UPDATE BUTTON IS CLICKED: " .$_GET['id']. "<br>"; Any suggestions or advice will be greatly appreciated <!DOCTYPE html> <head> <link rel="stylesheet" href="css/main-forcourtdirectory.css"> </head> <?php //============================================================================================================================================================================================/ //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()); } //CLOSE CONNECTION TO MYSQL ON LOCALHOST======================================================================================================================================================/ //============================================================================================================================================================================================/ //============================================================================================================================================================================================/ //OPEN CONNECTION TO MYSQL ON LOCALHOST=======================================================================================================================================================/ mysqli_select_db($conn, "courtdirectory"); //CLOSE CONNECTION TO MYSQL ON LOCALHOST======================================================================================================================================================/ //============================================================================================================================================================================================/ //============================================================================================================================================================================================/ // DEFINE VARIABLES AND SET EMPTY VALUES======================================================================================================================================================/ // PROSECUTOR VARIABLES=======================================================================================================================================================================/ $varprosecutor = $varprosecutoraddress = $varprosecutorphone = $varprosecutorfax = $varprosecutornotes = ""; //============================================================================================================================================================================================/ // PROSECUTOR ERROR VARIABLES=================================================================================================================================================================/ $varprosecutorErr = $varprosecutoraddressErr = $varprosecutorphoneErr = $varprosecutorfaxErr = $varprosecutornotesErr = ""; //============================================================================================================================================================================================/ // OTHER VARIABLES============================================================================================================================================================================/ $varmyid = $varipaddress = $formerror = $success = ""; //============================================================================================================================================================================================/ //============================================================================================================================================================================================/ //FORM SUBMITTED WITH POST METHOD=============================================================================================================================================================/ if ($_SERVER["REQUEST_METHOD"] == "POST") { //============================================================================================================================================================================================/ echo "WHY DOES THE ID NUMBER NOT SHOW UP HERE WHEN THE UPDATE BUTTON IS CLICKED: " .$_GET['id']. "<br>"; //==========================================================================================================================================================================================/ //START UPDATE SQL==========================================================================================================================================================================/ //NONE OF THIS CODE WILL WORK UNTIL I CAN GET THE ID NUMBER=================================================================================================================================/ //$result2 = mysqli_query($conn, "UPDATE courtdirectory SET prosecutor='$varprosecutor' WHERE courtdirectory.id = ($myid)") or die("Error: " . mysqli_error($conn)); //$retval3 = mysqli_query($conn, $result2); //if (mysqli_query($conn, $result2)) { // echo "Record updated successfully"; //} else { // echo "Error updating record: " . mysqli_error($conn); //} //END UPDATE SQL============================================================================================================================================================================/ //==========================================================================================================================================================================================/ }else{ if (isset($_GET['id'])) { $myid = $_GET['id']; $varmyid = $myid; } echo "I CAN GET THE ID NUMBER FROM THE COURTDIRECTORY.PHP PAGE: " .$myid. "<br>"; echo "I CAN SET THIS VARIABLE TO THE THE ID NUMBER: " .$varmyid. "<br>"; echo "<body>"; if (isset($_GET['id'])) { $myid = $_GET['id']; } $bulletinsQuery = "SELECT * FROM courtdirectory"; $bulletins = $conn->query($bulletinsQuery); if (isset($_GET['id'])) { $myid = $_GET['id']; } echo "<form action= " .$_SERVER['PHP_SELF']. " method='post'>"; echo "<table class='courtdirectorytable'>"; echo "<tbody>"; echo "<tr>"; echo "<th class='county'>County</th>"; echo "<th class='city'>City</th>"; echo "<th class='court'>Court</th>"; echo "<th class='judge'>Judge</th>"; echo "<th class='address'>Address</th>"; echo "<th class='phone'>Phone</th>"; echo "<th class='fax'>Fax</th>"; echo "<th class='notes'>Court Notes</th>"; echo "</tr>"; $sql2 = "SELECT * FROM courtdirectory WHERE courtdirectory.id = ($myid)"; $retval2 = mysqli_query($conn, $sql2); $result2 = mysqli_query($conn, "SELECT * FROM courtdirectory WHERE courtdirectory.id = ($myid)") or die("Error: " . mysqli_error($conn)); while($row = mysqli_fetch_array($retval2, MYSQLI_ASSOC)) { $varprosecutor = $row['prosecutor']; $varprosecutoraddress = str_replace(',', ' ', $row['prosecutoraddress1']); $varprosecutorphone = $row['prosecutorphone']; $varprosecutorfax = $row['prosecutorfax']; $varprosecutornotes = $row['prosecutornotes']; $varprosecutornotes = str_replace(['<br/>','</br>','<br />'], ' ', $row['prosecutornotes']); echo "<tr>"; echo "<td class='county'>" .$row['county']. "</td>"; echo "<td class='city'>" .$row['city']. "</td>"; echo "<td class='court'>" .$row['court']. "</td>"; echo "<td class='judge'>" .$row['judge']. "</td>"; echo "<td class='address'>" .$row['address']. "</td>"; echo "<td class='phone'>" .$row['phone']. "</td>"; echo "<td class='fax'>" .$row['fax']. "</td>"; echo "<td class='notes'>" .$row['notes']. "</td>"; echo "</tr>"; echo "</tbody>"; echo "</table>"; echo "</br>"; echo "<table class='courtdirectorytable'>"; echo "<tbody>"; echo "<tr>"; echo "<th class='prosecutor'>Prosecutor</th>"; echo "<th class='prosecutoraddress'>Prosecutor Address</th>"; echo "<th class='prosecutorphone'>Prosecutor Phone</th>"; echo "<th class='prosecutorfax'>Prosecutor Fax</th>"; echo "<th class='prosecutornotes'>Prosecutor Notes</th>"; echo "</tr>"; echo "<tr>"; echo "<td class='prosecutor'><textarea class='prosecutor' value='$varprosecutor'>$varprosecutor</textarea></td>"; echo "<td class='prosecutoraddress'><textarea class='prosecutoraddress' value='$varprosecutoraddress'>$varprosecutoraddress</textarea></td>"; echo "<td class='prosecutorphone'><textarea class='prosecutorphone' value='$varprosecutorphone'>$varprosecutorphone</textarea></td>"; echo "<td class='prosecutorfax'><textarea class='prosecutorfax' value='$varprosecutorfax'>$varprosecutorfax</textarea></td>"; echo "<td class='prosecutornotes'><textarea class='prosecutornotes' value='$varprosecutornotes'>$varprosecutornotes</textarea></td>"; echo "</tr>"; echo "</tbody>"; echo "</table>"; echo "<table class='submitbutton'>"; echo "<tbody>"; echo "<tr>"; echo "<td class='submitbutton'><button type='submit' class='courtdirectory-submit' name='submit' tabindex='6' data-submit='...Sendng'>Update</button></td>"; echo "</tr>"; echo "</tbody>"; echo "</table>"; } echo "</form>"; echo "</body>"; } ?> </html>
-
Keep value of selectbox if there is an error on the form
mike3075 replied to mike3075's topic in PHP Coding Help
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! -
Keep value of selectbox if there is an error on the form
mike3075 replied to mike3075's topic in PHP Coding Help
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 -
Keep value of selectbox if there is an error on the form
mike3075 replied to mike3075's topic in PHP Coding Help
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 -
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">•</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?
-
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 = '[email protected]'; // email $mail->Password = 'PasswordWasHere'; // password $mail->setFrom($varemail); // From email and name $mail->addAddress('[email protected]'); // 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
-
Contact form working, but email not sending or being received
mike3075 replied to mike3075's topic in PHP Coding Help
Ginerjm, that worked! Thank you very much! requinix, I will create a test page using PHPMailer. Thank you both for your suggestions! -
Contact form working, but email not sending or being received
mike3075 replied to mike3075's topic in PHP Coding Help
It's not. I will change it and see what happens. Thank you -
Contact form working, but email not sending or being received
mike3075 replied to mike3075's topic in PHP Coding Help
Thank you for the quick response. I will give it a shot
