Jump to content

php redirect depending on database number


tommyinnn

Recommended Posts

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!

 

 

 

 

 

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'] ) );

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

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' );

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.