PHP - Problems Error With Mysql Setting Up Register Form
Hi guys I am working on adding a third party php members register and login into a clients web site but every time I try the regidter page is shows me this error message.
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'username'@'localhost' (using password: YES) in /home/cpassoc2/public_html/register-exec.php on line 15 Failed to connect to server: Access denied for user 'username'@'localhost' (using password: YES) This is what i have in the config.php page. <?php define('DB_HOST', 'localhost'); define('DB_USER', 'cpassoc2-memark'); define('DB_PASSWORD', '?????????'); password replaced define('DB_DATABASE', 'cpassoc2-me'); ?> I have set up the my SQL within the control panel of the site, So do i need to do any thing else???, what am i missing???. Mark..... Similar TutorialsI am trying to use the new way of validating the entered email in a register form. Code: [Select] /* REGISTER FORM */ // check if submit button has been clicked if (isset($_POST['submit_signup'])) { // process and assign variables after post submit button has been clicked $user_email = strip_tags(trim($_POST['email'])); $user_email = filter_var($user_email, FILTER_VALIDATE_EMAIL); $nickname = strip_tags(trim($_POST['nickname'])); $password = $_POST['password']; $repassword = $_POST['repassword']; $month = $_REQUEST['month']; $day = $_REQUEST['day']; $year = $_REQUEST['year']; $dob = $year . "-" . $month . "-" . $day; $find_us_question = strip_tags(trim($_POST['find_us_question'])); // connect to database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $check_query = "SELECT * FROM user WHERE nickname = '$nickname'"; $check_connect = mysqli_query($dbc, $check_query) or die(mysqli_error($dbc)); $check_count = mysqli_num_rows($check_connect); // Check if the email exists twice $query_get = "SELECT email FROM user WHERE email = '$user_email'"; $query_run = mysqli_query($dbc, $query_get); $num_rows = mysqli_num_rows($query_run); // check if username is already taken if ($check_count != 0) { echo "Username already exists!"; } elseif ($num_rows != 0) { echo "This email address is already registered in the database, you can not register it twice."; // check if fields are empty } elseif (empty($user_email) || empty($nickname) || empty($password) || empty($day) || empty($month) || empty($year)) { echo "Please fill out all the fields!"; // check char length of input data } elseif (strlen($nickname) > 30 || strlen($user_email) > 50) { echo "Maximum allowed character length for nickname/firstname/lastname are 30 characters!"; // check password char length } elseif (strlen($password) > 25 || strlen($password) < 6) { echo "Your password must be between 6 and 25 characters!"; // check if passwords match with each other } elseif ($password != $repassword) { echo "Please make sure your passwords are matching!"; } else { // encrypt password $password = sha1($password); I would like to implement now an error message stating something along the lines that the entered email address is not valid, how would I have to do the if statement to check the condition? I'm sorry this code is a mess, this is my attempt at a online youtube tutorial http://www.youtube.com/user/phpacademy#p/c/9CC58D1B2A2D83D6/9/cBJZZlLrXGo The script runs with no parse errors but it does not the following: - present error messages when input is incorrect - enter correct input into the database - retain the user input in the form so the user does not need to re enter the information. I would just use another script but this is the 2nd part of a tutorial that will really help me learn so I need this to work . Any help appreciated. 1. 2. <?php 3. include("design/header.php"); 4. require("connect.php"); 5. 6. //register code 7. 8. 9. if(isset($POST['submit'])) 10. { 11. //grab submitted data 12. $firstname = $_POST['firstname']; 13. $lastname = $_POST['lastname']; 14. $username = $_POST['username']; 15. $password = $_POST['password']; 16. $password_repeat = $_POST['password_repeat']; 17. 18. $dob_year = $_POST['dob_year']; 19. $dob_month = $_POST['dob_month']; 20. $dob_day = $_POST['dob_day']; 21. 22. $gender = $_POST['gender']; 23. 24. if ( 25. $firstname&& 26. $lastname&& 27. $username&& 28. $password&& 29. $password_repeat&& 30. $dob_year&& 31. $dob_month&& 32. $dob_day&& 33. $gender 34. ) 35. { 36. 37. //validation 38. if(strlen($firstname)>25 || strlen($lastname)>25 || strlen($username)>25) 39. echo "Firstname, lastname and username must be no more than 25 characters."; 40. 41. 42. else 43. { 44. if (strlen($password)>25 || strlen($password)<6) 45. echo "Password must be between 6 and 25 characters."; 46. 47. else 48. { 49. if (is_numberic($dob_year)&&is_numberic($dob_month)&&is_numberic($dob_day)) 50. { 51. 52. if (strlen($dob_year)>4||strlen($dob_year)>2||strlen($dob_year)>2) 53. echo "Date of birth must be 4 characters, month and must be 2."; 54. else 55. { 56. if ($gender=="Male"||$gender=="Female") 57. { 58. //compare pass 59. if ($password==$password_repeat) 60. { 61. //check dob limits for month and day 62. if ($dob_month>12||$dob_day>31) 63. echo "Date of birth month or day is bigger than expected!"; 64. else{ 65. //check for existing user 66. $query =mysql_query("SELECT * FROM users WHERE username='$username'"); 67. if (mysql_num_rows($query)>=1) 68. echo "That username is already taken."; 69. else { 70. //success!! 71. $dob_db = "$dob_year-$dob_month-$dob_day"; 72. $password_db = md5($password); 73. 74. switch ($gender) 75. { 76. case "Male": 77. $gender_db = "M"; 78. break; 79. case "Female": 80. $gender_db = "F"; 81. break; 82. $register = mysql_query("INSERT INTO user VALUES ('','$firstname','$lastname','$username','$password_db','$dob_db','$gender_db')"); 83. echo "success!"; 84. } 85. } 86. } 87. } 88. else 89. {echo "Passwords must match"; 90. } 91. } 92. else 93. echo "Gender must be Male or Female."; 94. } 95. } 96. else 97. echo "Date of birth must be in number form. For example 1993/05/30"; 98. } 99. } 100. }else{ 101. echo "Please enter your details and click Register!"; 102. } 103. } 104. 105. ?> 106. 107. <p> 108. <form action='register.php' method='POST'> 109. 110. <table width='60%'> 111. <tr> 112. <td width='40%' align='right'> 113. <font size='2' face='arial'>Firstname: 114. </td> 115. <td> 116. <input type='text' value='<?php echo $firstname; ?>' name='firstname' maxlength='25'> 117. </td> 118. </tr> 119. <tr> 120. <td width='40%' align='right'> 121. <font size='2' face='arial'>Lastname: 122. </td> 123. <td> 124. <input type='text' value='<?php echo $lastname; ?>' name='lastname' maxlength='25'> 125. </td> 126. </tr> 127. <tr> 128. <td width='40%' align='right'> 129. <font size='2' face='arial'>Username: 130. </td> 131. <td> 132. <input type='text' value='<?php echo $username; ?>' name='username' maxlength='25'> 133. </td> 134. </tr> 135. <tr> 136. <td width='40%' align='right'> 137. <font size='2' face='arial'>Password: 138. </td> 139. <td> 140. <input type='password' name='password' maxlength='25'> 141. </td> 142. </tr> 143. <tr> 144. <td width='40%' align='right'> 145. <font size='2' face='arial'>Repeat Password: 146. </td> 147. <td> 148. <input type='password' name='password_repeat' maxlength='25'> 149. </td> 150. </tr> 151. <tr> 152. <td width='40%' align='right'> 153. <font size='2' face='arial'>Date of birth: 154. </td> 155. <td> 156. <input type='text' name='dob_year' maxlength='4' size='3' value='<?php if ($dob_year) echo $dob_year; else echo "YYYY";?>'> /<input type='text' name='dob_month' maxlength='2' size='1' value='<?php if ($dob_month) echo $dob_month; else echo "MM";?>'> / <input type='text' name='dob_day' maxlength='2' size='1' value='<?php if ($dob_day) echo $dob_day; else echo "DD";?>'> 157. </td> 158. </tr> 159. <tr> 160. <td width='40%' align='right'> 161. <font size='2' face='arial'>Gender: 162. </td> 163. <td> 164. <select name='gender'> 165. <option>Female</option> 166. <option>Male</option> 167. </select> 168. </td> 169. </tr> 170. 171. </table> 172. <div align='right'><input type='submit' name='submit' value='Register'> 173. </form> 174. 175. 176. <?php 177. include("design/footer.php"); 178. 179. ?> 180. Hello, I have a registration page requesting simple information (first name, last name, email and password). When I click my 'register' button I receive the following errors:
Below is most of the code where I experience issues. The lines called out a mysqli_stmt_bind_param($q, 'ssss', $first_name, $last_name, $email, $hashed_passcode); // execute query mysqli_stmt_execute($q); if (mysqli_stmt_affected_rows($q) == 1) { // One record inserted if (empty($errors)) { // If everything's OK. // Register the user in the database... // Hash password current 60 characters but can increase $hashed_passcode = password_hash($password1, PASSWORD_DEFAULT); require ('msqli_connect.php'); // Connect to the db. // Make the query: $query = "INSERT INTO users (userid, first_name, last_name, "; $query .= "email, password, registration_date) "; $query .="VALUES(' ', ?, ?, ?, ?, NOW() )"; $q = mysqli_stmt_init($dbcon); mysqli_stmt_prepare($q, $query); // use prepared statement to ensure that only text is inserted // bind fields to SQL Statement mysqli_stmt_bind_param($q, 'ssss', $first_name, $last_name, $email, $hashed_passcode); // execute query mysqli_stmt_execute($q); if (mysqli_stmt_affected_rows($q) == 1) { // One record inserted header ("location: register-thanks.php"); exit(); } else { // If it did not run OK. // Public message: $errorstring = "<p class='text-center col-sm-8' style='color:red'>"; $errorstring .= "System Error<br />You could not be registered due "; $errorstring .= "to a system error. We apologize for any inconvenience.</p>"; echo "<p class=' text-center col-sm-2' style='color:red'>$errorstring</p>"; // Debugging message below do not use in production //echo '<p>' . mysqli_error($dbcon) . '<br><br>Query: ' . $query . '</p>'; mysqli_close($dbcon); // Close the database connection. // include footer then close program to stop execution echo '<footer class="jumbotron text-center col-sm-12" style="padding-bottom:1px; padding-top:8px;"> include("footer.php"); </footer>'; exit(); } } else { // Report the errors. $errorstring = "Error! <br /> The following error(s) occurred:<br>"; foreach ($errors as $msg) { // Print each error. $errorstring .= " - $msg<br>\n"; } $errorstring .= "Please try again.<br>"; echo "<p class=' text-center col-sm-2' style='color:red'>$errorstring</p>"; }// End of if (empty($errors)) IF. } catch(Exception $e) // We finally handle any problems here { // print "An Exception occurred. Message: " . $e->getMessage(); print "The system is busy please try later"; } catch(Error $e) { //print "An Error occurred. Message: " . $e->getMessage(); print "The system is busy please try again later."; } ?> I have done some searching around to try and figure out the issue; but I can't seem to put my finger on it. This is a new database, and I haven't been able to get test registered as of yet. Any help would be appreciated. Thank you The error is on line 101. Help please. Code: [Select] <?php //begin register script $submit = $_POST['submit']; //form data $username= strip_tags ($_POST['username']); $email= strip_tags($_POST['email']); $pwd= strip_tags($_POST['pwd']); $confirmpwd= strip_tags($_POST['confirmpwd']); $date = date("Y-m-d"); if ($submit) { //check for required form data if($username&&$pwd&&$confirmpwd&&$email) { //encrypt password $pwd = md5($pwd); $confirmpwd =md5($pwd); //check if passwords match if ($pwd==$confirmpwd) { //check length of username if (strlen($username)>25||strlen($username)>25) { echo "length of username is too long"; } else { //check password length if(strlen($pwd)>25||strlen($pwd)<6) { echo"password must be between 6 and 25 characters"; } else { //register the user } else echo "your passwords do not match"; } else echo "please fill in all fields"; } ?> Hi, I have taken the step of writing my site in MySQLi instead of MYSQL as advised. However, I had a script that I got off the internet, the original file works great and registers the user to the database. However the edited version of the script, where I have added more information such as the users address etc, no longer works. I have compared the two files and can't seem to find the problem. When the script is run, it skips all the registration part and jumps to the last error in the script saying 'You Could Not Be Registered Because Of Missing Data.'. All the variables match the column names in the database.
Here is the original working script
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); // some error checking /* if($_POST['reg']){ echo "form submitted"; }else{ echo "form not submitted"; } */ if( isset( $_POST['user'] ) && isset( $_POST['pass'] ) && isset( $_POST['email'] ) ){ // echo $_POST['user']." - ".$_POST['pass']." - ".$_POST['email']; if( strlen( $_POST['user'] ) < 5 ) { include('header.inc'); echo "Username Must Be 5 or More Characters."; include('footer.inc'); } elseif( strlen( $_POST['pass'] ) < 5 ) { include('header.inc'); echo "Password Must Be 5 or More Characters."; include('footer.inc'); } elseif( $_POST['pass'] == $_POST['user'] ) { include('header.inc'); echo "Username And Password Can Not Be The Same."; include('footer.inc'); } elseif( $_POST['email'] == "" ) { //More secure to use a regular expression to check that the user is entering a valid email // versus just checking to see if the field is empty include('header.inc'); echo "Email must be valid."; include('footer.inc'); } else { require( 'database.php' ); $username = mysqli_real_escape_string($con, $_POST['user']); //Remove md5() function if not using encryption i.e. $password = $_POST['pass']; $password = mysqli_real_escape_string($con, md5( $_POST['pass'])); $email = mysqli_real_escape_string($con, $_POST['email'] ); $sqlCheckForDuplicate = "SELECT username FROM user WHERE username = '". $username ."'"; //echo "$sqlCheckForDuplicate<br/>"; $result = mysqli_query($con, $sqlCheckForDuplicate); if(mysqli_num_rows($result) == 0){ //echo "No Duplicates<br/>"; $sqlRegUser = "INSERT INTO user( username, password, email ) VALUES ( '". $username ."', '". $password ."', '". $email."' )"; //echo "$sqlRegUser<br/>"; if( !mysqli_query($con, $sqlRegUser ) ) { include('header.inc'); echo "You Could Not Register Because Of An Unexpected Error."; include('footer.inc'); } else { /* Note: When using the header function, you cannot send output to the browser * before the header function is called. IF you want to echo a message to the * user before going back to your login page then you should use the HTML * Meta Refresh tag. */ //echo "You Are Registered And Can Now Login"; //echo " $username"; //this is for error checking header ('location: login.php'); // if using echo then use meta refresh /* *?> *<meta http-equiv="refresh" content="2;url= login.php/"> *<? */ } mysqli_free_result($result); } else { include('header.inc'); echo "The Username You Have Chosen Is Already Being Used By Another User. Please Try Another One."; //echo " $username;" //this is for error checking include('footer.inc'); } /* close connection */ mysqli_close($con); } } else { include('header.inc'); echo "You Could Not Be Registered Because Of Missing Data."; include('footer.inc'); } ?>and here is my version <?php error_reporting(E_ALL); ini_set('display_errors', '1'); if( isset( $_POST['user'] ) && isset( $_POST['pass'] ) && isset( $_POST['pass_again'] ) && isset( $_POST['firstname'] ) && isset( $_POST['lastname'] ) && isset( $_POST['email'] ) && isset( $_POST['email_again'] ) && isset( $_POST['address1'] ) && isset( $_POST['address2'] ) && isset( $_POST['town'] ) && isset( $_POST['county'] ) && isset( $_POST['postcode'] ) && isset( $_POST['business'] ) && isset( $_POST['vat_registered'] ) && isset( $_POST['vat_number'] )) { if( strlen( $_POST['user'] ) < 5 ) { include('includes/overall/header.php'); echo "Username Must Be 5 or More Characters."; include('includes/overall/footer.php'); } elseif( strlen( $_POST['pass'] ) < 5 ) { include('includes/overall/header.php'); echo "Password Must Be 5 or More Characters."; include('includes/overall/footer.php'); } elseif( $_POST['pass'] == $_POST['user'] ) { include('includes/overall/header.php'); echo "Username And Password Can Not Be The Same."; include('includes/overall/footer.php'); } elseif( $_POST['pass_again'] == "" ) { include('includes/overall/header.php'); echo "Passwords must match"; include('includes/overall/footer.php'); } // CREATE BETTER EMAIL CHECK elseif( $_POST['email'] == "" ) { include('includes/overall/header.php'); echo "Email must be valid."; include('includes/overall/footer.php'); } elseif( $_POST['email_again'] == "" ) { include('includes/overall/header.php'); echo "Emails must match."; include('includes/overall/footer.php'); } elseif( $_POST['address_1'] == "" ) { include('includes/overall/header.php'); echo "Address cannot be empty"; include('includes/overall/footer.php'); } elseif( $_POST['address_2'] == "" ) { include('includes/overall/header.php'); echo "Address cannot be empty"; include('includes/overall/footer.php'); } elseif( $_POST['town'] == "" ) { include('includes/overall/header.php'); echo "Town cannot be empty"; include('includes/overall/footer.php'); } elseif( $_POST['county'] == "" ) { include('includes/overall/header.php'); echo "County cannot be empty"; include('includes/overall/footer.php'); } elseif( $_POST['postcode'] == "" ) { include('includes/overall/header.php'); echo "Postcode cannot be empty"; include('includes/overall/footer.php'); } elseif( $_POST['business'] == "" ) { include('includes/overall/header.php'); echo "Business cannot be empty"; include('includes/overall/footer.php'); } elseif( $_POST['vat_registered'] == "" ) { include('includes/overall/header.php'); echo "VAT Registered cannot be empty"; include('includes/overall/footer.php'); } elseif( $_POST['vat_number'] == "" ) { include('includes/overall/header.php'); echo "VAT number cannot be empty, please enter N/A if not VAT registered."; include('includes/overall/footer.php'); } else { require( 'database.php' ); $username = mysqli_real_escape_string($con, $_POST['user']); //Remove md5() function if not using encryption i.e. $password = $_POST['pass']; $password = mysqli_real_escape_string($con, md5( $_POST['pass'])); $password_again = mysqli_real_escape_string($con, md5( $_POST['pass_again'])); $firstname = mysqli_real_escape_string($con, $_POST['firstname']); $lastname = mysqli_real_escape_string($con, $_POST['lastname']); $email = mysqli_real_escape_string($con, $_POST['email'] ); $email_again = mysqli_real_escape_string($con, $_POST['email_again']); $address_1 = mysqli_real_escape_string($con, $_POST['address_1']); $address_2 = mysqli_real_escape_string($con, $_POST['address_2']); $town = mysqli_real_escape_string($con, $_POST['town']); $county = mysqli_real_escape_string($con, $_POST['county']); $postcode = mysqli_real_escape_string($con, $_POST['postcode']); $business = mysqli_real_escape_string($con, $_POST['business']); $vat_registered = mysqli_real_escape_string($con, $_POST['vat_registered']); $vat_number = mysqli_real_escape_string($con, $_POST['vat_number']); $sqlCheckForDuplicate = "SELECT username FROM user WHERE username = '". $username ."'"; //echo "$sqlCheckForDuplicate<br/>"; $result = mysqli_query($con, $sqlCheckForDuplicate); if(mysqli_num_rows($result) == 0){ //echo "No Duplicates<br/>"; $sqlRegUser = "INSERT INTO user( username, password, password_again, firstname, lastname, email, email_again, address_1, address_2, town, county, postcode, business, vat_registered, vat_number ) VALUES ( '". $username ."', '". $password ."', '". $password_again ."', '". $firstname ."', '". $lastname ."', '". $email ."', '". $email_again ."', '". $address_1 ."', '". $address_2 ."', '". $town ."', '". $county ."', '". $postcode ."', '". $business ."', '". $vat_registered ."', '". $vat_number."' )"; //echo "$sqlRegUser<br/>"; if( !mysqli_query($con, $sqlRegUser ) ) { include('includes/overall/header.php'); echo "You Could Not Register Because Of An Unexpected Error."; include('includes/overall/footer.php'); } else { header ('location: login.php'); } mysqli_free_result($result); } else { include('includes/overall/header.php'); echo "The Username You Have Chosen Is Already Being Used By Another User. Please Try Another One."; //echo " $username;" //this is for error checking include('includes/overall/footer.php'); } /* close connection */ mysqli_close($con); } } else { include('includes/overall/header.php'); echo "You Could Not Be Registered Because Of Missing Data."; include('includes/overall/footer.php'); } ?> Error reporting is switched on, I just cant see the problem. Any help is much appreciated :) Deprecated: Function session_register() is deprecated in /home/james/public_html/funshizzle.com/install/session.php on line 0 That is my error, I have no idea, What is it? Sorry for many posts, trying to make my website
When I press the register button on my website it will just act as if the page is refreshing and not send any information to mysql
I believe I have connected everything up correctly, can anyone tell my what I have done wrong please?
If you want to check out the website to see what is going on check out www.jokestary.comli.com
<?php //This function will display the registration form function register_form(){ $date = date('D, M, Y'); echo "<form action='?act=register' method='post'>" ."Username: <input type='text' name='username' size='30'><br>" ."Password: <input type='password' name='password' size='30'><br>" ."Confirm your password: <input type='password' name='password_conf' size='30'><br>" ."Email: <input type='text' name='email' size='30'><br>" ."<input type='hidden' name='date' value='$date'>" ."<input type='submit' value='Register'>" ."</form>"; } //This function will register users data function register(){ //Connecting to database include('connect.php'); if(!$connect){ die(mysql_error()); } //Selecting database $select_db = mysql_select_db("database", $connect); if(!$select_db){ die(mysql_error()); } //Collecting info $username = $_REQUEST['username']; $password = $_REQUEST['password']; $pass_conf = $_REQUEST['password_conf']; $email = $_REQUEST['email']; $date = $_REQUEST['date']; //Here we will check do we have all inputs filled if(empty($username)){ die("Please enter your username!<br>"); } if(empty($password)){ die("Please enter your password!<br>"); } if(empty($pass_conf)){ die("Please confirm your password!<br>"); } if(empty($email)){ die("Please enter your email!"); } //Let's check if this username is already in use $user_check = mysql_query("SELECT username FROM users WHERE username='$username'"); $do_user_check = mysql_num_rows($user_check); //Now if email is already in use $email_check = mysql_query("SELECT email FROM users WHERE email='$email'"); $do_email_check = mysql_num_rows($email_check); //Now display errors if($do_user_check > 0){ die("Username is already in use!<br>"); } if($do_email_check > 0){ die("Email is already in use!"); } //Now let's check does passwords match if($password != $pass_conf){ die("Passwords don't match!"); } //If everything is okay let's register this user $insert = mysql_query("INSERT INTO users (username, password, email) VALUES ('$username', '$password', '$email')"); if(!$insert){ die("There's little problem: ".mysql_error()); } echo $username.", you are now registered. Thank you!<br><a href=login.php>Login</a> | <a href=index.php>Index</a>"; } switch($act){ default; register_form(); break; case "register"; register(); break; } ?>Here is the connect.php code <?php $hostname="mysql6.000webhost.com"; //local server name default localhost $username="a5347792_users"; //mysql username default is root. $password=""; //blank if no password is set for mysql. $database="a5347792_users"; //database name which you created $con=mysql_connect($hostname,$username,$password); if(! $con) { die('Connection Failed'.mysql_error()); } mysql_select_db($database,$con); ?> Hello,
i got a problem with a part of my code :
<?php ok, so I have this code for my event registration page......I need to make this event register button dissapear after the date has passed.......can I do this using dd/mm/yyyy or do i need yyyy-mm-dd? here is the codeif ($reg_end == date("F",strtotime("+1 month"))){ echo "<form action='registration.php' method='get'><input type='hidden' name='eventid' value='{$row['eventid']}'><INPUT TYPE='submit' name='submit' VALUE='Register'></form>\n";} else{echo "No longer accepting registrations";} also I need to know how to modify the red code to do this........thanks in advance.......btw I will have field call reg_end which is when the turn off date is....... Hi everyone, im working on a e comm site as a project. I have a register.php page, and its supposed to check for the presence of posted data, and if data is not posted show a form block,and if posted data is present insert it into a database. However its not working,i get an unexpected } on line 114, where there is a }else{ . I've only been working with php a few days, but from what i've read the braces seem where they should be,can someone please tell me where the problem is? <script language="JavaScript" type="text/javascript" src="library/checkout.js"></script> <?php //set up a couple of functions function doDB() { global $mysqli; //connect to server and select database; you may need it $mysqli = mysqli_connect("localhost", "root", "", "onlinestore"); } //determine if they need to see the form or not if (!$_POST) { //they need to see the form, so create form block $display_block = " <form name=\"register\" method=\"post\"action=\"index.php?r=1\"\ id=\"register\"> <table width=\"550\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\" class=\"entryTable\"> <tr class=\"entryTableHeader\"> <td colspan=\"2\">Login Details</td> </tr> <tr> <td width=\"150\" class=\"label\">Email</td> <td class=\"content\"><input name\=\"txtEmail\" type=\"text\" class=\"box\" id=\"txtEmail\" size=\"30\" maxlength=\"50\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Password</td> <td class=\"content\"><input name=\"txtPassword\" type=\"password\" class=\"box\" id=\"txtPassword\" size=\"30\" maxlength=\"50\"></td> </tr> </table> <p> </p> <table width=\"550\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\" class=\"entryTable\"> <tr class=\"entryTableHeader\"> <td colspan=\"2\">Shipping Information</td> </tr> <tr> <td width=\"150\" class=\"label\">First Name</td> <td class=\"content\"><input name=\"txtShippingFirstName\" type=\"text\" class=\"box\" id=\"txtShippingFirstName\" size=\"30\" maxlength=\"50\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Last Name</td> <td class=\"content\"><input name=\"txtShippingLastName\" type=\"text\" class=\"box\" id=\"txtShippingLastName\" size=\"30\" maxlength=\"50\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Address1</td> <td class=\"content\"><input name=\"txtShippingAddress1\" type=\"text\" class=\"box\" id=\"txtShippingAddress1\" size=\"50\" maxlength=\"100\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Address2</td> <td class=\"content\"><input name=\"txtShippingAddress2\" type=\"text\" class=\"box\" id=\"txtShippingAddress2\" size=\"50\" maxlength=\"100\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Phone Number</td> <td class=\"content\"><input name=\"txtShippingPhone\" type=\"text\" class=\"box\" id=\"txtShippingPhone\" size=\"30\" maxlength=\"32\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Area</td> <td class=\"content\"><input name=\"txtShippingState\" type=\"text\" class=\"box\" id=\"txtShippingState\" size=\"30\" maxlength=\"32\"></td> </tr> <tr> <td width=\"150\" class=\"label\">City</td> <td class=\"content\"><input name=\"txtShippingCity\" type=\"text\" class=\"box\" id=\"txtShippingCity\" size=\"30\" maxlength=\"32\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Post Code</td> <td class=\"content\"><input name=\"txtShippingPostalCode\" type=\"text\" class=\"box\" id=\"txtShippingPostalCode\" size=\"10\" maxlength=\"10\"></td> </tr> </table> <p> </p> <table width=\"550\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\" class=\"entryTable\"> <tr class=\"entryTableHeader\"> <td width=\"150\">Payment Information</td> <td><input type=\"checkbox\" name=\"chkSame\" id=\"chkSame\" value=\"checkbox\" onClick=\"setPaymentInfo(this.checked);\"> <label for=\"chkSame\" style=\"cursor:pointer\">Same as shipping information</label></td> </tr> <tr> <td width=\"150\" class=\"label\">First Name</td> <td class=\"content\"><input name=\"txtPaymentFirstName\" type=\"text\" class=\"box\" id=\"txtPaymentFirstName\" size=\"30\" maxlength=\"50\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Last Name</td> <td class=\"content\"><input name=\"txtPaymentLastName\" type=\"text\" class=\"box\" id=\"txtPaymentLastName\" size=\"30\" maxlength=\"50\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Address1</td> <td class=\"content\"><input name=\"txtPaymentAddress1\" type=\"text\" class=\"box\" id=\"txtPaymentAddress1\" size=\"50\" maxlength=\"100\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Address2</td> <td class=\"content\"><input name=\"txtPaymentAddress2\" type=\"text\" class=\"box\" id=\"txtPaymentAddress2\" size=\"50\" maxlength=\"100\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Phone Number</td> <td class=\"content\"><input name=\"txtPaymentPhone\" type=\"text\" class=\"box\" id=\"txtPaymentPhone\" size=\"30\" maxlength=\"32\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Area</td> <td class=\"content\"><input name=\"txtPaymentState\" type=\"text\" class=\"box\" id=\"txtPaymentState\" size=\"30\" maxlength=\"32\"></td> </tr> <tr> <td width=\"150\" class=\"label\">City</td> <td class=\"content\"><input name=\"txtPaymentCity\" type=\"text\" class=\"box\" id=\"txtPaymentCity\" size=\"30\" maxlength=\"32\"></td> </tr> <tr> <td width=\"150\" class=\"label\">Post Code</td> <td class=\"content\"><input name=\"txtPaymentPostalCode\" type=\"text\" class=\"box\" id=\"txtPaymentPostalCode\" size=\"10\" maxlength=\"10\"></td> </tr> </table> <p> </p> <p> </p> <p align=\"center\"> <input class=\"box\" name=\"btnStep1\" type=\"submit\" id=\"btnStep1\" value=\"Proceed >>\"> </p> </form>" } else { //connect to database doDB(); //add records $add_sql = "INSERT INTO tbl_customer (email) VALUES('".$_POST["txtEmail"]."')"; $add_sql = "INSERT INTO tbl_customer (password) VALUES('".$_POST["txtPassword"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_first_name) VALUES('".$_POST["txtShippingFirstName"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_last_name) VALUES('".$_POST["txtShippingLastName"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_address1) VALUES('".$_POST["txtShippingAddress1"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_address2) VALUES('".$_POST["txtShippingPhone"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_phone) VALUES('".$_POST["txtShippingState"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_city) VALUES('".$_POST["txtShippingCity"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_state) VALUES('".$_POST["txtShippingState"]."')"; $add_sql = "INSERT INTO tbl_customer (od_shipping_postal_code) VALUES('".$_POST["txtShippingPostalCode"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_first_name) VALUES('".$_POST["txtPaymentFirstName"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_last_name) VALUES('".$_POST["txtPaymentLastName"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_address1) VALUES('".$_POST["txtPaymentAddress1"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_address2) VALUES('".$_POST["txtPaymentPhone"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_phone) VALUES('".$_POST["txtPaymentState"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_city) VALUES('".$_POST["txtPaymentCity"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_state) VALUES('".$_POST["txtPaymentState"]."')"; $add_sql = "INSERT INTO tbl_customer (od_payment_postal_code) VALUES('".$_POST["txtPaymentPostalCode"]."')"; $add_res = mysqli_query($mysqli, $add_sql) or die(mysqli_error($mysqli)); $display_block = "<p>Thanks for signing up!</p>"; } ?> Hello, I'm working on a register script, and basically I would like the user to repeat their password. And I would like PHP to compare the to passwords, and if they both match then it continues, whereas if they don't match it calls an error. Here is what I have so far: Form: Consists of 2 text fields - subpass, and subconfirmpass PHP: $field = "subpass"; if(!$subpass == $subconfirmpass){ $form->setError($field, "* Passwords do not match"); } $field is referring to the text fields in where the user inputs their password $form is keeping track of errors in user submitted forms and the form field values that were entered correctly. I would appreciate your help, Thanks Hello, I've been working on a search script that call on a function to retrieve info from my database. What I'm trying to do next is to echo various errors e.g. No search results to display. At the moment I have three messages I would like to display based on the user input but it is not working when I try to set up a second functions within the same tags. I have got it working by using header:location but it would be much faster and easier to just echo the messages on one page I will post the code below. Code: [Select] <?php require_once('Connections/price_db.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); //this is the function I would like to add function showErrors($error1 = "", $error2 = "", $error3 = ""){ $var = $_GET['search'] ; $error = false; $error1 = ""; $error2 = ""; $error3 = ""; if (strlen ($var) < 3){ $error = true; $error1 = "You Must Enter At Least Three Characters To Search"; } if (strlen ($var) == 0) { $error = true; $error2 = "Please Enter a Search"; } if ($totalRows_Recordset1 == 0){ $error = true; $error3 = "Your Search Returned No Results"; } if ($error){ showErrors($error1,$error2,error3); } //above is where I have come into troubles 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; } }} $colname_Recordset1 = "-1"; if (isset($_GET ['search'])) { $colname_Recordset1 = $_GET['search']; } mysql_select_db($database_price_db, $price_db); $query_Recordset1 = sprintf("SELECT * FROM price_db WHERE tb_name LIKE %s OR tb_desc LIKE %s", GetSQLValueString("%" . $colname_Recordset1 . "%", "text"),GetSQLValueString("%" . $colname_Recordset1 . "%", "text")); $Recordset1 = mysql_query($query_Recordset1, $price_db) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> and this is the html for it Code: [Select] <div class="bold_14"> <?php echo $error1 ?> <?php echo $error2 ?> <?php echo $error3 ?> </div> HI. I am talking about this website. http://www.elfster.com/ Please browse this website. Can any one tell me how database structure / queries will work? (i know PHP / MYSQL) Can any one guide me a little bit. I would really appreciate it, Thanks Waiting for reply. Ok well i have a virtual world, my friendcoded the emulator. In PHP but he's on holiday for 2 weeks. I keep getting Quote PHP Warning: PHP Startup: It is not safe to rely on the system's timezone setti ngs. You are *required* to use the date.timezone setting or the date_default_tim ezone_set() function. In case you used any of those methods and you are still ge tting this warning, you most likely misspelled the timezone identifier. We selec ted 'Europe/London' for '0.0/no DST' instead in Unknown on line 0 PHP Warning: eval(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone _set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ' Europe/London' for '0.0/no DST' instead in C:\inetpub\wwwroot\main\server\chapat iz.php(2) : eval()'d code on line 4 But there are only 4 lines in chapatiz.php and it has nothing to do with it i think Quote <?php eval(file_get_contents('serv_original.ini')); ?> Here's chapatiz.php (Its attached since its big) Quote //config $socketurl = "munizonline.co.uk; $httpurl = "munizonine.co.uk; $rootPath = "c:/inetpub/wwwroot/"; // SQL SETTINGS $host = 'localhost'; $user = 'root'; $dbname = 'chapatiz'; $password = '---'; $sqli = new mysqli("p:". $host, $user, $password, $dbname); // create a persistant sql connexion (keepAlive) $banned_ips = array(); ///// ADD BAN BY IP FROM HTACCESS $filename = $rootPath.".htaccess"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); $contents = utf8_decode($contents); $ex = explode("\n", $contents); $exf = array(); foreach ($ex AS $k => $str) { if(preg_match('`deny from (.*?) \#`', $str, $sortie)) { $return = $sortie[1]; array_push($exf, $return); } } foreach ($exf AS $k => $str) { array_push($banned_ips, $str); } // LOG ALL ACTIONS function dolog($text) { $myFile = "c:/inetpub/wwwroot/main/log/chat.txt"; $fh = fopen($myFile, 'a'); fwrite($fh, $text. "\n"); fclose($fh); } function serve($r) { return file_get_contents('C:/inetpub/wwwroot/main/server/serve/'. $r. '.php'); } function getitems($name) { return file_get_contents('http://munizonline.co.uk/main/items.php?u='. $name); } function haveitem($name, $item) { $c = file_get_contents('http://munizonline.co.uk/main/items.php?u='. $name); $pattern = '/"'. $item .'"/'; $pattern2 = '/"0'. $item .'"/'; if ((preg_match($pattern, $c)) OR (preg_match($pattern2, $c))) { return true; } else { return false; } } function dotag($tag) { $tag = explode('##', $tag); $tags = array(); foreach ($tag AS $k => $v) { list($name, $value) = explode('=', $v); $tags[$name] = $value; } return $tags; } function updatetag($tags, $tochange, $value) { $tags[$tochange] = $value; $new = "##"; foreach ($tags AS $k => $v) { $new .= $k. "=". $v. '##'; } return $new; } ini_set('display_errors', '1'); error_reporting(0); $quete8 = $sqli->query('UPDATE phpbb_users SET online = 0'); function cmd() { return false; } $modee = false; session_start(); $_SESSION['start'] = "yess"; $mainsock = socket_create(AF_INET, SOCK_STREAM, 0); //modifiez la prochaine ligne si besoin $pport = rand(81, 8000); while (!socket_bind($mainsock, $socketurl, $pport)) { $pport = rand(81, 8000); echo "\n port modified to ". $pport. "\n"; } $myFile = $rootPath."main/server/socket.php"; $fh = fopen($myFile, 'w+') or die("can't open file"); fwrite($fh, $socketurl. ":". $pport); fclose($fh); socket_set_nonblock($mainsock); socket_listen($mainsock); $clients=Array(); $compteur=0; $write = NULL; $except = NULL; $lol = NULL; $race = "0"; $flag = "0"; date_default_timezone_set('Europe/London'); $ok_marry = "0"; $ok_pv = "0"; function random($car) { $string = ""; return $string; } function random3($car3) { $string3 = ""; return $string3; } function random2($car2) { $string2 = ""; return $string2; } function random1($car1) { $string1 = ""; return $string1; } echo("Waiting for players!\n"); $file = file_get_contents($rootPath.'main/server/server_while.php'); $lasteval = time(); while(true){ if ($lasteval <= strtotime('-1 minute')) { if (file_exists($rootPath."main/server/server_while.php")) { $file = file_get_contents($rootPath.'main/server/server_while.php'); } $lasteval = time(); echo "\neval again\n\n"; } eval($file); } I have no clue whats wrong it use to work. Hey guys, Currently Im using: $row = mysql_fetch_array($result) or die(mysql_error()); echo $row['user_family']. " - ". $row['user_registered']; $row['user_family'] = $fam; $_SESSION['family'] = $fam; to take data from a mysql table & set it as SESSION family. However, I cant seem to get this to set. The information IS being taken from mysql because its being echo'd earlier up in the code, but its just not passing to the session. Any ideas? Two part question: 1) I have a MySql table called "lang_key", which will store all of the common text for a site, which will allow easy site modifications from the "non tech" admin. Now, I am creating a recordest that will pull the information from the table, and create a basic list of variables in php. For example: I connect to the database, and do a wildcard select. I can figure out how to set a basic php variable like the example below: Code: [Select] $query1 = "SELECT * FROM lang_key"; $result = mysql_query($query1); while($row = mysql_fetch_array($result)) { $template = $row['common_text']; } There are three fields in my lang_key table (unique_id, string_id, and common_text') What I want to do is take it a step further from the example and I want $template to be the value of "common_text" Where string_id = "curr_template" I hope this makes sense? I really just want to create my recordset and then populate the website with the recordset info. Part II Do you recommend that I use a lang_key database, or would it be simpler and more efficient to just create a lang page with static variables, and use the php file write option to update the page? Thanks!!! Hi I'm having a problem getting a query to work. I have a simple form with user input for start and end date with format: 2009-03-19 (todays date): $Startdate = $_POST['date']; This works well when something is entered into the form, and afterwards using my query: SELECT COUNT(*) as total FROM mydb WHERE Date BETWEEN '$Startdate' AND '$EndDate' ........ Problem is if user submits the form without entering anything in the date input fields, which makes sense. I want to check if inputs has been made, and if not set af default date, but can't make it work: if (isset($_POST['date']) && $_POST['date'] !='') { $Startdate = $_POST['date'];} else { $Startdate = '1980-01-01';} How can I set $Startdate to something that can be used in the query as below doesn't work? When I run 'select 1700-price as blah from goldclose as t2 order by dayid desc limit 1' by itself in mysql I get a numerical result: one row, one column. In my php script, the 1700 is actually a variable. so here it is $changequery = sprintf("select $goldprice-price as change from goldclose order by dayid desc limit 1"); $change = mysql_query(changequery); while ($row = mysql_fetch_array($change)) { printf("$row[0]"); } mysql_free_result($changeresult); I get the following error, Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/root/fuzzy/htmlmain4.php on line 99 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in <b>/root/fuzzy/htmlmain4.php on line 103 Not sure why? All i want is to get the result of that select statement into a variable such as $change i wonder if anyone can help with this problem. I have a form where the dates are set (and have to be passed) in the format: &checkin_monthday=1&checkin_year_month=2012-3&checkout_monthday=2&checkout_year_month=2012-3 so my form is like this:<select id="b_checkin_month" name="checkin_year_month" onchange="checkDateOrder('b_availFrm2', 'b_checkin_day', 'b_checkin_month', 'b_checkout_day', 'b_checkout_month');"> <option value="2012-2">February '12</option> <option value="2012-3">March '12</option> <option value="2012-4">April '12</option> <option value="2012-5">May '12</option> <option value="2012-6">June '12</option> <option value="2012-7">July '12</option> <option value="2012-8">August '12</option> <option value="2012-9">September '12</option> <option value="2012-10">October '12</option> <option value="2012-11">November '12</option> <option value="2012-12">December '12</option> <option value="2013-1">January '13</option> </select> and then every month i have to manually delete the top month and add a new month at the end. is there anyway to automate this with php rather than the javascript route which means users with scripting disabled cant use the form. I saw something that suggested you can do a check for current month/year with php and then set code based on the result but understandng what to do was beyond me im afraid. Thanks in advance. |