PHP - <?php If ($_post['inputfieldid'] == "value") { Echo "selected"; } ?>
hello,
I was wondering what is the point of writing for a dropdown: <?php if ($_POST[inputfieldID] == "value") { echo "selected"; } ?> or for a checkbox/ radio button: <?php if ($_POST['cb/radioID'] == "value") { echo "checked"; } ?> I guess it's for after submit, if there is any error, the values filled will still be echoed in the inputfield, or am i wrong? But then if that is true, i have a php search box where i use AJAX object to to send all the input they filled in after submit. But after pushing submit the inputted values remain. I guess when using AJAX to send the information i don't need <?php if ($_POST[inputfieldID] == "value") { echo "selected"; } ?> in my html forms? Little confused Can maybe somebody bring clearness Similar TutorialsCan someone please help me with an array problem i can not figure out. I need the array to be numbered from 1 to how ever many fields that are needed in the form and have a mysql field name and the title of the field also in the array. 1, "mysql_field_name", "Title of form field" 2, "", "" and so on then the form will be shown based on the array. I have the following draft code which I am working with. any suggestions on how i may do this array ? Code: [Select] <?php $options = array( '1'=> array('fieldtext'=>'option1', 'mysqlfield'=>'option1'), '2'=> array('fieldtext'=>'option2', 'mysqlfield'=>'option2'), '3'=> array('fieldtext'=>'option3', 'mysqlfield'=>'option3'), '4'=> array('fieldtext'=>'option4', 'mysqlfield'=>'option4'), ); // $options = array(1 => "option1", "option2", "option3", "option4"); // the line above works but i want to include the name of the mysql field as well. $userid = 1; ?> <div style="align: center; margin: 12px; font-family:Tahoma;"> <br><br><?php if ($_POST['Update'] != "Update") { // check if form submitted yet, if not get data from mysql. $res = db_query("SELECT * FROM `users` WHERE `userid` = '" . $userid . "'"); foreach($options as $key => $value) { $_POST[$key] = mysql_result($res, 0, $value); } $ok_to_update = "no"; } elseif ($_POST['Update'] == "Update") { // check if form submitted yet, if so get POST data. // error checking // foreach($options as $key => $value) { // $_POST[$i] = ""; // } $ok_to_update = "yes"; } if ($_POST['Update'] == "Update" && $ok_to_update == "yes") { // $res = db_query("INSERT INTO `users` () VALUES ()"); // add user details to database. ?><p><br><br><br>Thank you for updating</p><?php } else { ?><form name="form1" method="post" action=""> <?php foreach($options as $key => $value) { ?><p><?php echo($value); ?>: <input type="text" name="<?php echo($key); ?>" value="<?php echo($_POST[$key]);?>"></p> <?php } ?> <input name="Update" type="submit" value="Update"> </form> <?php } ?> </div> Hi, bit stuck on how to find and replace "<" and ">" with "<" and ">". I basically have a database record that outputs to screen and I need the code in the <code> tags to be rendered to the screen. I therefore need it to go through the whole array variable from the db and change the symbols just inside the code tags. Please be aware that the code tags might happen more than once here's an example below Code: [Select] <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> the desired output would be: <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> help on this would be great Cheers Rob Hi guys I am a newbie with PHP and I have been trying to solve this problem for 3 days.. Ive set up a booking form on my website to be sent directly to my email once the client clicked on the send button.. The problem I am having while checking these pages on wamp is that the booking form is ok but when I click on the send button the following message error appears "Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\fluffy_paws\booking_form2.php on line 27" When I check online I have this message "500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed." Are my codes wrong??? My webhosting is Blacknight.com , Im on Windows Vista, my internet is a dongle with O2 ireland Thanks for your help! Hi guys I'm struggling a bit, I need to replace a word that occurs multiple times in text with an array("up","down","forward","backwards") of words. $find = "left"; $replace = array("up","down","forward","backwards"); $text = "left left left left"; echo str_replace($find,$replace,$text); The Output is: array array array array Did try this with a foreach statement as well, but no luck. Is there a better way of doing this? Thanks cant work out this mysql syntax error "operation":"medupdate","medid":"","name":"ibo","medyear":"5","medmonth":"21","medday":"1","recuser":1,"SuccFail":"fail","SuccFailMessage":"error occured You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '''WHERE med_id=' at line 2","ResultData":""} Code: [Select] $sql="update metodology set med_description='".$req['name']."', med_year='".$req['medyear']."', med_month='".$req['medmonth']."', med_day='".$req['medday']."', med_recorddate= now(), med_recorduserid= 1'"; $sql.= " WHERE med_id=".$req['medid']; How can i make echo "<b>Site:</b> ".$req_user_info['site']."<br>"; linkable The site raw fron the db contains an site url. Regards I am getting the following error when using composer: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? Just started. I am pretty sure composer.json wasn't changed. journalctl doesn't show anything. Maybe Doctrine related, however, nothing seems to help.
Any ideas? [michael@devserver www]$ php -v PHP 7.3.4 (cli) (built: Apr 2 2019 13:48:50) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.4, Copyright (c) 1998-2018 Zend Technologies with DBG v9.1.9, (C) 2000,2018, by Dmitri Dmitrienko [michael@devserver www]$ composer -V Composer version 1.4.2 2017-05-17 08:17:52 [michael@devserver www]$ yum info composer Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.us.oneandone.net * epel: mirror.rnet.missouri.edu * extras: mirror.us.oneandone.net * remi-php73: mirror.bebout.net * remi-safe: mirror.bebout.net * updates: mirror.us.oneandone.net Installed Packages Name : composer Arch : noarch Version : 1.8.4 Release : 1.el7 Size : 1.8 M Repo : installed From repo : epel Summary : Dependency Manager for PHP URL : https://getcomposer.org/ License : MIT Description : Composer helps you declare, manage and install dependencies of PHP projects, : ensuring you have the right stack everywhere. : : Documentation: https://getcomposer.org/doc/ [michael@devserver www]$ composer update Loading composer repositories with package information Updating dependencies (including require-dev) [ErrorException] "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [<packages>]... [michael@devserver www]$
This topic has been moved to Linux. http://www.phpfreaks.com/forums/index.php?topic=318175.0 I have a registration form on my website and after Registration I want the user to activate first his account. I don't have problem on sending this email to the user. What I want to appear is like this.. GoodDay "username", Blah Blah! how can you actually do that? I know that you can do that through session variables but the thing is email's can't accept scripts on sending emails. how can I get the value from a session variable for example and convert it to plain html text so that i can OUTPUT it to the email.. HELP PLEASE! Hi, I currently have an if, elseif, else program that starts off with Code: [Select] if( $v_name == "" || $v_msg == "" ) echo "something" how do I turn this into a switch? but the very next elseif I have Code: [Select] elseif( strcspn( $_REQUEST['msg'], '0123456789' ) == strlen( $_REQUEST['msg'] ) ) echo "something" is it possible to turn this into a switch with 2 different strings like that to evaluate? This topic has been moved to PHP Installation & Configuration. http://www.phpfreaks.com/forums/index.php?topic=347922.0 Hey guys! I have the following doubt: I have a php file that does the following alongside with other code not displayed he $fp = fopen("emails.txt", "w"); It opens a txt file called emails.txt that is in the same folder where the php is saved but how do I tell $fp = fopen("/folderbefore/emails.txt", "w"); ?? In other words, how do I write the path on the script that the emails.txt is located in a previous folder where the php file is located?? Thanks in advance for your help Cheers! Hi all, Using a form with check boxes divided into different categories, I collect data selected by the user. I now want to combine each choice in each category with each choice in the other categories and list the combinations to the user. If the user chooses one or more options in each category, it is relatively easy to nest foreach loops, since the number of categories will always be the same. For example, if the form contains three categories of options, the code will be: Code: [Select] foreach ($form['cat_1'] as $k1 => $val1) { foreach ($form['cat_2'] as $k2 => $val2) { foreach ($form['cat_3'] as $k3 => $val3) { echo $val1.' _ '.$val2.' _ '.$val3.'<br/>'; } } } Things get complicated if the user does not select options within a given category. More generally, I want to be able to generate the list regardless of the number of categories in which the user selects options. Thank you in advance for your advice. Hi, I have set up 2 php pages page 1 - add_entry2.php In this page I have a invoice table created where I can dynamically add/delete rows. This has a View Bill button which takes me to page 2- add_entry3.php In this page it shows up the rows added in page 1 in read only format, so if the user wants to modify the data that he/she entered then he must Click on <back> that i have provided in the page 2 which will direct him to page 1 Now the problem starts here on click of Back the dynamically added rows dissappear..which is frustrating..I know its something to do with my code..but can anyone help me fix it. One more thing is that i dont want to store the data into DB till the finalise button is clicked on page 2 so that means till page 2 is submitted nothing goes to DB from Page 1. I am able to retain values if I use the code Code: [Select] <form action="add_entry2.php" name="eval_edit" method="post" format="html"> i,e if I submit back to the same page and retrieve values form $_POST but If I use the code Code: [Select] <input type="button" value="Back" onClick="history.go(-1);return true;">to get back to add_entry2.ph it looses all the values. Is there any other way to code the BACK link retaining my $_POST values(Do you think $_SESSION would work in this case?) preg_replace() asks that "Delimiter must not be alphanumeric or backslash" in the pattern. So I changed $new_text = preg_replace($_POST['withthis'] ,$_POST['withthis'],$_POST['text']); to this $replacethis = $_POST['replacethis']; $new_text = preg_replace("/$replacethis/",$_POST['withthis'],$_POST['text']); It works fine, but out of curiosity, is there any way to have the POST variable as a parameter directly, and why does it not work? Just to try it, I attempted: "/$_POST['withthis']/" and $_POST["/'withthis'/"] and both do not work. str_replace is a better option I think, but I am just trying to get a better understanding of this delimiter rule. Thanks for your time! I want to post some form identifyer when I hit submit, so that I can use this in an SQL query. Previously I used the below code and would retrieve either page1.php or page2.php etc from $_POST['subject']); Code: [Select] <td> <select name="subject" id="subject" onchange="gotourl(this.value)"> <option value="" >Please Select</option> <option value="page1.php" >page1</option> <option value="page2.php">page2</option> <option value="page3.php">page3</option> </select> </td> will this work? Code: [Select] <form id="form1" name="form1" value="tableName" method="post" action=""> $_POST['form1']) returns tableName...... Thanks Code: [Select] <?php if (isset($_POST['submit'])) { // Grab the selected value $optionValue = $_POST['subscriptionLevel']; // Grab the id of the selected value ** HOW DO I DO THIS? ** $optionID = ?????????????????????????; } ?> <html> <body> <form name="form" method="post" action=""> <table> <tr> <td> <label for="subscriptionLevel"></label> <select name="subscriptionLevel" id="subscriptionLevel"> <?php do { ?> <option id="<?php echo $dbRowResult['sub_level']; ?>" value="<?php echo $dbRowResult['sub_price']; ?>"><?php echo $dbRowResult['sub_desc']; ?></option> <?php } while ($dbRowResult = $db->dbGetRow($dbQueryResult)); ?> </select> </td> <td> <label> <input type="submit" name="submit" id="submit" value="submit"> </label> </td> </tr> </table> </form> </body> </html> How do I grab the id of the selected value? Thank you. I'm a very new PHP user (as in, I just started today) and need to make a set of navigation buttons which will take the user to "next" or "previous" pages. I assume that the $_GET function is involved, but I don't know how to do it. It needs to work like this: If the URL looks like "http://website.com/page1.php" I need the "next" button (a href image) to change it to "/page2.php", and while on page 2, for the "previous" button to take the user to "/page1.php" and so forth. How can I cause the page number to increment or decrease respective to the href image being clicked? Hey can anyone please help? I making this form on my website and I have two drop down lists, one is for sizes and the other is for colors. They both have an option for "other" and I'm wanting a textbox to appear when "other" is selected. I got the first drop down to work but I can't figure out how to get the second one to work without messing with the first. Here is the code I have please help: <form name="form1" method="post" action=""> <script type="text/javascript"> function showfield(name){ if(name=='Other')document.getElementById('div1').innerHTML='Other: <input type="text" name="other" />'; else document.getElementById('div1').innerHTML=''; } </script> <p>Size: <select name="size" id="size" onchange="showfield(this.options[this.selectedIndex].value)"> <option selected="selected">Please select ...</option> <option value="1' H X 6" W">2' H X 1' 6" W</option> <option value="1' H X 2' W">1' H X 2' W</option> <option value="1' H X 1' 4" W">1' H X 1' 4" W</option> <option value="Other">Other</option> </select> <div id="div1"></div> <p>Color: <select name="Color" id="Color" onchange="showfield(this.options[this.selectedIndex].value)"> <option selected="selected">Please select ...</option> <option value="Walnut Stain/Dark Brown">Walnut Stain/Dark Brown</option> <option value="Tan">Tan</option> <option value="Walnut">Walnut</option> <option value="Other">Other</option> </select> <div id="div1"></div> </p> This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=347354.0 |