PHP - Editing A Form After Submitting
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? 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'); } ?> 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? 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 a firm that post to my database. When I tested it always posted my information correctly. I require the user to be logged in before they can access the page with the form. I do I ensure that each php variable has a value in it before the data is posted? Any help would be appreciated. I can post my code if needed. i have a php script and i want it to submit to itself having the php script on the same page, the problem is when i do it it tries to upload the file without waiting for the form resaulting in format you tried to upload was not allowed" (its an image uploader) heres my code Code: [Select] <?php // Configuration - Your Options $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation. $max_filesize = 1524288; // Maximum filesize in BYTES (currently 1.5MB). $upload_path = './files/'; // The place the files will be uploaded to (currently a 'files' directory). $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension). $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. // Check if the filetype is allowed, if not DIE and inform the user. if(!in_array($ext,$allowed_filetypes)) die('<font size="4"><font color="red">The file you attempted to upload is not allowed.</font></font>'); // Now check the filesize, if it is too large then DIE and inform the user. if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize) die('The file you attempted to upload is too large.'); // Check if we can upload to the specified path, if not DIE and inform the user. if(!is_writable($upload_path)) die('You cannot upload to the specified directory, please CHMOD it to 777.'); // Upload the file to your specified path. if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) echo '<font size="4"><span style="color: white; text-shadow: lime 0px 0px 3px;"><h2>Upload Successful!</h2><br> <img src="' . $upload_path . $filename . '"><br> <p id="codes"><label for="codedirect">Direct Link:</label><br /> <input type="text" id="codebb" value="http://imageplanet.site90.net/' . $upload_path . $filename . '" onclick="javascript:this.focus();this.select();" readonly="true" /><br /> <label for="codehtml">HTML code:</label><br /> <input type="text" id="codehtml" value="<img src="http://imageplanet.site90.net/' . $upload_path . $filename . '">" onclick="javascript:this.focus();this.select();" readonly="true" /><br /> <label for="codebb">IMG code:</label><br /> <input type="text" id="codebb" value="[IMG]http://imageplanet.site90.net.info/' . $upload_path . $filename . '[/IMG]" onclick="javascript:this.focus();this.select();" readonly="true" /></p></div> </span></font>'; // It worked. else echo '<font size="4"><font color="red">There was an error during the file upload. Please try again.</font</font>'; // It failed :(. ?> <form action="upload.php" method="post" enctype="multipart/form-data"> <p> <label for="file"><font color="white">Select a image:</font></label> <br><br> <input type="file" name="userfile" id="file"> <br /> <button>Click Here To Upload</button> <p> <br> <br> <font color="#006FFF"><span style="font-family: Criovision; font-weight: normal; font-style: normal; text-decoration: none; font-size: 15pt;">Max File Upload Size: 1.5MB<br></span></font> </div> </span> i just want it so it doesn't display that error I have this HTML form that isn't doing anything when the submit button pressed, I am using PHP to validate it. I know I am missing something, can you help me? :/ Thanks in advance! Code: [Select] <?php require("styles/top.php");?> <div id="head_reg"> <div id="head_cen_reg"> <div id="head_sup_reg" class="head_height_reg"> <p class="search"> <label>SEARCH</label> <input name="search" type="text" class="txt" /> <input name="search-btn" type="submit" class="btn" value="SEARCH" /> </p> <h1 class="logo"></h1> <?php require("scripts/links.php"); ?> </div> </div> </div> <div id="content"> <br /> <div id="register_form"> <form action="register.php" method="post" enctype="multipart/form-data"> <center> <table> <tr> <td>Desired Username </td> <td><input type="text" name="username" class="textbox" /></td> </tr> <tr> <td>E-Mail </td> <td><input type="text" name="email" class="textbox" /></td> </tr> <tr> <td>Password </td> <td><input type="text" name="pass" class="textbox" /></td> </tr> <tr> <td>Confirm Password </td> <td><input type="text" name="repass" class="textbox" /></td> </tr> <tr> <td><p class="register"> <input name="reg-btn" type="submit" class="btn" value="REGISTER" /> </p></td> </tr> </table> </center> </form> </div> <center><a href="#" id="showreg">Why register? Click here</a></center> <div id="content_cen"> <div id="content_sup"> <div id="welcom_pan"> <h3><span>Why</span> Register?</h3> <p>Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nulla vitae diam magna, eget fringilla tellus. Curabitur est velit, suscipit eu faucibus eget, aliquam ac enim. per inceptos himenaeos. Nulla vitae diam magna, eget fringilla tellus.</p> </div> </div> </div> </div> <div id="foot"> <div id="foot_cen"> <ul> </ul> <p></p> </div> </div> <?php if(isset($_POST['reg_btn'])){ $username = $_POST['username']; $email = $_POST['email']; $password = $_POST['pass']; $repassword = $_POST['repass']; if ($username && $password && $repassword && $email){ if ($password == $repassword){ if (strstr($email, "@") && strstr($email, ".") && (strlen($email) >= 6)){ $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows == 0){ $query = mysql_query("SELECT * FROM users WHERE email='$email'"); $numrows = mysql_num_rows($query); if ($numrows == 0){ $pass = md5(md5($password)); $ip = $_SERVER['REMOTE_ADDR']; $date = date("F,d,Y:g:i:s A"); mysql_query("INSERT INTO users VALUES ('', '$username', '$pass', '$email','Member', '$date', '', '$ip', '0')"); } else echo"That email is already in use!"; } else echo"That username is already taken!"; } else echo"That email is too short!"; } else echo"Those passwords do not match!"; } else echo"<script type='text/javascript'>alert('You did not fill out the entire form!')</script>"; } ?> Got this page, a player clicks the "accept challenge" button, then it is recorded in the database that the challenge as been started and once the form has been self submitted, the button is disabled. It does what I expect, but I have to refresh the page again for the button to be displayed as disabled. How can I do it so the page is changed once the form has been submitted? Code: [Select] <?php session_start();what but after clicking a button I have to refresh the page again, before the button is displayed as disabled include('functions.php'); connect(); ?> <!DOCTYPE html> <html> <head> <title>University Crusade</title> <link rel="stylesheet" href="css/style.css" type="text/css" media="screen"> <meta name="viewport" content="width=device-width, minimum-scale=1,maximum-scale=1, user-scalable=no"> </head> <body> <?php if (isset($_SESSION['userid'])) { include('safe.php'); if (isset($_POST['start1'])) { mysql_query("UPDATE chal1 SET start1=1 WHERE userid='".$_SESSION['userid']."'") or die ("Could not update start1"); } if (isset($_POST['start2'])) { mysql_query("UPDATE chal1 SET start2=1 WHERE userid='".$_SESSION['userid']."'") or die ("Could not update start2"); } if (isset($_POST['start3'])) { mysql_query("UPDATE chal1 SET start3=1 WHERE userid='".$_SESSION['userid']."'") or die ("Could not update start3"); } ?> <ul id="tab-nav"> <li><a href="stats.php" id="tab-character">Character</a></li> <li><a href="games.php" class="active" id="tab-games">Games</a></li> <li><a href="account.php" id="tab-account">Account</a></li> </ul> <div id="wrapper"> <h2 id="name">Select a Challenge</h2> <ul id="table-view"> <li> <fieldset> <legend>"Easter Egg" Challenge</legend> <div id="rewards"> <p class="instructions"> Find each of the 4 "Easter Egg" barcodes around the university campus. </p> <p> Rewards: Every egg is worth <span class="stat">50</span> XP and <span class="stat">35</span> gold coins. </p> </div> <form action="games.php" method="POST"> <?php if ($start1 == 1) { echo "<br />The value is 1"; echo "<button class=\"buttons\" type=\"submit\" name=\"start1\" disabled=\"disabled\">Accept challenge</button>"; } elseif ($start1 == 0) { echo "<br />The value is 0"; echo "<button class=\"buttons\" type=\"submit\" name=\"start1\">Accept challenge</button>"; } ?> </form> </fieldset> </li> <li class="even"> <fieldset> <legend>Increase Strength</legend> <div id="rewards"> <p class="instructions"> You'll find the barcode in the Sports Centre. </p> <p> Rewards: Every time you visit the Sports Centre you'll receive <span class="stat">2</span> Str. points. </p> </div> <form action="games.php" method="POST"> <?php if ($start2 == 1) { echo "<br />The value is 1"; echo "<button class=\"buttons\" type=\"submit\" name=\"start2\" disabled=\"disabled\">Accept challenge</button>"; } elseif ($start2 == 0) { echo "<br />The value is 0"; echo "<button class=\"buttons\" type=\"submit\" name=\"start2\">Accept challenge</button>"; } ?> </form> </fieldset> </li> <li> <fieldset> <legend>Increase Intelligence</legend> <div id="rewards"> <p class="instructions"> You'll find the barcode in the university Library. </p> <p> Rewards: Every time you visit the Library you'll receive <span class="stat">2</span> Int. points. </p> </div> <form action="games.php" method="POST"> <?php if ($start3 == 1) { echo "<br />The value is 1"; echo "<button class=\"buttons\" type=\"submit\" name=\"start3\" disabled=\"disabled\">Accept challenge</button>"; } elseif ($start3 == 0) { echo "<br />The value is 0"; echo "<button class=\"buttons\" type=\"submit\" name=\"start3\">Accept challenge</button>"; } ?> </form> </fieldset> </li> </ul> </div> <div id="footer"> <a class="buttons" href="logout.php">log me out</a> </div> <?php } else { die (" <div id=\"wrapper\"> <p>Opps! You don't seem to be logged in...</p> <a class=\"buttons\" href=\"index.php\">login now</a><br /> <p>Don't have an account? No worries, just <a class=\"buttons\" href=\"register.php\">register for one.</a></p> </div> "); } ?> Thanks Hi - I have a form which is populated with values from a DB. This is done by looping through the DB values using a foreach. It works fine. I populate my form with those values. However, I want to be able to amend those values, and then submit the new values back to the DB with 1 single submit button. I don't want a separate submit button for each row of my form. The problem is that because the form is built with a foreach, as the it loops through the variables on each pass of the DB, only the final row of DB are present in the form variables. Question: My 'foreach' approach must be faulty. What is the mechanism or approach I need to use to update the values from the whole form ?? MANY THANKS for all your help !! I am trying to learn how to program in PHP. For a long time i was using WAMP and my localhost. When i ran into trouble i searched the web, watched videos and eventually find a solution.
Trying to upload my scripts into a shared hosting web server i had some difficulties in basic things, like using $_SESSION superglobal variable.
What i want to do is to use a hidden field with a value inside a form, and after submitting the form, to compare the $_SESSION variable to the $_POST variable in order to check for CSRF.
<?php //call all custom functions require_once('Custom_Functions/functions.php'); //session must be send before HTML headers secure_session_start(); ?> <!DOCTYPE html> <html lang="en"> <body> <?php if(isset($_POST['submit'])) { $postvalue = $_POST['input1']; $sessionvalue = $_SESSION['hashed_token']; echo '<br />==========================<br />'; echo '<br />AFTER PRESSING SUBMIT<br />'; echo '<br />==========================<br />'; echo 'Value of $_POST["hashed_token"] = '.$postvalue.'<br />'; echo 'Value of $_SESSION["hashed_token"] = '.$sessionvalue.'<br />'; } $hashed_token = hash('sha256', uniqid(mt_rand(), TRUE)); $_SESSION['hashed_token'] = $hashed_token; echo '<br />==========================<br />'; echo '<br />BEFORE PRESSING SUBMIT<br />'; echo '<br />==========================<br />'; echo '<br />Value of $_SESSION["hashed_token"] = '.$hashed_token.'<br />'; ?> <form action="" method="POST"> <input type="hidden" name="input1" value="<?php echo $hashed_token; ?>" /> <p><input type="submit" name="submit" /></p> </form> </body> </html>In this script i have 1 custom function: a) secure_session_start() function secure_session_start(){ //Set a custom session name $session_name = 'TESTSESSID'; ini_set('session.use_only_cookies', 1); ini_set('session.entropy_file', '/dev/urandom'); if (in_array('sha512', hash_algos())) { ini_set('session.hash_function', 'sha256'); } ini_set('session.use_trans_sid', 0); ini_set('session.hash_bits_per_character', 5); ini_set('session.cookie_secure', 1); $secure = TRUE; $httponly = TRUE; $cookieParams = session_get_cookie_params(); session_set_cookie_params($cookieParams['lifetime'], $cookieParams['path'], $cookieParams['domain'], $secure, $httponly); session_name($session_name); ini_set("session.save_path", "/home/SESSIONS"); session_start(); }The procedure goes as follows: FIRST COMMUNICATION WITH THE SERVER: The superglobal variable $_SESSION['hashed_token'] is assigned the random hash value, which is then passed to the hidden input field. I then echo it. RESULT: ========================== BEFORE PRESSING SUBMIT ========================== Value of $_SESSION["hashed_token"] = 93438a1b9b72085ce9430291acebdc4cfdee9d001b91a26207aebc22e04689fc SECOND COMMUNICATION WITH THE SERVER: The user press the submit button, the script then checks if the submit button is pressed, and gets in the if statement(because is TRUE). Then i collect the $_POST and $_SESSION values and echo them. New random hash is assigned to the $_SESSION superglobal variable. RESULT: ========================== AFTER PRESSING SUBMIT ========================== Value of $_POST["hashed_token"] = 93438a1b9b72085ce9430291acebdc4cfdee9d001b91a26207aebc22e04689fc Value of $_SESSION["hashed_token"] = 8f176aeb3a09a1b30e0ea862c78625d7c11743da933d366cface3fa238388e57 ========================== BEFORE PRESSING SUBMIT ========================== Value of $_SESSION["hashed_token"] = c3442382b146f03394ad86911018247c57fa19d4a653d0bf6bb9bc7506e88ca0 For me this is very weird. The random hash is assigned to the $_SESSION variable, but when i try to call it after the submit is pressed its giving me a complete different value. If i remove the function secure_session_start() and just use session_start() it works: RESULT (using session_start() ) ========================== AFTER PRESSING SUBMIT ========================== Value of $_POST["hashed_token"] = a5eaaaa38c428af623a599e664ea9c64a2ff0674e18e9250c54e52bbc586b614 Value of $_SESSION["hashed_token"] = a5eaaaa38c428af623a599e664ea9c64a2ff0674e18e9250c54e52bbc586b614 ========================== BEFORE PRESSING SUBMIT ========================== Value of $_SESSION["hashed_token"] = e2d4acc239a747217860d71a80553abd41142dbeb8f6fafab511caff8a081fc4 Any ideas why this is happening? The problem is inside the secure_session_start() function but i cant find out why. Also, when i use the secure_session_start() function and more specifically the ini_set("session.save_path", "/home/SESSIONS"); i am forcing the session to be stored inside the /home/SESSIONS folder. But when i only use the session_start() the session i still gets stored inside that path. I checked my .htaccess and there is nothing storing the sessions in that folder. Why is that? One last thing: When using FIREBUG-->Cookies is see 2 names: the custom one (TESTSESSID) and PHPSESSID(which is the default). Shouldnt i only see the custom session name only? Thanks in advance. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=316807.0 I have PHP forms that are not submitting to my database. I think it is something minor but I just can't see it! Can anyone help? At the beginning of index.php, the page holding the forms, I have this: Code: [Select] [b]<?php include("functions/globals.php"); ?> <?php include("functions/userfunctions.php"); ?>[/b] [b]Here are these pages:[/b] [b]globals.php[/b] <?php ob_start();//Required for the redirect to work?> <?php include("loginstatus.php");?> <?php session_start(); ?> [b]((Here's loginstatus.php for good measu [/b] <?php class cUser { public $username = "";//The User Name public $userid = "";//The User ID public $type = "";//The Type Of User } ?> [b]))[/b] [b]And here is userfunctions.php[/b] <?php include_once("databasefunctions.php"); (this holds the connection) $userdbtable = "users"; function GetHeaders() { $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= "To: {$username} <{$email}>" . "\r\n"; $headers .= 'From: My Website <[email]noreply@myswebsite.com[/email]>' . "\r\n"; return $headers; } function CreateAccount($firstname, $lastname, $username, $password, $email, $type) { global $userdbtable; openDatabase(); $firstname = mysql_real_escape_string($firstname); $lastname = mysql_real_escape_string($lastname); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $email = mysql_real_escape_string($email); $type = mysql_real_escape_string($type); $nonencrypted = $password; $password = sha1($password); $result = QuickQuery("INSERT INTO {$userdbtable}(firstname, lastname, username, password, email, type) VALUES('{$firstname}','{$lastname}','{$username}','{$password}','{$email}',{$type}')"); if($result) { $headers = GetHeaders(); $message = "\"Welcome to my website!\"<br /> <br /> Your username is: {$username}<br /> Your password is: {$nonencrypted}<br /> <br /> Signed,<br /> <br /> Me "; mail($email, "Account Creation", $message, $headers); mail("[email]myemailaddress@me.com[/email]", "Account Created", "{$username} has created a new account", $headers); } } function ValidateUser($username, $password) { global $userdbtable; openDatabase(); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $result = QuickQuery("SELECT * FROM {$userdbtable} WHERE username = '{$username}'"); closeDatabase(); if(!mysql_result($result,0,"username"))//Make sure the user exists return "User Does Not Exist"; $temppwd=mysql_result($result,0,"password");//Make sure the passwords match if(sha1($password) != $temppwd) return "Password Does Not Match"; return 1; } function GetUserID($username) { global $userdbtable; openDatabase(); $username = mysql_real_escape_string($username); $result = QuickQuery("SELECT id FROM {$userdbtable} WHERE username = '{$username}'"); closeDatabase(); if($result) return(mysql_result($result,0,"id"));//Get the user id else return 0; return(mysql_result($result,0,"id"));//Get the UserID } function GetUserType($username) { global $userdbtable; openDatabase(); $username = mysql_real_escape_string($username); $result = QuickQuery("SELECT type FROM {$userdbtable} where username = '{$username}'"); closeDatabase(); return(mysql_result($result,0,"type"));//Get the user type } function GetUserEmail($username) { global $userdbtable; openDatabase(); $username = mysql_real_escape_string($username); $result = QuickQuery("SELECT email FROM {$userdbtable} WHERE username = '{$username}'"); closeDatabase(); return(mysql_result($result,0,"email"));//Get the user email } function ConfirmPassword($id, $password) { global $userdbtable; openDatabase(); $password = mysql_real_escape_string($password); $password = sha1($password); $result = QuickQuery("SELECT * FROM {$userdbtable} WHERE id = '{$id}' AND password = '{$password}'"); closeDatabase(); if(!$result) return 0; else return 1; } function ChangePassword($id, $password) { global $userdbtable; openDatabase(); $password = mysql_real_escape_string($password); $password = sha1($password); return QuickQuery("UPDATE {$userdbtable} SET password='{$password}' WHERE id={$id}"); } function ResetPassword($email) { global $userdbtable; openDatabase(); $email = mysql_real_escape_string($email); $result = QuickQuery("SELECT * FROM {$userdbtable} WHERE email = '{$email}'"); $num = mysql_numrows($result); if(!$num) return 0; $user = mysql_result($result, 0, "username"); $email = mysql_result($result, 0, "email"); $randompwd = RandomPwd(); $temp = sha1($randompwd); $headers = GetHeaders(); mail($email, "Blah blah blah. Your newusername is: {$user}, and your new password is: {$randompwd}. ", $headers); if(QuickQuery("UPDATE {$userdbtable} SET password='{$temp}' WHERE email='{$email}'")) return 1; } function RandomPwd() { $length = 10; $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; $string = ""; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; } return $string; } ?> [b]Here is the info on index.php for login and registration[/b] [b]Login:[/b] <?php if($_GET['logout'] == 'logout') { session_destroy(); Redirect("index.php"); } if($_POST['submitted'] == "login") { // echo ValidateUser("Jimmy", "password"); //CreateAccount($name, $password, $email, $type); if(ValidateUser($_POST['username'], $_POST['password']) == 1) { $_SESSION['user'] = new cUser; $_SESSION['user']->username = $_POST['username']; $_SESSION['user']->usertype = GetUserType($_POST['username']); $_SESSION['user']->userid = GetUserID($_POST['username']); Redirect("index.php"); } // CreateAccount("test", "test", "[email]me@website.com[/email]", "user"); } ?> [b]Registration[/b] <?php if($_POST['submitted'] == "register") { $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $username = $_POST['username']; $email = $_POST['email']; $password = $_POST['password']; $confirmpwd = $_POST['confirmpwd']; if(!$firstname) $error = "Invalid First Name"; else if(!$lastname) $error = "Invalid Last Name"; else if(!$username) $error = "Invalid User Name"; else if(!$email) $error = "Invalid Email"; else if(!$password) $error = "Invalid Password"; } ?> <?php if($_POST['submitted'] && !$error) { $result = QuickQuery("SELECT username FROM users WHERE username='{$username}'"); if(mysql_numrows($result) > 0) $error = "Be More Creative. Someone Already is Using That Username."; else { $result = QuickQuery("SELECT email FROM users WHERE email='{$email}'"); if(mysql_numrows($result) > 0) $error = "Email Already Being Used. Maybe you already registered."; else if($confirmpwd != $password) $error = "Matching passwords means the second password must be exactly like this first."; else { CreateAccount($firstname, $lastname, $username, $password, $email, "user"); } } } ?> [b]Both forms are here[/b] <div class="btn-show"> <p>Login</p> </div> <div class="pushup-form"> <div class="btn-close"> Close </div> <div class="clear"> </div> <form action="index.php" method="post"> <p style="font-size:14px">Login</p> <p>Username:<input type="text" name="username" style="font-size:12px;"/></p> <p>Password:<input type="password" name="password" style="font-size:12px;"/></p> <p><input class="login" type="submit" name="submitted" value="login" /></p> <p><a href="pwd.php?pwd=lostpwd" style="font-size:10px">Forgot Username or Password?</a></p> </form> <div class="panel"> <form action="index.php" method="post"> <p>First Name:<input type="text" name="firstname" value="<?php echo $firstname;?>" /></p> <p>Last Name:<input type="text" name="lastname" value="<?php echo $lastname;?>" /></p> <p>Username:<input type="text" name="username" value="<?php echo $username;?>" /></p> <p>Email:<input type="text" name="email" class="clear" value="<?php echo $email;?>" /></p> <p>Password:<input type="password" name="password" value="<?php echo $password;?>" /></p> <p>Confirm Password:<input type="password" name="confirmpwd" value="<?php echo $confirmpwd;?>" /></p> <p class="clear"> <p><input class="register" type="submit" name="submitted" value="register"/></p> </p> </form> </div> <p style="text-align:center;" class="flip">Need to Register?</p> </div> [code] These forms open from the right side of my website by clicking "Register." The top of the form has an option for login and by clicking "Need to Register?" The rest of the form expands. Any ideas? My database is set up correctly. MOD EDIT: code tags added. Hi there, If a form was submitted without any proper method , how can we grab that particular information on the other side ? For example : index.php Code: [Select] <form action="process.php" method=""> Userame: <input type="text" name="userName" /> Password: <input type="password" name="pass" /> <input type="submit" name="submit" value="submit" </form> process.php $userName = $_REQUEST['userName']; $password = $_REQUEST['pass']; echo ("Welcome " . $username . " to our page."); Now what if a user deliberately alters the method, and uses "$_POST or $_GET or Leaves it blank. How can I can make it fool proof on the server side without using the $_REQUEST Global Variable? Is there any other way to grab that submitted information like in $_SERVER Global Variable ? *For those who think the form will not submit without disclosing the method, then they must try this after disabling their Java-script. I hope you understand my question and would reply me in as detail as possible. Thanks Hello, I have a problem with my login form, when i press the submit button, it returns a valitation error that I made. The error message is triggered when the submit button isn't pressed, but the form still tries to submit. session_start(); include "sources/php/class.php"; $e = $_POST['loginname']; $p = $_POST['loginpass']; $s = $_POST['submit']; if(!isset($s)) { header('location: '.$_SESSION['psite'].'.php?p=error&ploca=login&pid=0'); exit(); } Heres a piece of my code, first i define the variables, then check if the button was pressed, but something is wrong there? - But what? Hope you can help me. Thanks in advance. 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> Kindly help. Am a new php programmer and am learning how to HTML form data to a php script. Have tried several times but information on html form never get submitted. For some unknown reasons, the codes are failing . Here are my codes:
<html>
and
<html>
<body> Hi,
i have a contact form with this code:
<?php if(isset($_POST['submit'])) { $flag=1; if($_POST['yourname']=='') { $flag=0; echo "Please Enter Your Name<br>"; } else if(!preg_match('/[a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*/',$_POST['yourname'])) { $flag=0; echo "Please Enter Valid Name<br>"; } if($_POST['email']=='') { $flag=0; echo "Please Enter E-mail<br>"; } else if(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $_POST['email'])) { $flag=0; echo "Please Enter Valid E-Mail<br>"; } if($_POST['subject']=='') { $flag=0; echo "Please Enter Subject<br>"; } if($_POST['message']=='') { $flag=0; echo "Please Enter Message"; } if ( empty($_POST) ) { print 'Sorry, your nonce did not verify.'; exit; } else { if($flag==1) { wp_mail(get_option("admin_email"),trim($_POST[yourname])." sent you a message from StraightForwardLegal.com".get_option("blogname"),stripslashes(trim($_POST['message'])),"From: ".trim($_POST['yourname'])." <".trim($_POST['email']).">\r\nReply-To:".trim($_POST['email'])); echo "Thank you for contacting us!<br> We have received your email. <br> One of our Workers' Compensation Attorneys <br> will be in touch with you as soon as possible"; header ("location: http://www.straightforwardlegal.com"); exit; } } } ?>and then, <div class="frontForm"> <form method="post" id="contactus_form"><span style="font-size: 12px;> <div class="left"> Name*:<br><input type="text" name="yourname" id="yourname" rows="1" maxlength="35"><br> Email*:<br><input type="text" name="email" id="email" rows="1" value=""><br> Phone*:<br><input type="text" name="subject" id="subject" rows="1" columns="8" style= "max-height: 18px; min-height: 18px;" value="" /></td></tr> </div> <div class="right" style="margin-top: -120px;"/> Message*:<textarea name="message" id="message" rows="5" style="height: 90px;"></textarea><br><br> <input type="submit" name="submit" id="submit" value="Send"/></span> </form> </div> </div> </div> </div>I used header ("location: http://www.straightforwardlegal.com"); exit;but, it does not work. After submitting my contact form, the user gets taken to my contact page instead of going to my home page? I was wondering if someone could let me know what I have done wrong? Thank you, Megan Good day i am not receiving emails when hitting submit; not sure if my code is correct. jtconfirmation.co.za <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Names Confirmation RSVP</title> <link rel="stylesheet" href="church.css"> </head> <body> <form action="/mail_form.php" method="POST" id="church-form"> <div class="top"> <nav> <a href="index.html" class="mybutton">Home</a> </nav> </div> <div class="form"> <div class="info"> <h1>RSVP</h1> <h2>for the Confirmation Service of</h2> <h1>Name</h1> <p class="line">________________________________________</p> <h2>The Details</h2> <p>Sunday, 28 February 2021</p> <p>10:00 AM</p> <p>Please RSVP by 15 February 2021</p> <h2>Confirmation Service</h2> <p><a href="#" target="_blank"> Calvyn Protestant Church Diep River</a></p> <p>10 Keswick St, Elfindale</p> <p class="line">________________________________________</p> <input type="text" value="name" placeholder="Name"> <input type="email" value="email" placeholder="Email"> </div> <?php echo((!empty($errorMessage)) ? $errorMessage : '') ?> <button type="submit" class="accept" value="Send">Accept</button> <button type="submit" class="regret" value="Send">Regret</button> </div> </form> <script src="//cdnjs.cloudflare.com/ajax/libs/validate.js/0.13.1/validate.min.js"></script> <script> const constraints = { name: { presence: {allowEmpty: false} }, email: { presence: {allowEmpty: false}, email: true } }; const form = document.getElementById('church-form'); form.addEventListener('submit', function (event) { const formValues = { name: form.elements.name.value, email: form.elements.email.value }; const errors = validate(formValues, constraints); if (errors) { event.preventDefault(); const errorMessage = Object .values(errors) .map(function (fieldValues) { return fieldValues.join(', ') }) .join("\n"); alert(errorMessage); } }, false); </script> </body> </html> s <?php use PHPMailer\PHPMailer\PHPMailer; require __DIR__ . '/vendor/autoload.php'; $errors = []; $errorMessage = ''; if (!empty($_POST)) { $name = $_POST['name']; $email = $_POST['email']; if (empty($name)) { $errors[] = 'Name is empty'; } if (empty($email)) { $errors[] = 'Email is empty'; } else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors[] = 'Email is invalid'; } if (!empty($errors)) { $allErrors = join('<br/>', $errors); $errorMessage = "<p style='color: red;'>{$allErrors}</p>"; } else { $mail = new PHPMailer(); // specify SMTP credentials $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = 'name@example.com'; $mail->Password = 'P@ssword123'; $mail->SMTPSecure = 'tls'; $mail->Port = 587; $mail->setFrom($email, 'Mailtrap Website'); $mail->addAddress('piotr@mailtrap.io ', 'Me'); $mail->Subject = 'RSVP Church'; // Enable HTML if needed $mail->isHTML(true); $bodyParagraphs = ["Name: {$name}", "Email: {$email}", "Message:", nl2br($message)]; $body = join('<br />', $bodyParagraphs); $mail->Body = $body; echo $body; if($mail->send()){ header('Location: thank-you.html'); // redirect to 'thank you' page } else { $errorMessage = 'Oops, something went wrong. Mailer Error: ' . $mail->ErrorInfo; } } } ?>
Hi, I have a dynamic form which uses javascript to add rows on the fly. The name of the element on my test page is txtRow1, txtRow2, etc; the number is added when I add a new row. I am trying to figure out how I will extract the data once the form had been POSTED. I have tried Code: [Select] $tags = $_POST['txtRow']; foreach ($tags as $t) { echo "$t<br />"; } but that shows nothing. I would be grateful for any assistance. Thanks |