stanleybb Posted February 25, 2008 Share Posted February 25, 2008 Hi i would jsut like to say im new to php I want to make a registration page for my website, i have a mysql_connect.php link to the database which is phpmyadmin. The problem i am having is that as soon as you type in the info, on the form location on the site and click the button it doesnt save anything to the database. Why is this and what can i do? THats the code <?php $page_title = 'Register'; include ('./includes/header.html'); //check if the form has been submitted. if(isset($_POST['submitted'])) { $errors = array(); // initialize error array. //Check first name if (empty($_POST['first_name'])) { $errors[]= 'You forgot to enter your first name.'; } else { $fn = trim($_POST['first_name']); } //Check last name if (empty($_POST['last_name'])) { $errors[]= 'You forgot to enter your last name.'; } else { $ln = trim($_POST['last_name']); } //Check email address if (empty($_POST['email'])) { $errors[]= 'you forgot to enter email address.'; } else { $e = trim($_POST['email']); } //check the passwords match if(!empty($_POST['password1'])) { if($_POST['password1'] != $_POST['password2']) { $errors[] = 'Your password did not match the confirmed password.'; } else { $p = trim($_POST['password1']); } } else { $errors[] = 'You forgot to enter your password.'; } if(empty($errors)) { // if everythings okay. //register the user in the database. require_once('../mysql_connect.php'); // connect to the db //Make the query $query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW())"; $result = @mysql_query ($query); //run query. if($result) { // if it ran ok //send an email, if desired //print message echo '<h1 id="mainhead">Thank you!</h1> <p>You are now registered.</p><p><br /></p>'; //include the footer and quit the script (to not show the form). include ('.includes/footer.html'); exit(); } else { echo '<h1 id="mainhead">Systems Error</h1> <p class="error">you could not be registered due to a system error</p>'; echo '<p>' . mysql_error(). '<br /><br />Query: ' .$query . '</p>'; include ('./includes/footer.html'); exit(); } mysql_close(); // close the database connection. } else { //Report the errors echo '<h1 id="mainhead">Error!</h1> <p class="error"> The following error(s) occurred:<br/>'; foreach($errors as $msg) { //print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } // End of if (empty($errors)) IF. }// End of the main Submit conditional. ?> <h2>Register</h2> <form action="register.php" method="post"> <p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="15" maxlength="30" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Password: <input type="password" name="password1" size="10" maxlength="20" /></p> <p>Confirm Password: <input type="password" name="password2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="Register" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('.includes/footer.html'); ?> Link to comment https://forums.phpfreaks.com/topic/92908-register/ Share on other sites More sharing options...
redarrow Posted February 25, 2008 Share Posted February 25, 2008 try now see what the database chucks out..... always echo yor querys out to see if there set correctly. $query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW())"; $result = mysql_query ($query)or die(mysql_error()); try include() include("../mysql_connect.php"); // connect to the db Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-475933 Share on other sites More sharing options...
deansatch Posted February 25, 2008 Share Posted February 25, 2008 You do have the file named as register.php? Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-475934 Share on other sites More sharing options...
redarrow Posted February 25, 2008 Share Posted February 25, 2008 set for all in one...... <?php $page_title = 'Register'; include ('./includes/header.html'); //check if the form has been submitted. if(isset($_POST['submitted'])) { $errors = array(); // initialize error array. //Check first name if (empty($_POST['first_name'])) { $errors[]= 'You forgot to enter your first name.'; } else { $fn = trim($_POST['first_name']); } //Check last name if (empty($_POST['last_name'])) { $errors[]= 'You forgot to enter your last name.'; } else { $ln = trim($_POST['last_name']); } //Check email address if (empty($_POST['email'])) { $errors[]= 'you forgot to enter email address.'; } else { $e = trim($_POST['email']); } //check the passwords match if(!empty($_POST['password1'])) { if($_POST['password1'] != $_POST['password2']) { $errors[] = 'Your password did not match the confirmed password.'; } else { $p = trim($_POST['password1']); } } else { $errors[] = 'You forgot to enter your password.'; } if(empty($errors)) { // if everythings okay. //register the user in the database. require_once('../mysql_connect.php'); // connect to the db //Make the query $query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW())"; $result = @mysql_query ($query); //run query. if($result) { // if it ran ok //send an email, if desired //print message echo '<h1 id="mainhead">Thank you!</h1> <p>You are now registered.</p><p> </p>'; //include the footer and quit the script (to not show the form). include ('.includes/footer.html'); exit(); } else { echo '<h1 id="mainhead">Systems Error</h1> <p class="error">you could not be registered due to a system error</p>'; echo '<p>' . mysql_error(). ' Query: ' .$query . '</p>'; include ('./includes/footer.html'); exit(); } mysql_close(); // close the database connection. } else { //Report the errors echo '<h1 id="mainhead">Error!</h1> <p class="error"> The following error(s) occurred: '; foreach($errors as $msg) { //print each error. echo " - $msg \n"; } echo '</p><p>Please try again.</p><p> </p>'; } // End of if (empty($errors)) IF. }// End of the main Submit conditional. ?> <h2>Register</h2> <form action=" " method="post"> <p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="15" maxlength="30" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Password: <input type="password" name="password1" size="10" maxlength="20" /></p> <p>Confirm Password: <input type="password" name="password2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="Register" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('.includes/footer.html'); ?> Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-475941 Share on other sites More sharing options...
stanleybb Posted February 25, 2008 Author Share Posted February 25, 2008 i have tried splitting them up and that didnt work so you want to to change //register the user in the database. require_once to include('../mysql_connect.php'); // connect to the db Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-475954 Share on other sites More sharing options...
stanleybb Posted February 25, 2008 Author Share Posted February 25, 2008 i created the file register.php with this code <?php $page_title = 'Register'; include ('./includes/header.html'); //check if the form has been submitted. if(isset($_POST['submitted'])) { $errors = array(); // initialize error array. //Check first name if (empty($_POST['first_name'])) { $errors[]= 'You forgot to enter your first name.'; } else { $fn = trim($_POST['first_name']); } //Check last name if (empty($_POST['last_name'])) { $errors[]= 'You forgot to enter your last name.'; } else { $ln = trim($_POST['last_name']); } //Check email address if (empty($_POST['email'])) { $errors[]= 'you forgot to enter email address.'; } else { $e = trim($_POST['email']); } //check the passwords match if(!empty($_POST['password1'])) { if($_POST['password1'] != $_POST['password2']) { $errors[] = 'Your password did not match the confirmed password.'; } else { $p = trim($_POST['password1']); } } else { $errors[] = 'You forgot to enter your password.'; } if(empty($errors)) { // if everythings okay. //register the user in the database. require_once('../mysql_connect.php'); // connect to the db //Make the query $query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW())"; $result = @mysql_query ($query); //run query. if($result) { // if it ran ok //send an email, if desired //print message echo '<h1 id="mainhead">Thank you!</h1> <p>You are now registered.</p><p> </p>'; //include the footer and quit the script (to not show the form). include ('.includes/footer.html'); exit(); } else { echo '<h1 id="mainhead">Systems Error</h1> <p class="error">you could not be registered due to a system error</p>'; echo '<p>' . mysql_error(). ' Query: ' .$query . '</p>'; include ('./includes/footer.html'); exit(); } mysql_close(); // close the database connection. } else { //Report the errors echo '<h1 id="mainhead">Error!</h1> <p class="error"> The following error(s) occurred: '; foreach($errors as $msg) { //print each error. echo " - $msg \n"; } echo '</p><p>Please try again.</p><p> </p>'; } // End of if (empty($errors)) IF. }// End of the main Submit conditional. ?> the other is just called tryme.php that has the other in it <h2>Register</h2> <form action="register.php" method="post"> <p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="15" maxlength="30" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Password: <input type="password" name="password1" size="10" maxlength="20" /></p> <p>Confirm Password: <input type="password" name="password2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="Register" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('.includes/footer.html'); ?> Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-475956 Share on other sites More sharing options...
deansatch Posted February 25, 2008 Share Posted February 25, 2008 have you tried adding the error check on your query as suggested by redarrow? I have never come across NOW() in php before. Maybe that isn't recognised. Is this a function that is set in your mysql_connect.php file? Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-475976 Share on other sites More sharing options...
uniflare Posted February 25, 2008 Share Posted February 25, 2008 instead of //Make the query $query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW())"; $result = @mysql_query ($query); //run query. try: //Make the query $query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('$fn', '$ln', '$e', SHA('$p'), ".time().")"; $result = @mysql_query ($query) or die("Query: ".$query."<br>".mysql_error()); //run query. two changes: instead of now() you should use time() to insert a unix timestamp to record dates/times in a db. second i added a type of error catcher. see what it spits out. hope this helps, Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-475982 Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 And while you're at it, remove the @ suppressor. Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-475984 Share on other sites More sharing options...
stanleybb Posted February 25, 2008 Author Share Posted February 25, 2008 i removed the NOW and did that echo'text here' thing and nothing happend if i changed the require(mysql thing) to include it doesnt work either could it be the mysql_connect file? <?php DEFINE ('DB_USER', 'people_co_uk'); DEFINE ('DB_PASSWORD', 'password'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'people_co_uk'); $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die ('Could not connect to MySQL: ' . mysql_error() ); @mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() ); ?> Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-475990 Share on other sites More sharing options...
DarkerAngel Posted February 25, 2008 Share Posted February 25, 2008 $result = @mysql_query ($query) or die("Query: ".$query."<br>".mysql_error()); //run query. If you can find another way to test if the Register is happening... Remove the $result var set, and just run it as shown. mysql_query($query) or die("Query: ".$query."<br>".mysql_error()); //run query. Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-476002 Share on other sites More sharing options...
deansatch Posted February 25, 2008 Share Posted February 25, 2008 remove all the @ operators to use your error checking. Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-476009 Share on other sites More sharing options...
stanleybb Posted February 25, 2008 Author Share Posted February 25, 2008 what program do you use to input php Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-476014 Share on other sites More sharing options...
stanleybb Posted February 25, 2008 Author Share Posted February 25, 2008 just got this Query: INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('hi', 'hi', 'hi', SHA('hi'), 1203959501) Access denied for user 'people.co.uk'@'srv95.one.com' (using password: NO) Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-476021 Share on other sites More sharing options...
deansatch Posted February 25, 2008 Share Posted February 25, 2008 have you actually got a database set up? are your login details correct? Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-476024 Share on other sites More sharing options...
stanleybb Posted February 25, 2008 Author Share Posted February 25, 2008 yer the database is set up and table called users and the info is right to connect to the database it just wont save anything Also if i take it back to how it use to be but split up, as soon as you click register it displays you to the header.html page thing, and when i go on phpmyadmin site there isnt any new fields. Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-476031 Share on other sites More sharing options...
DarkerAngel Posted February 25, 2008 Share Posted February 25, 2008 Might I suggest using strings instead of DEFINE <?php $db_user = 'people_co_uk'; $db_pass = 'password'; $db_host = 'localhost'; $db_db = 'people_co_uk'; $dbc = mysql_connect ($db_host, $db_user, $db_pass) or die ('Could not connect to MySQL: ' . mysql_error() ); @mysql_select_db ($db_db) OR die ('Could not select the database: ' . mysql_error() ); ?> By the error it seems to be coming from your connection to the DB Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-476035 Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 Access denied means the user id/pw you are connecting with doesn't have the correct rights to perform that action. Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-476037 Share on other sites More sharing options...
stanleybb Posted February 25, 2008 Author Share Posted February 25, 2008 this is what i have so far, i dont get any errors when i click register but nothing is being saved mysql_connect.php <?php $db_user = 'people_co_uk'; $db_pass = 'password'; $db_host = 'localhost'; $db_db = 'people_co_uk'; $dbc = mysql_connect ($db_host, $db_user, $db_pass) or die ('Could not connect to MySQL: ' . mysql_error() ); @mysql_select_db ($db_db) OR die ('Could not select the database: ' . mysql_error() ); ?> tryme.php <h2>Register</h2> <form action="register.php" method="post"> <p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="15" maxlength="30" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Password: <input type="password" name="password1" size="10" maxlength="20" /></p> <p>Confirm Password: <input type="password" name="password2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="Register" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('.includes/footer.html'); ?> register.php <?php $page_title = 'Register'; include ('./includes/header.html'); //check if the form has been submitted. if(isset($_POST['submitted'])) { $errors = array(); // initialize error array. //Check first name if (empty($_POST['first_name'])) { $errors[]= 'You forgot to enter your first name.'; } else { $fn = trim($_POST['first_name']); } //Check last name if (empty($_POST['last_name'])) { $errors[]= 'You forgot to enter your last name.'; } else { $ln = trim($_POST['last_name']); } //Check email address if (empty($_POST['email'])) { $errors[]= 'you forgot to enter email address.'; } else { $e = trim($_POST['email']); } //check the passwords match if(!empty($_POST['password1'])) { if($_POST['password1'] != $_POST['password2']) { $errors[] = 'Your password did not match the confirmed password.'; } else { $p = trim($_POST['password1']); } } else { $errors[] = 'You forgot to enter your password.'; } if(empty($errors)) { // if everythings okay. //register the user in the database. require_once('../mysql_connect.php'); // connect to the db //Make the query $query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW())"; $result = mysql_query ($query); //run query. if($result) { // if it ran ok //send an email, if desired //print message echo '<h1 id="mainhead">Thank you!</h1> <p>You are now registered.</p><p> </p>'; //include the footer and quit the script (to not show the form). include ('.includes/footer.html'); exit(); } else { echo '<h1 id="mainhead">Systems Error</h1> <p class="error">you could not be registered due to a system error</p>'; echo '<p>' . mysql_error(). ' Query: ' .$query . '</p>'; include ('./includes/footer.html'); exit(); } mysql_close(); // close the database connection. } else { //Report the errors echo '<h1 id="mainhead">Error!</h1> <p class="error"> The following error(s) occurred: '; foreach($errors as $msg) { //print each error. echo " - $msg \n"; } echo '</p><p>Please try again.</p><p> </p>'; } // End of if (empty($errors)) IF. }// End of the main Submit conditional. ?> What program do you use to type in php by the way Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-476051 Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 Remove the @ from you DB connection. Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-476054 Share on other sites More sharing options...
stanleybb Posted February 25, 2008 Author Share Posted February 25, 2008 still the same, whats the @ sign for? Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-476061 Share on other sites More sharing options...
DarkerAngel Posted February 25, 2008 Share Posted February 25, 2008 revraz, the @mysql_select_db is fine I've never removed it in any of my scirpts. stanleybb, You don't have the script terminating on fail again. in register.php Rewrite: $result = mysql_query ($query); //run query To: $result = mysql_query ($query) or die($query.'<br>'.mysql_error()); //run query Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-476063 Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 It supresses the errors. still the same, whats the @ sign for? Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-476064 Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 But it's pointless to supress something and then do a DIE statement with a error. revraz, the @mysql_select_db is fine I've never removed it in any of my scirpts. Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-476067 Share on other sites More sharing options...
deansatch Posted February 25, 2008 Share Posted February 25, 2008 remove all the @ operators! You can stick them all back in when the script works but if it isn't working, you need to know where the errors are. Link to comment https://forums.phpfreaks.com/topic/92908-register/#findComment-476069 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.