xmodpt Posted July 31, 2009 Share Posted July 31, 2009 Hello all I have a problem, i have a working login and register form but now i need to attache a user photo to the registration form. Sounds simple but for someone that is just starting .... :facewall: . This is what i have: Data base: Id - int(10) firstname - Varchar (100) lastname - Varchar (100) login - Varchar (100) passwd - Varchar (32) photo - LONGBLOB My register form: register-form.php <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Login Form</title> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> </head> <body> <?php if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) { echo '<ul class="err">'; foreach($_SESSION['ERRMSG_ARR'] as $msg) { echo '<li>',$msg,'</li>'; } echo '</ul>'; unset($_SESSION['ERRMSG_ARR']); } ?> <form id="loginForm" name="loginForm" method="post" action="register-exec.php"> <table width="300" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <th>First Name </th> <td><input name="fname" type="text" class="textfield" id="fname" /></td> </tr> <tr> <th>Last Name </th> <td><input name="lname" type="text" class="textfield" id="lname" /></td> </tr> <tr> <th width="124">Login</th> <td width="168"><input name="login" type="text" class="textfield" id="login" /></td> </tr> <tr> <th>Password</th> <td><input name="password" type="password" class="textfield" id="password" /></td> </tr> <tr> <th>Confirm Password </th> <td><input name="cpassword" type="password" class="textfield" id="cpassword" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Register" /></td> </tr> </table> </form> </body> </html> register-exec.php <?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $fname = clean($_POST['fname']); $lname = clean($_POST['lname']); $login = clean($_POST['login']); $password = clean($_POST['password']); $cpassword = clean($_POST['cpassword']); $imgfile = array_item($_FILES, 'imgfile'); //Input Validations if($fname == '') { $errmsg_arr[] = 'First name missing'; $errflag = true; } if($lname == '') { $errmsg_arr[] = 'Last name missing'; $errflag = true; } if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } if($cpassword == '') { $errmsg_arr[] = 'Confirm password missing'; $errflag = true; } if( strcmp($password, $cpassword) != 0 ) { $errmsg_arr[] = 'Passwords do not match'; $errflag = true; } //Check for duplicate login ID if($login != '') { $qry = "SELECT * FROM members WHERE login='$login'"; $result = mysql_query($qry); if($result) { if(mysql_num_rows($result) > 0) { $errmsg_arr[] = 'Login ID already in use'; $errflag = true; } @mysql_free_result($result); } else { die("Query failed"); } } //If there are input validations, redirect back to the registration form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: register-form.php"); exit(); } if($submitbtn == 'OK' and is_array($imgfile)) { $uperr = array_item($imgfile, 'error'); $tmpfile = $imgfile['tmp_name']; //Create INSERT query $qry = "INSERT INTO members(firstname, lastname, login, passwd) VALUES('$fname','$lname','$login','".md5($_POST['password'])."')"; $result = @mysql_query($qry); //Check whether the query was successful or not if($result) { header("location: register-success.php"); exit(); }else { die("Query failed"); } ?> How do i add a field on all this so i can upload a photo (png/jpg) to the database it sef ? I have been googling alot and check alot of examples but none did what i need'it to do.... Thank you all Link to comment https://forums.phpfreaks.com/topic/168331-help-a-noob-user-profile-with-picture/ Share on other sites More sharing options...
xmodpt Posted August 1, 2009 Author Share Posted August 1, 2009 up Link to comment https://forums.phpfreaks.com/topic/168331-help-a-noob-user-profile-with-picture/#findComment-888036 Share on other sites More sharing options...
bundyxc Posted August 1, 2009 Share Posted August 1, 2009 Upload the image to your website, and keep them all in a folder. Take the URL to the image, and put it in the database. Then whenever you need to use the image, just grab the URL from the db. Link to comment https://forums.phpfreaks.com/topic/168331-help-a-noob-user-profile-with-picture/#findComment-888182 Share on other sites More sharing options...
xmodpt Posted August 1, 2009 Author Share Posted August 1, 2009 bundyxc: Thank you for the hint but i was thinking in getting it embed into the db for security reasons. i am talking about 5 users so it's not much load on the DB. Now taking your advise into consideration, how do i change my code to do it... I'll be honest... no clue... Thank you Link to comment https://forums.phpfreaks.com/topic/168331-help-a-noob-user-profile-with-picture/#findComment-888239 Share on other sites More sharing options...
JonathanV Posted August 1, 2009 Share Posted August 1, 2009 bundyxc: Thank you for the hint but i was thinking in getting it embed into the db for security reasons. i am talking about 5 users so it's not much load on the DB. Now taking your advise into consideration, how do i change my code to do it... I'll be honest... no clue... Thank you Use the FileIO and just put the name of the picture in your database as a field in the usertable. This should get you started There's some great examples for this on the php.net docs! Link to comment https://forums.phpfreaks.com/topic/168331-help-a-noob-user-profile-with-picture/#findComment-888245 Share on other sites More sharing options...
xmodpt Posted August 1, 2009 Author Share Posted August 1, 2009 Thank you 4 the hint. I will try to see if can make any sense out of it. Cya in a min Link to comment https://forums.phpfreaks.com/topic/168331-help-a-noob-user-profile-with-picture/#findComment-888247 Share on other sites More sharing options...
xmodpt Posted August 1, 2009 Author Share Posted August 1, 2009 thank you all :D :D Link to comment https://forums.phpfreaks.com/topic/168331-help-a-noob-user-profile-with-picture/#findComment-888521 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.