tommyinnn Posted October 1, 2007 Share Posted October 1, 2007 New to php coding, sorry I want to create a php script that will redirect a member after login depending on the data in their table. It is for my dating site, http://findmytag.com 80% of my members do not have a photo installed, so rather than just make a picture mandatory upon signup, I want to make it so all new & current members cannot access their members area unless they have a photo in their profile. If not, direct them to the photo upload page (upload_photo.php) if they do, just go stright to their members page (index.php) The members information is stored in members_users & the table I want to check is pictures_cnt here's kinda what I want to do, but clearly this won't work if ( $pictures_cnt == 0 ) (index.php) else (upload_photo.php) Thanks for anyone that can guide me in the right direction! Quote Link to comment https://forums.phpfreaks.com/topic/71356-php-redirect-depending-on-database-number/ Share on other sites More sharing options...
HuggieBear Posted October 1, 2007 Share Posted October 1, 2007 Try the header() function... <?php if ($pictures_cnt == 0){ header('Location: index.php'); } else { header('Location: upload_photo.php'); } ?> Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/71356-php-redirect-depending-on-database-number/#findComment-359030 Share on other sites More sharing options...
tommyinnn Posted October 1, 2007 Author Share Posted October 1, 2007 Thanks huggiebear, I've been working on it for about a hour & I'm comming close, but I can't figure this out. Wouldn't I need to tell the script where in the database I need to go? I found this code on another page, is something like this what I'm looking for? $sql = 'SELECT id, username, password, pictures_cnt, '; $row = $db->getRow( $sql, array( USER_TABLE, $_SESSION['UserId'] ) ); Quote Link to comment https://forums.phpfreaks.com/topic/71356-php-redirect-depending-on-database-number/#findComment-359080 Share on other sites More sharing options...
jaymc Posted October 1, 2007 Share Posted October 1, 2007 No What huggie said is correct When logging in it checks to see if they have a photo, if they dont, do not let them proceed to the main website Instead, force them to go to your photo uploader Used header() from huggies example Quote Link to comment https://forums.phpfreaks.com/topic/71356-php-redirect-depending-on-database-number/#findComment-359085 Share on other sites More sharing options...
d.shankar Posted October 1, 2007 Share Posted October 1, 2007 Then try this <?php if (empty(mysql_count_rows($row)){ header('Location: index.php'); } else { header('Location: upload_photo.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71356-php-redirect-depending-on-database-number/#findComment-359096 Share on other sites More sharing options...
trq Posted October 1, 2007 Share Posted October 1, 2007 Correction, that would be... <?php if (!mysql_num_rows($result)){ header('Location: index.php'); } else { header('Location: upload_photo.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71356-php-redirect-depending-on-database-number/#findComment-359097 Share on other sites More sharing options...
tommyinnn Posted October 1, 2007 Author Share Posted October 1, 2007 The code I put in was just an example off of another page. below is the code for the photo upload page, which i figured was a good starting point. The site uses Smarty Templates (tpl files), would I be better off using a tpl file rather than a php file? On my members home page, I can use this code to list either "no pictures" or "# pictures"... {checkuser userid=$smarty.session.UserId checkfor='picscnt'} I tried creating something using that code for several weeks with no luck. Here is the code for the upload_photos.php page <?php if ( !defined( 'SMARTY_DIR' ) ) { include_once( 'init.php' ); } include ( 'sessioninc.php' ); Header("Cache-Control: must-revalidate"); $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() -30) . " GMT"; Header($ExpStr); if( $_GET['del'] == 'yes' ){ $sql = 'SELECT id, picture, tnpicture FROM ! WHERE userid = ? AND picno = ?'; $row = $db->getRow( $sql, array( USER_SNAP_TABLE, $_SESSION['UserId'], $_GET['picno'] ) ); if ($config['images_in_db'] == 'N') { if (substr_count($row['picture'], 'file:' )>0 ) { $curr_imgfile = ltrim(rtrim(str_replace('file:','',$row['picture'] ) ) ); } if (substr_count($row['tnpicture'],'file:' )>0 ) { $curr_tnimgfile = ltrim(rtrim(str_replace('file:','',$row['tnpicture'] ) ) ); } } if ($_GET['typ'] == 'tn' or $config['drop_tn_also'] == 'Y') { @unlink(USER_IMAGE_DIR.$curr_tnimgfile); $sql = 'update ! set tnpicture = ?, tnext = ? where userid = ? and picno = ?'; $db->query ( $sql, array( USER_SNAP_TABLE, '', '', $_SESSION['UserId'], $_GET['picno'] ) ); } if ($_GET['typ'] == 'pic') { @unlink(USER_IMAGE_DIR.$curr_imgfile); $sql = 'update ! set picture = ?, picext = ? where userid = ? and picno = ?'; $db->query ( $sql, array( USER_SNAP_TABLE, '', '', $_SESSION['UserId'], $_GET['picno'] ) ); } $recdel = $db->getOne('select id from ! where userid = ? and picno = ? and picture = ? and tnpicture = ?', array( USER_SNAP_TABLE, $_SESSION['UserId'], $_GET['picno'], '','' ) ) ; if ($recdel > 0) { $db->query('delete from ! where userid = ? and picno = ?',array( USER_SNAP_TABLE, $_SESSION['UserId'], $_GET['picno'] ) ); } updateLoadedPicturesCnt($_SESSION['userid']); header('location: ?'); exit; } if( function_exists( imagejpeg ) ) { $t->assign( 'editable', 1 ); } else { $t->assign( 'editable', 0 ); } $sql = 'select picno, picture, tnpicture, album_id from ! where userid = ? order by picno'; $rows = $db->getAll( $sql, array( USER_SNAP_TABLE, $_SESSION['UserId'] ) ); $userdata = $db->getRow('select usr.level, usr.username, mem.uploadpicture, mem.uploadpicturecnt, mem.allowalbum from ! as usr, ! as mem where mem.roleid = usr.level and usr.id = ?', array(USER_TABLE, MEMBERSHIP_TABLE, $_SESSION['UserId'] ) ); $data = array(); $data[]=" "; foreach ($rows as $row) { $data[] = $row; $nextpic = $row['picno']; } $nextpic++; $useralbums = $db->getAll('select id, name from ! where username = ? order by name', array(USERALBUMS_TABLE, $userdata['username'] ) ); $t->assign('nextpic',$nextpic); $t->assign('maxsize', floor($config['upload_snap_maxsize']/1000)); $t->assign('album_id', $_POST['album_id']); $t->assign('useralbums',$useralbums); $t->assign('userdata',$userdata); $t->assign ( 'lang', $lang ); $t->assign ( 'data', $data ); $t->assign('max_picture_cnt', (count($data) < $userdata['uploadpicturecnt'])? count($data) : $userdata['uploadpicturecnt'] ); $t->assign('rendered_page',$t->fetch('usersnap.tpl')); $t->display ( 'index.tpl' ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/71356-php-redirect-depending-on-database-number/#findComment-359126 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.