PHP - I Keep Getting An Unexpected T Else Error With My Register Script
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"; } ?> Similar TutorialsHi, 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 :) Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\mywork\unique.php on line 15 <html> <head> <title> </title> </head> <body bgproperties="fixed"> <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $con = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'mywork'; mysql_select_db($dbname, $con); $sql=mysql_query(insert into users (regno,name,gender,date,month,year,emailid,cell,paddress,caddress,incometype,incomeamt,dad,fyes,dadocup,mom,myes,momocup,password) VALUES ('$_POST[regno]','$_POST[name]','$_POST[gender]','$_POST[date]','$_POST[month]','$_POST[year]','$_POST[emailid]','$_POST[cell]','$_POST[paddress]','$_POST[caddress]','$_POST[incometype]','$_POST[incomeamt]','$_POST[dad]','$_POST[fyes]','$_POST[dadocup]','$_POST[mom]','$_POST[myes]','$_POST[momocup]','$_POST[password]')"); $sql1=mysql_fetch_array($sql); $result = @mysql_query($SQl1); $result="SELECT * FROM users WHERE regno='$regno'"; while($row = mysql_fetch_array($result)) { //echo $row['regno']."regno<br>"; //echo $row['name']."name<br>"; //echo $row['gender']."gender<br>"; //echo $row['date']."date<br>"; //echo $row['month']."month<br>"; //echo $row['year']."year<br>"; //echo $row['emailid']."emailid<br>"; //echo $row['cell']."cell<br>"; //echo $row['paddress']."paddress<br>"; //echo $row['caddress']."caddress<br>"; //echo $row['incometype']."incometype<br>"; //echo $row['incomeamt']."incomeamt<br>"; //echo $row['dad']."dad<br>"; //echo $row['fyes']."fyes<br>"; //echo $row['dadocup']."dadocup<br>"; //echo $row['mom']."mom<br>"; //echo $row['myes']."myes<br>"; //echo $row['momocup']."momocup<br>"; //echo $row['password']."password<br>"; } echo "Thanks for Register!"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con); ?> <form name="security" action="index.php" method="post"> <input type="submit" value="click here to login"> </form> </body> </html> Hey, so this is my register script
<?php error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', 1); require 'connect.php'; echo "<title> Register </title>"; if(isset($_POST['register'])) { $username = trim($_POST['username']); $username = mysqli_real_escape_string($con, $_POST['username']); $password = mysqli_real_escape_string($con, $_POST['password']); $password = hash('sha512', $_POST['password']); if(!$_POST['username'] OR !$_POST['password']) { die("You must enter a username and password!"); } $stmt = $con->prepare("INSERT INTO usrs_usr (username, password) VALUES (?, ?)"); $stmt->bind_param("ss", $username, $password); $stmt->get_result(); var_dump($stmt); $stmt->execute(); echo "New user has been created successfully"; $stmt->close(); $conn->close(); } ?>Now the problem is i have done a variable dump which outputs nothing, and the only error i am getting is Fatal error: Call to a member function bind_param() on a non-object 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 Hey I would just like to release a simple login/register script that will work just fine and has some nice systems in it. The Login. (I will post the code then below tell you what you need to do to get it to work with MYSQL DATABASE) Create a file and call it login with the suffix .php so if you have file extensions showing on your computer it will look like "login.php" then put this code inside of it. Code: [Select] <?php session_start(); ?> <?php function mysql_prep($value) { $magic_quotes_active = get_magic_quotes_gpc(); $new_enough_php = function_exists("mysql_real_escape_string"); // i.e PHP >= v4.3.0 if($new_enough_php){ // PHP v4.3.0 or higher if ($magic_quotes_active){ $value = stripslashes($value); } $value = mysql_real_escape_string($value); }else{ //Before PHP v4.3.0 //if magic quotes aren't already on then add slahes manually if(!$magic_quotes_active){ $value = addslashes($value); } // if magic quotes are active then the slashes already exist } return $value; } function redirect_to($location = NULL){ if($location != NULL){ header("Location: {$location}"); exit; } } define("DB_SERVER","localhost"); define("DB_USER","root"); define("DB_PASS","yourpassword"); define("DB_NAME","yourdatabasename"); $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS); if(!$connection){ die("Database Connection Failed: " . mysql_error()); } $db_select = mysql_select_db("bcooperz", $connection); if(!$db_select){ die("Connection to database failed: " . mysql_error()); } ?> <?php if(isset($_SESSION['user_id'])){ redirect_to("staff.php"); } ?> <?php if (isset($_POST['submit'])){ $errors = array(); // Perform validations on the form $required_fields = array('username', 'password'); foreach($required_fields as $fieldname){ if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname])){ $errors[] = $fieldname; } } $field_with_lengths = array('username' => 30, 'password' => 30); foreach($field_with_lengths as $fieldname => $maxlength) { if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $errors[] = $fieldname; } } $username = trim(mysql_prep($_POST['username'])); $password = trim(mysql_prep($_POST['password'])); $hashed_password = sha1($password); if (empty($errors)){ // Checks database to see if username and password exist their $query = "SELECT id, username FROM users WHERE username='$username' AND hashed_password='$hashed_password' LIMIT 1"; $result_set = mysql_query($query, $connection); if(!$result_set){ die("Database Query Failed: " . mysql_error()); } if (mysql_num_rows($result_set) == 1) { // The Username and Password have been found in the database and the user is verified // Only 1 Match $found_user = mysql_fetch_array($result_set); $_SESSION['user_id'] = $found_user['id']; $_SESSION['username'] = $found_user['username']; redirect_to("staff.php"); }else{ // Username and Password was not found in the database. $message = "Username/Password Combination Incorrect.<br/>Please make sure your caps lock key is off and try again."; echo $message; } }else{ $count = count($errors); if($count == 1){ echo "Their Was {$count} Error In The Form" . "<br />"; print_r(implode(", ", $errors)); }else{ echo "Their Was {$count} Error's In The Form" . "<br />"; echo "<b>"; print_r(implode(", ", $errors)); echo "</b>"; } } }else{ // The Form Has Not Been Submitted if(isset($_GET['logout']) && $_GET['logout'] == 1){ echo "You Are Now Logged Out"; } if(isset($_GET['nowlogged']) && $_GET['nowlogged'] == 1){ echo "You Need to Login to reach this page."; } $username = ""; $password = ""; } ?> <html> <head> <title>Register</title> </head> <body> <form action="login.php" method="post"> Username : <input type="text" name="username" maxlength="30" value="<?php echo htmlentities($username); ?>" /><br /> Password : <input type="password" name="password" maxlength="30" value="<?php echo htmlentities($password); ?>" /><br /><br /> <input type="submit" name="submit" value="Login" /><br /> </form> <p>Haven't got an account? register <a href="register.php">here!</a></p> </body> </html> Now once you have a file called "login.php" with the above code inside of it you will need to goto your mysql database and create a database with a table that has 3 fields in the following format. - id - int(11) - Auto increment - username - varchar(50) - hashed_password - varchar(40) Now search for this in the login.php code Code: [Select] define("DB_SERVER","localhost"); define("DB_USER","root"); define("DB_PASS","yourpassword"); define("DB_NAME","yourdatabasename"); And This: Code: [Select] $db_select = mysql_select_db("bcooperz", $connection); And change these to your settings. Once you have done all this create a new file called register with the suffix .php as well so if you have file extensions turned on it will look like "register.php" And add this code inside it: Code: [Select] <?php function mysql_prep($value) { $magic_quotes_active = get_magic_quotes_gpc(); $new_enough_php = function_exists("mysql_real_escape_string"); // i.e PHP >= v4.3.0 if($new_enough_php){ // PHP v4.3.0 or higher if ($magic_quotes_active){ $value = stripslashes($value); } $value = mysql_real_escape_string($value); }else{ //Before PHP v4.3.0 //if magic quotes aren't already on then add slahes manually if(!$magic_quotes_active){ $value = addslashes($value); } // if magic quotes are active then the slashes already exist } return $value; } function redirect_to($location = NULL){ if($location != NULL){ header("Location: {$location}"); exit; } } ?> <?php define("DB_SERVER","localhost"); define("DB_USER","root"); define("DB_PASS","maxcooper"); define("DB_NAME","bcooperz"); $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS); if(!$connection){ die("Database Connection Failed: " . mysql_error()); } $db_select = mysql_select_db("bcooperz", $connection); if(!$db_select){ die("Connection to database failed: " . mysql_error()); } ?> <?php if(isset($_POST['submit'])){ $username = trim(mysql_prep($_POST['username'])); $password = trim(mysql_prep($_POST['password'])); $hashed_password = sha1($password); $confirmpass=$_POST['confirmpass']; $query2 = "SELECT * FROM users WHERE username='$username'"; $result2 = mysql_query($query2); $counted=mysql_num_rows($result2); $errors = array(); // Perform validations on the form $required_fields = array('username', 'password', 'confirmpass'); foreach($required_fields as $fieldname){ if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname])){ $errors[] = $fieldname; } } if($confirmpass!=$_POST['password']){ $errors[] = "passdifference"; } if($counted > 0){ $errors[] = "User Already Created"; } $field_with_lengths = array('username' => 30, 'password' => 30); foreach($field_with_lengths as $fieldname => $maxlength) { if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $errors[] = $fieldname; } } /* The Form Has Been Submitted */ if (empty($errors)){ $query = "INSERT INTO users (username,hashed_password) VALUES ('{$username}', '{$hashed_password}')"; $result = mysql_query($query, $connection); if($result){ echo "User Successfully Created"; }else{ echo "The User Could Not Be Created" . "<br />"; echo mysql_error(); } }else{ $count = count($errors); if($count == 1){ echo "Their Was {$count} Error In The Form" . "<br />"; print_r(implode(", ", $errors)); }else{ echo "Their Was {$count} Error's In The Form" . "<br />"; echo "<b>"; print_r(implode(", ", $errors)); echo "</b>"; } } }else{ /* The Form Has Not Yet Been Submitted */ $username = ""; $password = ""; } ?> <html> <head> <title>Register</title> </head> <body> <form action="register.php" method="post"> Username : <input type="text" name="username" maxlength="30" value="<?php echo htmlentities($username); ?>" /><br /> Password : <input type="password" name="password" maxlength="30" value="<?php echo htmlentities($password); ?>" /><br /> Confirm Password: <input type="password" name="confirmpass" maxlength="30" value="" /><br /><br /> <input type="submit" name="submit" value="Register" /><br /> </form> <p>Already have a account? login here <a href="login.php">here!</a></p> </body> </html> Once you have done that and you have a file called "register.php" you will need to perform the final step which will be changing the database details once again on the second file ("register.php"). Thanks, Bcooperz. Please tell me if this works Code: [Select] <?php mysql_connect ("-","-","-") or die ('Error'); mysql_select_db ("-"); $out = mysql_query("SELECT * FROM guestbook ORDER BY id DESC"); while($row = mysql_fetch_assoc($out); --and this one if that braces is deleted { ----this is where im getting the error $name = $row['name']; $email = $row['email']; $txt = $row['comment']; $msg = "Are you sure you want to delete"; /* @var $_REQUEST <type> */ if (isset($_REQUEST ["action"]) && $_REQUEST["action"] == "del") { $id = intval($_REQUEST['id']); mysql_query("DELETE FROM guestbook WHERE id=$id;"); echo "<action=index.php>"; } echo "<font face='verdana' size='1'>"; echo "<table border='0'> <tr><td>Name: ".$name."</td></tr>"." <tr><td>Email: ".$email."</td></tr> <tr><td colspan='2'>Comment:</td></tr> <tr><td colspan='2' width='500'><b>".$txt."</b></td></tr> <tr><td><a onclick=\"return confirm('.$msg.');\" href='index.php?action=del&id=".$row['id']."'><span class='red'>["."Delete"."]</span></a> </td></tr> </table><br />"; echo "<hr size='1' width='500' align='left'></font>"; } ?> Kindly help me please. When i delete ({) the error will become the ( i dont know what to do already. Thanks. I just enabled error reporting and I am not that familiar with it. I know I have an error some where around line 33. I know I am missing a bracket or a comma or some other syntax error I just cannot find where the error is. Below is my script. Thanks for any help. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Airline Survey</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="author" content="Revised by abc1234"/> </head> <body> <?php $WaitTime = addslashes($_POST["wait_time"]); $Friendliness = addslashes($_POST["friendliness"]); $Space = addslashes($_POST["space"]); $Comfort = addslashes($_POST["comfort"]); $Cleanliness = addslashes($_POST["cleanliness"]); $Noise = addslashes($_POST["noise"]); if (empty($WaitTime) || empty($Friendliness) || empty($Space) || empty($Comfort) || empty($Cleanliness) || empty($Noise)) echo "<hr /><p>You must enter a value in each field. Click your browser's Back button to return to the form.</p><hr />"; else { $Entry = $WaitTime . "\n"; $Entry .= $Friendliness . "\n"; $Entry .= $Space . "\n"; $Entry .= $Comfort . "\n"; $Entry .= $Cleanliness . "\n"; $Entry .= $Noise . "\n"; $SurveyFile = fopen("survey.txt", "w") } if (flock($SurveyFile, LOCK_EX)) { if (fwrite($SurveyFile, $Entry) > 0) { echo "<p>The entry has been successfully added.</p>"; flock($SurveyFile, LOCK_UN; fclose($SurveyFile); else echo "<p>The entry could not be saved!</p>"; } else echo "<p>The entry could not be saved!</p>"; } ?d> <p><a href="AirlineSurvey.html">Return to Airline Survey</a></p> </body> </html> I have been trying to get my files to upload onto a computer and I receive this message: Parse error: syntax error, unexpected T_STRING in /home/content/19/6550319/html/listing.php on line 27. Line 27 is how the php logs into my SQL. The problem is that I was able to log in before. I just made changes to the form by adding a dropdown menu and price and now it says it doesnt parse. Can anyone figure this out. I will include the code without the login information because the forum is public but I did put the words left out for you to see where I took out the passcodes. Code: [Select] <?php //This is the directory where images will be saved $target = "potofiles/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $price=$_POST['price']; $gig=$_POST['giga']; $yesg=$_POST['yesg']; $pic=($_FILES['photo']['name']); $pic2=($_FILES['phototwo']['name']); $pic3=($_FILES['photothree']['name']); $pic4=($_FILES['photofour']['name']); $description=$_POST['iPadDescription']; $condition=$_POST['condition']; $fname=$_POST['firstName']; $lname=$_POST['lastName']; $email=$_POST['email'] // Connects to your Database mysql_connect ("left out", "left out", "left out") or die(mysql_error()) ; mysql_select_db("left out") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO listing (price,giga,yesg,photo,phototwo,photothree,photofour,iPadDescription,condition,firstName,lastName,email) VALUES ('$price', '$gig', '$yesg', '$pic', '$pic2', '$pic3', '$pic4', '$description', '$condition', '$fname', '$lname', '$email')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } echo date("m/d/y : H:i:s", time()) ?>
Hello everyone,
1 <?php
7 // Create connection
10 // Check connection
14 $firstname = $conn->real_escape_string($_REQUEST['firstname']); 25 $sql2 = "INSERT INTO countries VALUES ('$country')"; 27 $sql3 = "INSERT INTO Contacts (firstname, lastname, address, city, country, phone, email) VALUES ('$firstname', '$lastname', '$address', $city, $country, '$phone_number','$email')";
29 SELECT * FROM cities;
if($conn->query($sql2) === true){
if($conn->query($sql3) === true){ Hi folks, I am a complete n00b at php and mysql. I am teaching myself from books and the WWW, but alas I am stuck... the error I get is: Parse error: syntax error, unexpected T_STRING in X:\xampp\htdocs\search.php on line 7 here is the code: <?php mysql_connect ("localhost", "user", "password") or die (mysql_error()); mysql_select_db ("it_homehelp_test") or die (mysql_error()); $term = $_POST['term']; $sql = $mysql_query(select * from it_homehelp_test where ClientName1 like '%term%'); <<<------this is line 7 while ($row = mysql_fetch_array($sql)){ echo 'Client Name:' .$row['ClientName1']; echo 'Address:' .$row['Address1']; echo 'Phone:' .$row['Tel1']; } ?> Any help you can offer would be great. I can also post the ".html" file that creates the search bar if it is needed. Thanks I don`t get it, waht is wrong?! Code: [Select] <?php require_once 'auth.php'; if (!isset($_SESSION['SESS_VERIFY'])) { header("location: access-denied.php"); exit(); } if ($_SESSION['lang'] == 'Ro') { // setare data romania date_default_timezone_set('Europe/Bucharest'); $today = getdate(); $zi = $today['mday']; $luna = $today['mon']; $lunastring = $today['month']; $an = $today['year']; $data = $zi.$luna.$an; $data = (string)$data; $ora = date('H:i:s'); $msg = array(); $err = array(); $luni = array ( 1=>'Ianuarie', 2=>'Februarie', 3=>'Martie', 4=>'Aprilie', 5=>'Mai', 6=>'Iunie', 7=>'Iulie', 8=>'August', 9=>'Septembrie', 10=>'Octobrie', 11=>'Noiembrie', 12=>'Decembrie'); // comun const SQL_ERR = 'SQL statement failed with error: '; const ADD_MODEL = 'ADAUGA UN MODEL NOU'; . .many constants.. . } elseif ($_SESSION['lang'] == 'It') {... Thank you! Hi all, Does anybody can help me with this error...? I am trying create a simple form which insert data into mysql table called 'sample' Here is my code... Code: [Select] <?php $connection = mysql_connect("localhost","root", "123"); if(!$connection) { die("db connection error" .mysql_error()); } $db_select = mysql_select_db("project", $connection); if(!$db_select) { die("db select error" .mysql_error()); } $sql = "INSERT INTO sample (id,firstname,lastname,bio,gender) VALUES ('$_POST['ID_']','$_POST['firstname']','$_POST['lastname']','$_POST['bio']','$_POST['gender']')"; if(!$sql) { die('Error: ' . mysql_error()); } echo "1 record added"; ?> And every time I am getting this annoying error Quote Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\project\process.php on line 19 and Line 19 is Code: [Select] ('$_POST['ID_']','$_POST['firstname']','$_POST['lastname']','$_POST['bio']','$_POST['gender']')"; Thanks in advance..! :-) This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=344105.0 Hey Everyone, I'm getting this error when I submit my contact form. Parse error: syntax error, unexpected $end in /home1/user/public_html/contact/process.php on line 22 I got this code from a video on youtube. http://www.youtube.com/watch?v=rdsz9Ie6h7I If I made a mistake or TYPO please let me know. Thanks! Here's my code: <?php $emailSubject = 'Contact Form Submission'; $sendto = 'info@mydomain.com'; $nameField = $_Post['name']; $emilField = $_Post['email']; $phoneField = $_Post['phone']; $SubjectField = $_Post['subject']; $messageField = $_Post['message']; $body = <<<EOD <br><hl><br>This Form was submitted from the Domain.com contact page.<br> Name: $name<br> E-Mail: $email<br> Phone: $phone<br> Subject: $subject<br> Message: $message<br> BOD; $headers = "FROM: $email\r\n"; $headers .="Content-Type: text/html\r\n"; $success = mail($sendto, $emailSubject, $body, $headers); ?> I just edited the tablerate.php in magento, and now I am getting this error, but I don't know what's wrong. Anybody here can help me?
The error message reads "Parse error: syntax error, unexpected '*', expecting function (T_FUNCTION) in /home/echoshom/public_html/app/code/core/Mage/Shipping/Model/Carrier/Tablerate.php on line 50"
Attached is tablerate.php
Attached Files
Tablerate.php 9.23KB
2 downloads |