dominic600 Posted August 13, 2011 Share Posted August 13, 2011 So im creating an 'edit profile' page and when i go to test it, it will not connect to the database. I know its not th database cause it still allows me to login, post comments and stuff like that. Heres the code its probably something obivious that im just over looking but im not sure.. <?php require("top.php"); ?> <div id='content'> <?php if($username){ require('scripts/connect.php'); if ($_POST['savebtn']){ $firstname = fixtext($_POST['firstname']); $lastname = fixtext($_POST['lastname']); $email = fixtext($_POST['email']); $website = fixtext($_POST['website']); $youtube = fixtext($_POST['youtube']); $bio = fixtext($_POST['bio']); $password = fixtext($_POST['password']); $name = $_FILES['avatar'] ['name']; $type = $_FILES['avatar'] ['type']; $size = $_FILES['avatar'] ['size']; $tmpname = $_FILES['avatar']['tmpname']; $ext = substr($name, strrpos($name, '.')); if ($firstname && $lastname && $email && $password){ if (strstr($email, "@") && strstr($email, ".") && strlen($email) >= 6){ $password = md5($password); $query = mysql_query("SELECT password FROM users WHERE id='$userid'"); $numrows = mysql_num_rows($query); if($numrows == 1){ mysql_query ("UPDATE users SET firstname='$first_name' WHERE id='$userid'"); mysql_query ("UPDATE users SET lastname='$last_name' WHERE id='$userid'"); mysql_query ("UPDATE users SET email='$email' WHERE id='$userid'"); mysql_query ("UPDATE users SET website='$website' WHERE id='$userid'"); mysql_query ("UPDATE users SET youtube='$youtube' WHERE id='$userid'"); mysql_query ("UPDATE users SET bio='$bio' WHERE id='$userid'"); if ($name){ $avatarname = $username.$ext; move_upload_file($tmpname, "avatars/$avatarname"); mysql_query ("UPDATE INTO users SET avatar='$avatarname' WHERE id='$userid'"); } echo "Changes have been saved."; } else echo "Your password was incorrect."; } else echo "You did not enter a valid Email."; } else echo "You did not provide the required info."; } $query = mysql_query("SELECT * FROM users WHERE id='$getid'"); $numrows = mysql_num_rows($query); if($numrows == 1){ $row = mysql_fetch_assoc($query); $id = $row['id']; $firstname = $row['firstname']; $lastname = $row['lastname']; $email = $row['email']; $avatar = $row['avatar']; $bio =($row['bio']); $website = $row['website']; $youtube = $row['youtube']; $lastlogin = $row['last_login']; $active = $row['active']; $locked = $row['locked']; $date = $row['date']; } else echo "An error occured while connecting to the datatbase."; $infoform = "<form action='editprofile.php' method='post'> <table cellspacing='10px'> <tr> <td>First Name:</td> <td><input type='text' name='firstname' class='textbox' size='40' value='$firstname'><font color='red'>*</font></td> </tr> <tr> <td>Last Name:</td> <td><input type='text' name='lastname' class='textbox' size='40' value='$lastname'><font color='red'>*</font></td> </tr> <tr> <td>E-mail:</td> <td><input type='text' name='email' class='textbox' size='40' value='$email'><font color='red'>*</font></td> </tr> <tr> <td>Avatar:</td> <td><input type='file' name='avatar'></td> </tr> <tr> <td>Website:</td> <td><input type='text' name='website' class='textbox' size='40' value='$website'></td> </tr> <tr> <td>Youtube User Name:</td> <td><input type='text' name='youtube' class='textbox' size='40' value='$youtube'></td> </tr> <tr> <td>Bio:</td> <td><textarea name='bio' cols='35' rows='5' class='textbox'>$bio</textarea></td> </tr> <tr> <td>Current Password:</td> <td><input type='password' name='password' class='textbox' size='40'><font color='red'>*</font></td> </tr> <tr> <td></td> <td><input type='submit' name='savebtn' value='Confirm Changes' class='button'></td> </tr> </table> </form>"; echo "$infoform"; ///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// echo "<br /><hr /><br />"; $passform ="<form action='editprofile.php' method='post'> <table cellspacing='10px'> <tr> <td>Current Password:</td> <td><input type='password' name='oldpass' class='textbox' size='40'><font color='red'>*</font></td> </tr> <tr> <td>New Password:</td> <td><input type='password' name='newpass' class='textbox' size='40'><font color='red'>*</font></td> </tr> <tr> <td>Confirm New Password:</td> <td><input type='password' name='confirmpass' class='textbox' size='40'><font color='red'>*</font></td> </tr> <tr> <td></td> <td><input type='submit' name='updatepass' class='submitbtn' size='40'><font color='red'>*</font></td> </tr> </table></form>"; if($_POST['passbtn']){ $oldpass = fixtext($_POST['oldpass']); $newpass = fixtext($_POST['newpass']); $confirmpass = fixtext($_POST['confirmpass']); if($oldpass && $newpass && $confirmpass){ if ($newpass == $confirmpass){ $oldpass = md5($oldpass); $newpass = md5($newpass); $query = mysql_query("SELECT password FROM users WHERE id='$userid'"); $numrows = mysql_num_rows($query); if($numrows == 1){ mysql_query ("UPDATE users SET password='$newpass' WHERE id='$userid'"); echo"Your password has been changed."; } else echo "Your current password is incorrect."; } else echo "Your new passwords did not match."; } else echo"You did not fill in all required fileds."; } else echo "$passwform"; } else echo "you must be logged in to do that."; ?> </div> <div id='footer'></div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/244661-not-connecting-to-the-database/ Share on other sites More sharing options...
Elven6 Posted August 13, 2011 Share Posted August 13, 2011 Hi, Try moving connect.php to the very top of the file (where the top.php line is located)? I assume the only error you're seeing is, An error occured while connecting to the datatbase. Try adding something like mysql_error(); to your code so you can see a more detailed error message. Quote Link to comment https://forums.phpfreaks.com/topic/244661-not-connecting-to-the-database/#findComment-1256704 Share on other sites More sharing options...
trq Posted August 13, 2011 Share Posted August 13, 2011 Where is $username defined? Quote Link to comment https://forums.phpfreaks.com/topic/244661-not-connecting-to-the-database/#findComment-1256705 Share on other sites More sharing options...
dominic600 Posted August 13, 2011 Author Share Posted August 13, 2011 sorry for the delay in replying my internet went out. but my $username is defined in my top.php Quote Link to comment https://forums.phpfreaks.com/topic/244661-not-connecting-to-the-database/#findComment-1256716 Share on other sites More sharing options...
PFMaBiSmAd Posted August 13, 2011 Share Posted August 13, 2011 Without the actual symptom or error you are getting that leads you to believe that - "... an 'edit profile' page and when i go to test it, it will not connect to the database.", it is not directly possible to help you with what your code is doing. We don't have access to all your code, your server, or your database, so we must rely on just the information that you supply in your posts. Quote Link to comment https://forums.phpfreaks.com/topic/244661-not-connecting-to-the-database/#findComment-1256824 Share on other sites More sharing options...
dominic600 Posted August 13, 2011 Author Share Posted August 13, 2011 Oh ok. well what other info or code do you need to see? Quote Link to comment https://forums.phpfreaks.com/topic/244661-not-connecting-to-the-database/#findComment-1256877 Share on other sites More sharing options...
dominic600 Posted August 13, 2011 Author Share Posted August 13, 2011 UPDATE I got it connecting to the database. And now its saying i do not have all the required feilds filled in. even when i fill in them all! Quote Link to comment https://forums.phpfreaks.com/topic/244661-not-connecting-to-the-database/#findComment-1256940 Share on other sites More sharing options...
iStriide Posted August 14, 2011 Share Posted August 14, 2011 There's no need for all of this: <?php mysql_query ("UPDATE users SET firstname='$first_name' WHERE id='$userid'"); mysql_query ("UPDATE users SET lastname='$last_name' WHERE id='$userid'"); mysql_query ("UPDATE users SET email='$email' WHERE id='$userid'"); mysql_query ("UPDATE users SET website='$website' WHERE id='$userid'"); mysql_query ("UPDATE users SET youtube='$youtube' WHERE id='$userid'"); mysql_query ("UPDATE users SET bio='$bio' WHERE id='$userid'"); ?> Just do this: mysql_query("UPDATE users SET firstname = '$firstname', lastname = '$lastname', email = '$email', website = '$website', youtube = '$youtube', bio = '$bio' WHERE id = '$userid'") or trigger_error(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/244661-not-connecting-to-the-database/#findComment-1256949 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.