PHP - Editing Variables From A Form
I want to make a file that I can edit from a form. I don't know what type of file I should use, and how I would edit that file.
When someone goes to the file I don't want them to be able to see the contents (like a php file holding variables). I also don't want to use .htaccess for this. This file will have things in such as the database connection variables. When someone edits the form, and save it, it will edit the database connection variables to the proper values. Here is the file I have now: Code: [Select] <?php $settings = array(); $settings['db']['host'] = 'xxxx'; $settings['db']['username'] = 'xxxx'; $settings['db']['password'] = 'xxxx'; $settings['db']['database'] = 'xxxx'; ?> Here is an example input field: Code: [Select] <input type="text" name="host" value="<?php echo $settings['db']['host']; ?>" /> What would be the best way to do this? Similar TutorialsOne more question for the day. I'm trying to figure out the best way to run about this. Right now I have it set up so that two or more content pages CAN NOT have the same name or shortname as it performs checks to verify that there aren't both on my add new and edit pages. Now problem here is that say I'm on the edit form and I'm editing a content page with its dropdowns and what not in the form. Now I'm thinking what would be the next course of option because what if I only want to change one dropdown but still keep the same name and shortname. When I submit it, its going to kickback my response that it can't be saved because there's already a page in there with that name and shortname even though I didn't change it. Any suggestions? Hi. When i fill in my contact form, it shows a "Message sent successfully" message. Then nothing happens. I think there is something wrong with my hosting but the service provider just can't help with that.
How can i edit these codes to send a mail through smtp?
<?php
I have an email form that can have comma separated email addresses. I need to modify my code such that initially if the form does not contain any value, it should let me add email addresses to it. When I enter the web page next time it should display and let me edit the existing email addresses. Here is my code below. Right now it does not insert anything the first time. Code: [Select] <? error_reporting(E_ALL & ~E_NOTICE); $conn = mysql_connect('localhost','test','*****') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('test',$conn) or trigger_error("SQL", E_USER_ERROR); //$sql=mysql_query("SELECT * from new_database") or die(mysql_error()); $getemail=mysql_query("SELECT * from email") or die(mysql_error()); if(mysql_num_rows($getemail) > 0) { while($getemail_results=mysql_fetch_assoc($getemail)) { $getemailadd=$getemail_results['email']; } } else { $getemailadd=''; } if (!isset($_POST['submit'])) { ?> <b>ADDING A Email</b><br> <form action="<?php echo $PHP_SELF;?>" method="post"> Email:<br> <input type="text" size ="80" name="email" value="<?PHP if(isset($getemailadd)){ echo $getemailadd; } ?>" /><br> <input type="submit" name="submit" value="submit" /> </form> <? } else { // Get values from form $email=$_POST['email']; //$sql=mysql_query("INSERT into email(email)VALUES('$email')") or die (mysql_error()); $sql=mysql_query("UPDATE email SET email='$email'") or die (mysql_error()); header('Location: index.php'); } ?> Hi, i have problem with editing register form over Inspect element or when u press F12 in mozilla or chrome. When u select country u can edit form on F12 and change country value so form save it like that in database. Problem is because its in foreach loop and i cant get a check if country in post variable is valid, and compare it with that in database. In my $_POST variable country is stored like ' Croatia, hr ' and in database its like 'id, name, alpha_2, alpha_3'.
So can i find value i need for example Albania and al wihout any loop ?
// if user is logged in redirect him to index page if ($general->is_logged() === true) { header('Location: index.php'); exit(); } // get list of countries $country = $teams->get_country(); require_once 'core/classes/recaptchalib.php'; $publickey = "***********************"; $privatekey = "***********************"; // process form if (isset($_POST['register'])) { if (isset($_POST['username']) && isset($_POST['nickname']) && isset($_POST['password']) && isset($_POST['repeat_password']) && isset($_POST['email']) && isset($_POST['repeat_email']) && isset($_POST['gender']) && isset($_POST['country']) && isset($_POST['recaptcha_challenge_field']) && isset($_POST['recaptcha_challenge_field'])) { $username = trim($general->safe_input($_POST['username'])); $nickname = trim($general->safe_input($_POST['nickname'])); $password = trim($general->safe_input($_POST['password'])); $rpassword = trim($general->safe_input($_POST['repeat_password'])); $email = trim($general->safe_input($_POST['email'])); $remail = trim($general->safe_input($_POST['repeat_email'])); $gender = trim($general->safe_input($_POST['gender'])); $cntry = $general->safe_input($_POST['country']); $date_registered = time(); $password_hash = $general->safepass($password); // captcha $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); // if username is empty if (empty($username)) { $error[] = 'Username is empty.'; // if username already exists } elseif ($users->user_exists($username) === true) { $error[] = 'Username in use, please choose another.'; // username must be between 3 and 20 characters long } elseif (strlen($username) < 3 || strlen($username) > 20) { $error[] = 'Username must be between 3 and 20 charaters long.'; } // if nickname is empty if (empty($nickname)) { $error[] = 'Nickname is empty.'; // if nickname in use } elseif ($users->nick_exists($nickname) === true) { $error[] = 'Nickname in use, please choose another.'; // nickname must be between 3 and 20 characters long } elseif (strlen($nickname) < 3 || strlen($nickname) > 20) { $error[] = 'Nickname must be between 3 and 20 characters long.'; } // if passowrd field is empty if (empty($password)) { $error[] = 'Password filed is empty.'; } // if password repeat field is empty if (empty($rpassword)) { $error[] = 'Repeat password filed is empty'; } // if password and repeat password is not empty if (!empty($password) && !empty($rpassword)) { // passwords match ? if not throw error message if ($password != $rpassword) { $error[] = 'Passwords don\'t match.'; // password must be between 6 and 30 characters long } elseif (strlen($password) < 6 || strlen($password) > 30) { $error[] = 'Password must be between 6 and 30 characters long.'; } } // is email empty if (empty($email)) { $error[] = 'Email filed is empty.'; } // is repeat email is empty if (empty($remail)) { $error[] = 'Repeat email filed is empty.'; } // if email and repeat email is not empty if (!empty($email) && !empty($remail)) { // if emails are not same if ($email != $remail) { $error[] = 'Emails don\'t match.'; // if email and repeat email is same } elseif ($email == $remail) { // is email valid if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error[] = 'Invalid email format.'; // is email in use } elseif ($users->email_exists($email) === true) { $error[] = 'Email in use, please choose another.'; // email must be between 10 and 30 characters long } elseif (strlen($email) < 10 || strlen($email) > 30) { $error[] = 'Email must be between 10 and 30 characters long.'; } } } // if gender is empty if (empty($gender)) { $error[] = 'Please select gender.'; } // if gender is not empty if (!empty($gender)) { // if gender is Male or Female if ($gender == 'Male') { $gender = 'Male'; } elseif ($gender == 'Female') { $gender = 'Female'; } else { $error[] = 'Invalid gender.'; } } // if country is empty if (empty($cntry)) { $error[] = 'Please select country.'; } // check if country is valid if (!empty($cntry)) { // $newCountry['0'] is name key // $newCountry['1'] is alpha_2 key $newCountry = explode(',', $cntry); if (in_array($newCountry['0'], $country['name'])) { $error[] = 'VALID.'; } else { $error[] = 'Invalid country.'; } } // check if capthha is valid if (!$resp->is_valid) { $error[] = 'Invalid captcha code.'; } // if no errors register user if (empty($error) === true) { //$add_user = $users->register_user($username, $password_hash, $email, $gender, $date_registered, $cntry, $nickname); unset($_POST); // clean $_post variable echo 'REGISTER USER !'; } /* if ($DBH->lastInsertId()) { header('Location: index.php?page=register_success'); exit(); } else { $error = '<p class="error-msg">There was a problem, please try again.</p>'; }*/ } } ?> <script type="text/javascript"> var RecaptchaOptions = { theme : 'clean' }; </script> <h3>Register</h3> <?php if (!empty($error)) { echo '<div style="padding:10px;margin:0 10px;border:1px solid #f3f3f3;background:#E35454;color:#fff;"><ul style="margin:0 0 0 20px;">'; foreach ($error as $error) { echo '<li>'.$error. '</li>'; } echo '</ul></div>'; } ?> <form action="" method="POST" class="register-form"> <input type="text" name="username" size="40" maxlength="20" placeholder="Username" value="<?php if (isset($_POST['username'])) { echo htmlentities($_POST['username'], ENT_QUOTES, "UTF-8"); } ?>" required> <input type="text" name="nickname" size="40" maxlength="20" placeholder="Nickname" value="<?php if (isset($_POST['nickname'])) { echo htmlentities($_POST['nickname'], ENT_QUOTES, "UTF-8"); } ?>" required><br /><br /> <input type="password" name="password" size="40" maxlength="30" placeholder="Password" required> <input type="password" name="repeat_password" size="40" maxlength="30" placeholder="Repeat password" required><br /><br /> <input type="text" name="email" size="40" maxlength="30" placeholder="Email" value="<?php if (isset($_POST['email'])) { echo htmlentities($_POST['email'], ENT_QUOTES, "UTF-8"); } ?>" required> <input type="text" name="repeat_email" size="40" maxlength="30" placeholder="Repeat email" value="<?php if (isset($_POST['repeat_email'])) { echo htmlentities($_POST['repeat_email'], ENT_QUOTES, "UTF-8"); } ?>" required><br /><br /> <select name="gender" required> <option value="">Select gender</option> <option value="Male">Male</option> <option value="Female">Female</option> </select> <select name="country" style="width: 215px;" required> <option value="">Select country</option> <?php foreach ($country as $key) { echo '<option value="'.$key['name'].','.$key['alpha_2'].'">'.$key['name'].'</option>'; } ?> </select> <br><br> <center><?php echo recaptcha_get_html($publickey); ?></center> <br> <center><input type="submit" name="register" value="Register" class="small-button"></center> </form> Hello Im quite confused at what filtering I should use on my data when pulling it from a MySQL database. I don't sanitize my data on input because I am using prepared statements with PHP's PDO Driver which means I don't need to use mysql_real_escape_string() at all. When I pull the data to be displayed i.e. in a HTML Table I use the below function to make it safe for HTML output. public static function htmlSafe($data) { return nl2br(htmlentities($data, ENT_QUOTES)); } However the rules change when Im using a HTML Form to edit the data, and I am unsure what I need to strip out. I.e. What would I need to do to make all data safe to insert into the following form input. <input id = "someInput" type = "text" value = "<?php echo $someVarThatNeedsFiltering ?>" /> Also, one more question, in my html attributes (Valid ones like class, name, id, style, _target) I use a mixture of double quotes(") and single quotes ('), for quoting my values. Which one should I use or which one is more valid, doubles, or singles? So i have this CMS that is used by lots of users and generally they do have rights to edit each others article. So now i'm thinking how can i at least warn them that somebody else is already editing it. Just that. maybe with sessions? but what happens when a user just closes the windows, will it destroy it. i taught about storing the value to mySQL but again what if the user closes the windows and so on. i never did this and i could use a boost. thanks guys This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347360.0 Hi i have this edit form that allows user to mofy data but the problems on the text box is that it deletes the rest of the data after the space from the first word i tried to increase the size of the varChars on mysql but did no work why it happens how can i stop from happening?? this the form input <input type="text" name="name" id="name" class='text_box' value="<?php echo $_GET['name'];?>"/> I wrote this while loop to cycle through all the rows in my database, and for each row, to create two things, first to echo the name of the book, and the second was to create a button next to it that when clicked, sends the BookID of that row via the post method to the the page at /scas/moreinfo.php . The first echo statement works, and states every book name on the page one after another. For some reason however the form Posts the same book id in every form i think, the value of it being the value in BookID in the last row of the database, in this case 16, so no matter what button is pressed, it sends the value 16. What have I done wrong? while($row = mysql_fetch_array($result)) { echo $row['BookName'] ; echo "<form name='moreinfo' action='/scas/moreinfo.php' method='post'>"; echo "<input type='hidden' name='BookID' value='" .$row['BookID']. "'>"; echo "<input type='submit' value='More Info' />"; echo "<br />"; } ...to obtain an id_item users doesn´t know and I need to send to the DB
I got this
<?php require_once('Connections/conexxion.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO movimiento (venta, compra, taller, regula_mas, regula_menos, id_lente, id_cil, id_esf) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['venta'], "int"), GetSQLValueString($_POST['compra'], "int"), GetSQLValueString($_POST['taller'], "int"), GetSQLValueString($_POST['regula_mas'], "int"), GetSQLValueString($_POST['regula_menos'], "int"), GetSQLValueString($_POST['id_lente'], "int"), GetSQLValueString($_POST['id_cil'], "int"), GetSQLValueString($_POST['id_esf'], "int")); mysql_select_db($database_conexxion, $conexxion); $Result1 = mysql_query($insertSQL, $conexxion) or die(mysql_error()); } mysql_select_db($database_conexxion, $conexxion); $query_lente = "select id_lente, lente from lentes"; $lente = mysql_query($query_lente, $conexxion) or die(mysql_error()); $row_lente = mysql_fetch_assoc($lente); $totalRows_lente = mysql_num_rows($lente); mysql_select_db($database_conexxion, $conexxion); $query_esfera = "SELECT * FROM esfera"; $esfera = mysql_query($query_esfera, $conexxion) or die(mysql_error()); mysql_select_db($database_conexxion, $conexxion); $query_cilindro = "SELECT * FROM cilindro"; $cilindro = mysql_query($query_cilindro, $conexxion) or die(mysql_error()); $query_item = "select id_item from item inner join rx on rx.id_rx = item.id_rx inner join cilindro on cilindro.id_cil = rx.id_cil inner join esfera on esfera.id_esf = rx.id_esf where cilindro = ".$_POST['sel_cil']." and esfera = ".$_POST['sel_esf']." and id_lente =". $_POST['sel_lente']; $idlente = mysql_query($query_lente, $conexxion) or die (mysql_error()); ?> <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right">Venta:</td> <td><input type="text" name="venta" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Compra:</td> <td><input type="text" name="compra" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Taller:</td> <td><input type="text" name="taller" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Regula_mas:</td> <td><input type="text" name="regula_mas" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Regula_menos:</td> <td><input type="text" name="regula_menos" value="" size="32" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">lente:</td> <td><?php echo "<select name='sel_lente'>"; while($row= mysql_fetch_array($lente)){?> <option value=" <?php echo $row['id_lente'] ;?> " > <?php echo $row['lente']; ?> </option> <?php } ?> </select> <label for="id_lente"></label></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">cilindro:</td> <td><?php echo "<select name='sel_cil'>"; while($row= mysql_fetch_array($cilindro)){?> <option value=" <?php echo $row['id_cil'] ;?> " > <?php echo $row['cilindro']; ?> </option> <?php } ?> </select> <label for="id_cil"></label></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Esfera:</td> <td><?php echo "<select name='sel_esf'>"; while($row= mysql_fetch_array($esfera)){?> <option value=" <?php echo $row['id_esf'] ;?> " > <?php echo $row['esfera']; ?> </option> <?php } ?> </select></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">id_lente</td> <td><label for="id_lente3"></label> <input type="text" name="id_lente" id="id_lente3" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> </td> <td><input type="submit" value="Insert record" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> <?php mysql_free_result($esfera); mysql_free_result($cilindro); mysql_free_result($lente); ?>and with this query $query_item = "select id_item from item inner join rx on rx.id_rx = item.id_rx inner join cilindro on cilindro.id_cil = rx.id_cil inner join esfera on esfera.id_esf = rx.id_esf where cilindro = ".$_POST['sel_cil']." and esfera = ".$_POST['sel_esf']." and id_lente =". $_POST['sel_lente']; $idlente = mysql_query($query_lente, $conexxion) or die (mysql_error());I would obtain the id_item, but , how?, because the form it´s not procesed and I´m getting no variable values. Basically atm I am trying to accomplish a way to $_POST a selection from my dropdown box in to a PHP variable for use elsewhere. The eventual goal being a form that will allow you to select a user from the dropdown box; then via a HTML form with some additional text fields, add/update database table records for that person. I have been searching and searching, and I cant find anything that addresses using a dropdown box that pulls names from my SQL in a html web form. All I can find are tons of guides on simple html only forms. At the moment, the dropdown box is working, It is pulling names from my database/table. But when I select a name from the list and then click on my submit button the $_POST does not seem to be pulling the value for "username". I have the following for the index page: <?php include('/nav.php'); include('/config.php'); include('/dbopen.php'); echo "Select a name: <select name='$name'>"; $query="select * from players"; $result=mysql_query($query); while($row=mysql_fetch_array($result)){ $name=$row['PLAYER_NAME']; echo "<option name=username value='$name'>$name</option>"; } echo "</select>"; ?> <html> <body> <form action="moduser.php" method="post" /> <input type="submit" value="CLICK!" /> </form> </body> </html> and the following for a test page to see if my form is being submitted correctly: <?php include('/nav.php'); include('/config.php'); include('/dbopen.php'); $username="$_POST[username]"; echo "Hello $username"; ?> NOTE: My includes are tested and working default scripts to connect to database, define some global vars etc. Should not be relevant to my particular problem Thanks Much, Dega. Hi, I have a user sign up form. When some data is incorrect or missing it reloads the form, saving the info the user has already entered and displaying an error message for the parts that are invalid. For example: Code: [Select] <tr><td width = "300"> <label for="email">Email Address:</label></td> <td><input type="text" id="email" name="email" value="<?php if (!empty($email)) echo $email; ?>" /><br /> </td></tr> How can I return the submitted info for a checkbox and a birthdate? Sorry, the birthdate code is kind of huge. Code: [Select] <tr><td width = "300"> <label for="terms">I agree to the <a href = "/TOS.php">Terms of Service</a>.</label></td> <td><input type="checkbox" id="terms" name="terms" value = "checked"/><br /> </td></tr> <td> <select id = "DateOfBirth_Month" name="DateOfBirth_Month"> <option>Month</option> <option value="1">January</option> <option value="2">Febuary</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select id = "DateOfBirth_Day" name="DateOfBirth_Day"> <option>Day</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select id = "DateOfBirth_Year" name="DateOfBirth_Year"> <option>Year</option> <option value="2010">2010</option> <option value="2009">2004</option> <option value="2008">2003</option> <option value="2007">2002</option> <option value="2006">2001</option> <option value="2005">2000</option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> <option value="1998">1998</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> <option value="1992">1992</option> <option value="1991">1991</option> <option value="1990">1990</option> <option value="1989">1989</option> <option value="1988">1988</option> <option value="1987">1987</option> <option value="1986">1986</option> <option value="1985">1985</option> <option value="1984">1984</option> <option value="1983">1983</option> <option value="1982">1982</option> <option value="1981">1981</option> <option value="1980">1980</option> <option value="1979">1979</option> <option value="1978">1978</option> <option value="1977">1977</option> <option value="1976">1976</option> <option value="1975">1975</option> <option value="1974">1974</option> <option value="1973">1973</option> <option value="1972">1972</option> <option value="1971">1971</option> <option value="1970">1970</option> <option value="1969">1969</option> <option value="1968">1968</option> <option value="1967">1967</option> <option value="1966">1966</option> <option value="1965">1965</option> <option value="1964">1964</option> <option value="1963">1963</option> <option value="1962">1962</option> <option value="1961">1961</option> <option value="1960">1960</option> <option value="1959">1959</option> <option value="1958">1958</option> <option value="1957">1957</option> <option value="1956">1956</option> <option value="1955">1955</option> <option value="1954">1954</option> <option value="1953">1953</option> <option value="1952">1952</option> <option value="1951">1951</option> <option value="1950">1950</option> <option value="1949">1949</option> <option value="1948">1948</option> <option value="1947">1947</option> <option value="1946">1946</option> <option value="1945">1945</option> <option value="1944">1944</option> <option value="1943">1943</option> <option value="1942">1942</option> <option value="1941">1941</option> <option value="1940">1940</option> <option value="1939">1939</option> <option value="1938">1938</option> <option value="1937">1937</option> <option value="1936">1936</option> <option value="1935">1935</option> <option value="1934">1934</option> <option value="1933">1933</option> <option value="1932">1932</option> <option value="1931">1931</option> <option value="1930">1930</option> <option value="1929">1929</option> <option value="1928">1928</option> <option value="1927">1927</option> <option value="1926">1926</option> <option value="1925">1925</option> <option value="1924">1924</option> <option value="1923">1923</option> <option value="1922">1922</option> <option value="1921">1921</option> <option value="1920">1920</option> <option value="1919">1919</option> <option value="1918">1918</option> <option value="1917">1917</option> <option value="1916">1916</option> <option value="1915">1915</option> <option value="1914">1914</option> <option value="1913">1913</option> <option value="1912">1912</option> <option value="1911">1911</option> <option value="1910">1910</option> <option value="1909">1909</option> <option value="1908">1908</option> <option value="1907">1907</option> <option value="1906">1906</option> <option value="1905">1905</option> <option value="1904">1904</option> <option value="1903">1903</option> <option value="1902">1902</option> <option value="1901">1901</option> <option value="1900">1900</option> </select> </td></tr> Thanks if you can help, Craig I need to echo out some string variables in a form. I also want to add some validation for Name, email etc. I think I have the code right or close, but I can an error on the index.php page which is. "Fatal error: Call to undefined function form_row_class() in index.php on line 14" here is the code for the form <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>String Tester</title> <link rel="stylesheet" type="text/css" href="main.css"/> </head> <body> <div id="content"> <h1>String Tester</h1> <form action="submit.php" method="post"> <table> <tr class="<?php echo form_row_class("name") ?>" > <th><label for="first_name">Name</label></th> <td> <input name="first_name" id="first_name" type="text" value="<?php echo h($_POST['name']); ?>" /> <?php echo error_for('name') ?> </td> </tr> <tr class="<?php echo form_row_class("email") ?>"> <th><label for="email">Email Address</label></th> <td> <input name="email" id="email" type="text" value="<?php echo h($_POST['email']); ?>" /> <?php echo error_for('email') ?> </td> </tr> <tr> <th></th> <td><input type="submit" value="submit" /></td> </tr> </table> </form> <h2>Message:</h2> <?php echo "<table>"; echo "<tr><td>"; echo $name; echo "</td></tr>"; echo "<tr><td>"; echo $email; echo "</td></tr>"; echo "<tr><td>"; echo $phone; echo "</td></tr>"; echo "</table>"; ?> </div> </body> </html> and the submit portion <?php // If request is a form submission if($_SERVER['REQUEST_METHOD'] == 'POST'){ // Validation // Check first_name is non-blank if(0 === preg_match("/\S+/", $_POST['name'])){ $errors['name'] = "Please enter a name."; } // Check email is valid (enough) if(0 === preg_match("/.+@.+\..+/", $_POST['email'])){ $errors['email'] = "Please enter a valid email address."; } // validate a phone number if( !preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $phone) ) { echo 'Please enter a valid phone number'; } // If no validation errors if(0 === count($errors)){ // Sanitize first, last, and email $name = mysql_real_escape_string($_POST['name']); $email= mysql_real_escape_string($_POST['email']); $email= mysql_real_escape_string($_POST['phone']); } // Helpers function form_row_class($name){ global $errors; return $errors[$name] ? "form_error_row" : ""; } function error_for($name){ global $errors; if($errors[$name]){ return "<div class='form_error'>" . $errors[$name] . "</div>"; } function h($string){ return htmlspecialchars($string); } ?> probably something simple I am missing. Hello all, I'm new to php and I'm running into some trouble. I'm hoping someone will be able to help me. Here is the code I already have: <?php include "include/dbc.php"; include "include/header.inc"; ?> <style type="text/css"> .mydate{ color:#00F; text-decoration:underline; cursor:pointer; } </style> <script type="text/javascript"> function displayDate(d){ var date=new Date(); var D=date.getDate(); date.setDate(D+d); var YYYY=date.getFullYear(); var MM=date.getMonth()+1; MM<10?MM='0'+MM:null; var DD=date.getDate(); DD<10?DD='0'+DD:null; var span=document.getElementById('date'); span.innerHTML= 'Entries for '+MM+'/'+DD+'/'+YYYY; } onload=function(){displayDate(0)}; </script> <h1>Food Diary</h1> <div class="full"> <center><div><span class="mydate" onclick="displayDate(-1)"><img src="images/left_arrow.png" border="0">Yesterday</span> <span id="date" style="font-size:2em;"></span> <span class="mydate" onclick="displayDate(1)">Tomorrow<img src="images/right_arrow.png" border="0"></span></div><br /> <a href="#" onclick="displayDate(0);return false;">Today</a> </center> <div class="full"> <form name="exercise" id="exercise" method="GET" action=""> <center><table> <tr> <td><h3>Add an Activity</h3></td> </tr> <tr> <td><input name="NewSearchString" style="width: 100px" type="text"/> <input type="submit" value="Search" /> </td> </tr> <tr> <td> <select name="activity"> <option value="_">Activity Browse...</option> <option value="all">All Activities</option> <option value="biking">Biking</option> <option value="condition">Conditioning</option> <option value="dancing">Dancing</option> <option value="fish">Fishing & Hunting</option> <option value="Home">Home Activities</option> <option value="misc">Miscellaneous</option> <option value="music">Music Playing</option> <option value="occupation">Occupation</option> <option value="running">Running</option> <option value="sports">Sports</option> <option value="walking">Walking</option> <option value="water">Water Activities</option> <option value="winter">Winter Activities</option> </select> <input type="submit" value="Submit" /></td></tr></table></center></form> </td> </tr> </table> </center> <table width="100%"> <tr bgcolor="#66CC33"> <td><div>Activity</div></td> <td><div>Specific Activity</div></td> <td><div>Time (hh:mm)</div></td> <td><div>Distance</div></td> <td><div>Units</div></td> </tr> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr> <?php if(isset($_GET[activity])) { $category=$_GET[activity]; $result = mysql_query("SELECT * FROM exercise WHERE type='$category'"); ?> <form action="add_activity.php" method="post"> <?php while($row = mysql_fetch_array($result)) { echo '<tr><td><div>'.$row[Type].'</div></td>'; echo '<td><div>'.$row[Name].'<input type="hidden" name="exerciseid" value="'.$row[No].'"></div></td>'; echo '<td><div><input type="text" name="duration"></div></td>'; echo '<td><div><input type="text" name="distance"></div></td>'; echo '<td><div><select> <option value="mile">mile</option> <option value="Km">km</option> <option value="M">m</option> <option value="Yard">yrd</option> <option value="Feet">ft</option> </select></div></td></tr>'; } mysql_close(); ?> <tr><td colspan="6" align="center"><input type="submit" name="submit" value="Add Activities"></td></tr> </form> <?php } ?> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr></table> This code is supposed to pull info from a database and place it in a table. Once the user clicks the add activities button at the bottom, there values are supposed to be passed and displayed in the second page. Here's what I have for the second page: <?php include "include/dbc.php"; include "include/header.inc"; $activity = $_POST['activity']; $exercise = $_POST['exercise']; $duration = $_POST['duration']; $distance = $_POST['distance']; echo $exercise; echo $duration; echo $distance; ?> (Keep in mind that I am using this code to test the functionality of the page before I make it look nice) When I pass the values to the 2nd page, I get a black screen. Nothing is passing and I don't know why. Am I going about this the wrong way? Is there something I need to do to make the code better? Any suggestions are appreciated. Thanks in advance. Hi, I have a feeling that this is going to be an easy miss but I've been over is a good few times and cannot see what it could be. Essentially, when I post the form in the first set of code (I've got rid of a load of unecessary html) the SESSION variables are not loaded into the second piece of code. Any ideas? Code: [Select] <?php session_start(); require ("connect.php"); $timeout = 1800; $logout_redirect_url = "login.php"; if (isset($_SESSION['start_time'])) { $elapsed_time = time() - $_SESSION['start_time']; if ($elapsed_time >= $timeout) { session_destroy(); header("Location: $logout_redirect_url"); } } $_SESSION['start_time'] = time(); ?> <div id="leftlink"> <a href="logout.php">Logout</a> </div> <table align="center" width="600px" cellpadding="0" cellspacing="0"> <tr> <td> <h2 align="center"><a href="index.php"><img src="images/logo.jpg" border="0" /></a> <br /> Emergency</h2> <hr /> </td> </tr> </table> </head> <body> <form action="post_reset.php" method="post" name"passre"> <table width="500" border="0" align="center" cellpadding="2" cellspacing="1"> <tr> <td width="230"><div align="right">E-mail Address : </div></td> <td width="40"> </td> <td width="230"><div align="left"> <input name="email" readonly="readonly" value="<?php echo ($_SESSION['email']) ; ?>" /></div></td> </tr> <tr> <td colspan="3"><div align="center"><input type="submit" name="submit" value="Submit" /></div></td> </tr> </table> </form> </body> </html> Code: [Select] <?php session_start; echo ($_SESSION['start_time']); require ("connect.php"); if (isset($_POST['submit'])){ $email = $_POST['email']; $getde = "SELECT * FROM users WHERE email = '$email'"; $getder = mysql_query($getde, $conn); $getdere = mysql_fetch_array($getder) Thanks Gareth what I am trying to accomplish is for the user to select the state they wish, hit submit. At this point another form should show asking which county based on the state they picked, then hit search. At this point, I'm having an issue having the state variable being passed to the 2nd form also having the state they selected stay selected. <?php $default = "Step 1. Pick Your State"; $select = "<option name='statebox'>$default</option>"; echo "<br/><form method='POST' action=".$_SERVER['PHP_SELF']." >"; echo "<select name='search'>"; echo "$select"; /////////////////////////////////////////////////////////////// //Connect to the database include_once 'phpforms/connect.php'; $sql = mysql_query("SELECT * FROM states"); while($row = mysql_fetch_array($sql)){ $state = $row['states']; echo "<option name='statebox'>$state</option>"; }//End While /////////////////////////////////////////////////////////////// echo "</select>"; echo "<input align='left' type='submit' name='stateboxbutton' value='Ok'> "; echo "</form>"; echo "</td>"; echo "<td>"; if(isset($_POST['stateboxbutton'])){ $statesearch = $_POST['statebox']; $selected = $_POST['statebox']; $select = "<option name='statebox'>$selected</option>"; echo "<br/><form action='../search-results.php' method='POST'>"; echo "<select name='search'>"; echo "<option name='default'>Step 2. Pick Your County</option>"; /////////////////////////////////////////////////////////////// //Connect to the database include_once 'phpforms/connect.php'; $sql = mysql_query("SELECT * FROM counties WHERE state LIKE '$statesearch'"); while($row = mysql_fetch_array($sql)){ $co = $row['counties']; echo "<option name='county'>$co</option>"; }//End While /////////////////////////////////////////////////////////////// echo "</select>"; echo "<input align='left' type='submit' name='button' value='Search'> "; echo "</form>"; }else{ }//End Else ?> So I'm making an ordering form for pizza, and it works fine and im using two separate pages: 1- display the form where the user can select the pizza, and 2-display the order and the price, and user can go back and edit the problem im having is when i got back from the 2nd page to the 1st page, to edit the data, I want the variables to stay the same. For example, if the user selected a medium cheese pizza, i want the values of cheese and pizza to still be there, so the user doesnt have to fill the entire form out again. ive done this before, but now when i try it doesn''t work and Ive tried everything. Thanks in advance If the code is needed, I'll post it here Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> <html> <head> <title>Title of the document</title> <meta name="description" content="Type a Short Description Here" /> <meta name="keywords" content="type, keywords, here" /> <meta name="author" content="Your Name" /> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="mystyle.css" /> </head> <body> <?php print_r ($_REQUEST) ; if(isset($_POST['ORDER'])) { $ORDER = $_POST['ORDER']; } if(isset($_POST['PTYPE'])) { $PTYPE = $_POST['PTYPE']; } if(isset($_POST['DTYPE'])) { $DTYPE = $_POST['DTYPE']; } if(isset($_POST['PSIZE'])) { $PSIZE = $_POST['PSIZE']; } if(isset($_POST['DSIZE'])) { $DSIZE = $_POST['DSIZE']; } if(isset($_POST['PTYPE2'])) { $PTYPE2 = $_POST['PTYPE2']; } if(isset($_POST['DTYPE2'])) { $DTYPE2 = $_POST['DTYPE2']; } if(isset($_POST['PSIZE2'])) { $PSIZE2 = $_POST['PSIZE2']; } if(isset($_POST['DSIZE2'])) { $DSIZE2 = $_POST['DSIZE2']; } if(isset($_POST['PTYPE3'])) { $PTYPE3 = $_POST['PTYPE3']; } if(isset($_POST['DTYPE3'])) { $DTYPE3 = $_POST['DTYPE3']; } if(isset($_POST['PSIZE3'])) { $PSIZE3 = $_POST['PSIZE3']; } if(isset($_POST['DSIZE3'])) { $DSIZE3 = $_POST['DSIZE3']; } echo "Order Type: <br/> \n"; echo"<form method='post' action='project2.php'>"; }if ($ORDER=='delivery') { $DEL='checked' ; }elseif ($ORDER=='takeout') { $TAKE='checked'; }elseif ($ORDER=='eatin') { $EAT='checked'; } echo"Delivery <input type='radio' name='ORDER' value='delivery' $DEL> \n"; echo"Take Out <input type='radio' name='ORDER' value='takeout' $TAKE> \n"; echo"Eat in <input type='radio' name='ORDER' value='eatin' $EAT> \n"; if ($PTYPE==='no pizza') { $NOPIZZA='selected' ; }elseif ($PTYPE=='cheese') { $CHEESE='selected' ; }elseif ($PTYPE=='pepporoni') { $PEPPORONI='selected' ; }elseif ($PTYPE=='veggie') { $VEGGIE='selected' ; }elseif ($PTYPE=='meat lovers') { $MEAT='selected' ; } echo $CHEESE ; echo"<br/>Pizza: <select name='PTYPE'>\n"; echo"<option></option>"; echo"<option $NOPIZZA>no pizza</option>"; echo"<option $CHEESE>cheese</option>"; echo"<option $PEPPORONI>pepporoni</option>"; echo"<option $VEGGIE>veggie</option>"; echo"<option $MEAT>meat lovers</option>"; echo"</select> "; $SMALL='selected' ; if (isset ($_POST['PSIZE']) && ($PSIZE=='Small')) { $SMALL='selected' ; }elseif (isset ($_POST['PSIZE']) && ($PSIZE=='Medium')) { $MEDIUM='selected' ; }elseif (isset ($_POST['PSIZE']) && ($PSIZE=='Large')) { $LARGE='selected' ; } echo "$SMALL"; echo" Pizza size: <select name='PSIZE'>\n"; echo"<option></option>"; echo"<option $SMALL>Small</option>"; echo"<option $MEDIUM>Medium</option>"; echo"<option $LARGE>Large</option>"; echo"</select>"; echo"<br/>Pizza2: <select name='PTYPE2'>\n"; echo"<option></option>"; echo"<option >no pizza</option>"; echo"<option >cheese</option>"; echo"<option >pepporoni</option>"; echo"<option >veggie</option>"; echo"<option >meat lovers</option>"; echo"</select> "; echo" Pizza size2: <select name='PSIZE2'>\n"; echo"<option></option>"; echo"<option>Small</option>"; echo"<option>Medium</option>"; echo"<option>Large</option>"; echo"</select>"; echo"<br/>Pizza3: <select name='PTYPE3'>\n"; echo"<option></option>"; echo"<option >no pizza</option>"; echo"<option >cheese</option>"; echo"<option >pepporoni</option>"; echo"<option >veggie</option>"; echo"<option >meat lovers</option>"; echo"</select> "; echo"Pizza size3: <select name='PSIZE3'>\n"; echo"<option></option>"; echo"<option>Small</option>"; echo"<option>Medium</option>"; echo"<option>Large</option>"; echo"</select>"; echo"</br> <br/>What drink would you like? <select name='DTYPE'>"; echo"<option></option>"; echo"<option>No drink</option>"; echo"<option>Bottled Pepsi</option>"; echo"<option>Bottled Fanta</option>"; echo"<option>Bottled Sprite</option>"; echo"<option>Bottled RootBeer</option>"; echo"</select>"; echo"Drink size: <select name='DSIZE'>"; echo"<option></option>"; echo"<option>.5 liter</option>"; echo"<option>1 liter</option>"; echo"<option>2 liter</option>"; echo"</select>"; echo"</br> <br/>What second drink would you like? <select name='DTYPE2'>"; echo"<option></option>"; echo"<option>No drink</option>"; echo"<option>Bottled Pepsi</option>"; echo"<option>Bottled Fanta</option>"; echo"<option>Bottled Sprite</option>"; echo"<option>Bottled RootBeer</option>"; echo"</select>"; echo"Drink size2: <select name='DSIZE2'>"; echo"<option></option>"; echo"<option>.5 liter</option>"; echo"<option>1 liter</option>"; echo"<option>2 liter</option>"; echo"</select>"; echo"</br> <br/>What third drink would you like? <select name='DTYPE3'>"; echo"<option></option>"; echo"<option>No drink</option>"; echo"<option>Bottled Pepsi</option>"; echo"<option>Bottled Fanta</option>"; echo"<option>Bottled Sprite</option>"; echo"<option>Bottled RootBeer</option>"; echo"</select>"; echo"Drink size3: <select name='DSIZE3'>"; echo"<option></option>"; echo"<option>.5 liter</option>"; echo"<option>1 liter</option>"; echo"<option>2 liter</option>"; echo"</select>"; echo"<br/> <br/> <input type='submit' value='submit your order' name='submit'>"; echo"</form>"; ?> </body> </html> and the second page Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> <html> <head> <title>Title of the document</title> <meta name="description" content="Type a Short Description Here" /> <meta name="keywords" content="type, keywords, here" /> <meta name="author" content="Your Name" /> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="mystyle.css" /> </head> <body> <?php print_r ($_REQUEST) ; $ORDER = $_POST['ORDER']; $PTYPE = $_POST['PTYPE']; $DTYPE = $_POST['DTYPE']; $PSIZE = $_POST['PSIZE']; $DSIZE = $_POST['DSIZE']; $PTYPE2 = $_POST['PTYPE2']; $DTYPE2 = $_POST['DTYPE2']; $PSIZE2 = $_POST['PSIZE2']; $DSIZE2 = $_POST['DSIZE2']; $PTYPE3 = $_POST['PTYPE3']; $DTYPE3 = $_POST['DTYPE3']; $PSIZE3 = $_POST['PSIZE3']; $DSIZE3 = $_POST['DSIZE3']; if (($PTYPE=='cheese')and($PSIZE=='Small')) { $PCOST=10 ; }elseif (($PTYPE=='cheese')and($PSIZE=='Medium')) { $PCOST=13 ; }elseif (($PTYPE=='cheese')and($PSIZE=='Large')) { $PCOST=15 ; }elseif (($PTYPE=='pepporoni')and($PSIZE=='Small')) { $PCOST=12 ; }elseif (($PTYPE=='pepporoni')and($PSIZE=='Medium')) { $PCOST=14 ; }elseif (($PTYPE=='pepporoni')and($PSIZE=='Large')) { $PCOST=16 ; }elseif (($PTYPE=='veggie')and($PSIZE=='Small')) { $PCOST=12 ; }elseif (($PTYPE=='veggie')and($PSIZE=='Medium')) { $PCOST=14 ; }elseif (($PTYPE=='veggie')and($PSIZE=='Large')) { $PCOST=16 ; }elseif (($PTYPE=='meat lovers')and($PSIZE=='Small')) { $PCOST=13 ; }elseif (($PTYPE=='meat lovers')and($PSIZE=='Medium')) { $PCOST=15 ; }elseif (($PTYPE=='meat lovers')and($PSIZE=='Large')) { $PCOST=17; }else { $PCOST=0 ; } if (($PTYPE2=='cheese')and($PSIZE2=='Small')) { $PCOST2=10 ; }elseif (($PTYPE2=='cheese')and($PSIZE2=='Medium')) { $PCOST2=13 ; }elseif (($PTYPE2=='cheese')and($PSIZE2=='Large')) { $PCOST2=15 ; }elseif (($PTYPE2=='pepporoni')and($PSIZE2=='Small')) { $PCOST2=12 ; }elseif (($PTYPE2=='pepporoni')and($PSIZE2=='Medium')) { $PCOST2=14 ; }elseif (($PTYPE2=='pepporoni')and($PSIZE2=='Large')) { $PCOST2=16 ; }elseif (($PTYPE2=='veggie')and($PSIZE2=='Small')) { $PCOST2=12 ; }elseif (($PTYPE2=='veggie')and($PSIZE2=='Medium')) { $PCOST2=14 ; }elseif (($PTYPE2=='veggie')and($PSIZE2=='Large')) { $PCOST2=16 ; }elseif (($PTYPE2=='meat lovers')and($PSIZE2=='Small')) { $PCOST2=13 ; }elseif (($PTYPE2=='meat lovers')and($PSIZE2=='Medium')) { $PCOST2=15 ; }elseif (($PTYPE2=='meat lovers')and($PSIZE2=='Large')) { $PCOST2=17; }else { $PCOST2=0 ; } if (($PTYPE3=='cheese')and($PSIZE3=='Small')) { $PCOST3=10 ; }elseif (($PTYPE3=='cheese')and($PSIZE3=='Medium')) { $PCOST3=13 ; }elseif (($PTYPE3=='cheese')and($PSIZE3=='Large')) { $PCOST3=15 ; }elseif (($PTYPE3=='pepporoni')and($PSIZE3=='Small')) { $PCOST3=12 ; }elseif (($PTYPE3=='pepporoni')and($PSIZE3=='Medium')) { $PCOST3=14 ; }elseif (($PTYPE3=='pepporoni')and($PSIZE3=='Large')) { $PCOST3=16 ; }elseif (($PTYPE3=='veggie')and($PSIZE3=='Small')) { $PCOST3=12 ; }elseif (($PTYPE3=='veggie')and($PSIZE3=='Medium')) { $PCOST3=14 ; }elseif (($PTYPE3=='veggie')and($PSIZE3=='Large')) { $PCOST3=16 ; }elseif (($PTYPE3=='meat lovers')and($PSIZE3=='Small')) { $PCOST3=13 ; }elseif (($PTYPE3=='meat lovers')and($PSIZE3=='Medium')) { $PCOST3=15 ; }elseif (($PTYPE3=='meat lovers')and($PSIZE3=='Large')) { $PCOST3=17; }else { $PCOST3=0 ; } if((($DTYPE=='Bottled Pepsi')or($DTYPE=='Bottled Fanta')or($DTYPE=='Bottled Sprite')or($DTYPE=='Bottled RootBeer'))and($DSIZE=='.5 liter')) { $DCOST=.69 ; }elseif((($DTYPE=='Bottled Pepsi')or($DTYPE=='Bottled Fanta')or($DTYPE=='Bottled Sprite')or($DTYPE=='Bottled RootBeer'))and($DSIZE=='1 liter')) { $DCOST=.99 ; }elseif((($DTYPE=='Bottled Pepsi')or($DTYPE=='Bottled Fanta')or($DTYPE=='Bottled Sprite')or($DTYPE=='Bottled RootBeer'))and($DSIZE=='2 liter')) { $DCOST=1.69 ; }elseif($DTYPE=='No drink'){ $DCOST=0 ; } if((($DTYPE2=='Bottled Pepsi')or($DTYPE2=='Bottled Fanta')or($DTYPE2=='Bottled Sprite')or($DTYPE2=='Bottled RootBeer'))and($DSIZE2=='.5 liter')) { $DCOST2=.69 ; }elseif((($DTYPE2=='Bottled Pepsi')or($DTYPE2=='Bottled Fanta')or($DTYPE2=='Bottled Sprite')or($DTYPE2=='Bottled RootBeer'))and($DSIZE2=='1 liter')) { $DCOST2=.99 ; }elseif((($DTYPE2=='Bottled Pepsi')or($DTYPE2=='Bottled Fanta')or($DTYPE2=='Bottled Sprite')or($DTYPE2=='Bottled RootBeer'))and($DSIZE2=='2 liter')) { $DCOST2=1.69 ; }elseif($DTYPE2=='No drink'){ $DCOST2=0 ; } if((($DTYPE3=='Bottled Pepsi')or($DTYPE3=='Bottled Fanta')or($DTYPE3=='Bottled Sprite')or($DTYPE3=='Bottled RootBeer'))and($DSIZE3=='.5 liter')) { $DCOST3=.69 ; }elseif((($DTYPE3=='Bottled Pepsi')or($DTYPE3=='Bottled Fanta')or($DTYPE3=='Bottled Sprite')or($DTYPE3=='Bottled RootBeer'))and($DSIZE3=='1 liter')) { $DCOST3=.99 ; }elseif((($DTYPE3=='Bottled Pepsi')or($DTYPE3=='Bottled Fanta')or($DTYPE3=='Bottled Sprite')or($DTYPE3=='Bottled RootBeer'))and($DSIZE3=='2 liter')) { $DCOST3=1.69 ; }elseif($DTYPE3=='No drink'){ $DCOST3=0 ; } $TOTAL=($PCOST+$PCOST3+$PCOST3+$DCOST+$DCOST2+$DCOST3) ; echo "<br/><br/>Your Order is:<br/>" ; echo " $PSIZE $PTYPE ($PCOST),$PSIZE2 $PTYPE2 ($PCOST2),$PSIZE3 $PTYPE3 ($PCOST3), <br/>" ; echo " $DSIZE $DTYPE ($DCOST),$DSIZE2 $DTYPE2 ($DCOST2),$DSIZE3 $DTYPE3 ($DCOST3), <br/> <br/>" ; echo"<br/><br/>Your total price is: $TOTAL <br/> <br/>"; if ($ORDER=='delivery') { echo"Please enter the information required for delivery <br/>" ; echo "Address: <input type=text><br/>"; echo "City: <input type=text><br/>"; echo "Zip Code: <input type=text><br/>"; } elseif ($ORDER=='takeout') { echo "Your order will be ready for pickup in 30 min"; } elseif ($ORDER=='eatin') { echo "Your order will be ready in 30 min"; } echo"<form action=asdf.php>"; echo"<br/> <input type=submit value='confirm this order'>"; echo"</form>"; echo "<form action=project.php>"; echo "<br/> <br/><input type=submit value='edit this order'>"; echo "<input type='hidden' name='ORDER' value='$ORDER'>"; echo "<input type='hidden' name='PTYPE' value='$PTYPE'>"; echo "<input type='hidden' name='PTYPE2' value='$PTYPE2'>"; echo "<input type='hidden' name='PTYPE3' value='$PTYPE3'>"; echo "<input type='hidden' name='PSIZE' value='$PSIZE'>"; echo "<input type='hidden' name='PSIZE2' value='$PSIZE2'>"; echo "<input type='hidden' name='PSIZE3' value='$PSIZE3'>"; echo "<input type='hidden' name='DTYPE' value='$DTYPE'>"; echo "<input type='hidden' name='DTYPE2' value='$DTYPE2'>"; echo "<input type='hidden' name='DTYPE3' value='$DTYPE3'>"; echo "<input type='hidden' name='DSIZE' value='$DSIZE'>"; echo "<input type='hidden' name='DSIZE2' value='$DSIZE2'>"; echo "<input type='hidden' name='DSIZE3' value='$DSIZE3'>"; echo "</form>"; ?> </body> </html> Hi everyone. I am David and I am new to web design and php. I am following a Lynda.com tutorial on php and sql. I have reached a certain point in the tutorial where I am reading values back from my database in to a php variable. The variable is holding an array data type and I am accessing the element within the array. I want a HTML select control and 2 radios buttons to reflect the values in the database. Therefore the Select control should read a numeric value of type int and the radio buttons are reflecting either a 1 or a 0. Firstly the code for the Select control uses a for loop to count the array elements and load the count into the Select control. The example uses php mixed with html. The for loop will count the number of element and add a number to the select control. The an If statment is used to make a decision if the count variable equals the value in the array element $sel_subject['position'] then select that value. This does not happen, and I can not seem to get it to work. <p>Position: <select name="position"> <!--use a php block so as to use some php variables --> <!--Use these variables with the get_all_sublects function. --> <!-- This function will return all the dataset --> <?php $sel_subject = get_all_subjects(); //Then use the mysql fuction to retuen the numberic value of all the rows. $subject_count = mysql_num_rows($sel_subject); //$subject_count + 1 becauce we are adding a subject for($count=1; $count <= $subject_count+1; $count++) { echo "<option value=\"{$count}\""; if ($sel_subject['position'] == $count) { echo " selected"; } echo ">{$count}</option>"; } ?> </select> </p> Secondly the radio buttons do something similar in that i want them to reflect the value in the array element. If a 1 then True and so be checked or 0 and so false and so be unchecked. <p>Visible: <input type= "radio" name= "visible" value= "0" <?php if ($sel_subject['visible'] == 0) { echo 'checked=" checked"'; } ?> >No</input> <input type= "radio" name= "visible" value= "1" <?php if ($sel_subject['visible'] == 1) { echo 'checked=" checked"'; } ?> >Yes</input> </p> Again this doesn't work either. So in summary, I cant get the php code to affect the html form controls and relay the stored data to the user. I have been racking my brain for days and getting no where. Please can anyone help me with this. I would be very grateful. All the best Irish_Dave Hello, I need to do the following: I have 2 forms on two different pages: Form 1: Name, Email, Phone Form 2: Name, Email, Phone, Address, etc. 1. User fills out Form 1, presses submit 2. Form 1 gets processed and I receive an email with the visitors Name, Email, Phone 3. After the Form has been processed I need to redirect the visitor to a new page (Form 2) 4. When Form 2 loads, fill in the form with the posted variables (Name, Email, Phone) from the previous process Here is my code: Form 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <form method="post" action="process_form.php"> <input type="text" name="name" /> <input type="text" name="email" /> <input type="text" name="phone" /> <input type="submit" name="submit" value="submit" /> </form> </div> </body> </html> process_form.php <?php $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $to = 'email@provider.com'; $subject = "Contact Form"; $message = "Contact Information\r\n" ."$name\r\n" ."$email\r\n" ."$phone\r\n\"; $headers = "From: $email\r\n"; mail($to, $subject, $message, $headers); // Redirect header("Location: http://www.domain.com/form2/"); ?> Form 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <form method="post" action="process_form_2.php"> <input type="text" name="name" /> <input type="text" name="email" /> <input type="text" name="phone" /> <input type="text" name="address" /> <input type="text" name="city" /> <input type="text" name="state" /> . . . <input type="submit" name="submit" value="submit" /> </form> </div> </body> </html> The form does get processed and I do get an email with the visitor's info. But I'm not able to pass on the variables from From1 to Form2. Thank you in advance. |