Jump to content

Limit records being inserted


Plazman65

Recommended Posts

Hi all, Im hoping that someone here can point me in the right direction. I have gone through everybook I have and have done some searching online with no luck.
Here is what I need to do,
When someone adds a job to their "watch page" I need to be able to limit the number of jobs they can watch depending on their membership type. I also dont want them to have duplicate entries (I havent put that part in yet)
I have tried the following- It didnt work, Im learning as fast as I can but not fast enough. Is this something salvagable? Or am I on the right track. Im not set on doing this a certain way, I just need to do it! Thanks for any help you can provide!

<?php

SELECT membershipcategory.userid AS userid_1, login.userid, mydepartments.username, mydepartments.idcode, mydepartments.depid, membershipcategory.mem_id
FROM ((mydepartments
LEFT JOIN login ON login.username=mydepartments.username)

$query="SELECT COUNT(*) FROM 'username' AND 'DEPID'
$result = mysql_query($query);

if (mem_id=1 and (username AND depid >5);
{
throw new Exception('You have reached your limit of Departments to add');
}

if (mem_id=12 and (username AND depid >10);
{
throw new Exception('You have reached your limit of Departments to add');
}

if (mem_id=1 and (username AND depid >5);

{
throw new Exception('You have reached your limit of Departments to add');
}
//if (depid='gold') then limit 25;



<form id="form2" name="form2" method="POST" action="<?php echo $editFormAction; ?>">
<label>depid</label>
<label>username
<input name="textfield" type="text" value="<?php echo $_SESSION['MM_Username']; ?>" />
</label>
<p>
<label>
<input name="textfield2" type="text" value="<?php echo $row_rs_mydepartment['depid']; ?>" />
</label>

<input type="submit" name="Submit" value="Submit" />
</label>
</p>
<input type="hidden" name="MM_insert" value="form2">
</form>
?>
Link to comment
Share on other sites

For starters:

this:
[code]
if (mem_id=1 and (username AND depid >5);
[/code]
I'd change to:
[code]
if (mem_id==1 && username >= 6 &&  depid >= 6);
[/code]

Also, you can't thow exception like that... If you throw them, you need to catch them, etc... read the manual for more... I'm no expert on that

Make these changes, then see where you are at.

BTW: You have to put a closeing ) when nesting... (xxx(yyy))

Link to comment
Share on other sites

[!--quoteo(post=353216:date=Mar 9 2006, 04:34 AM:name=AV1611)--][div class=\'quotetop\']QUOTE(AV1611 @ Mar 9 2006, 04:34 AM) [snapback]353216[/snapback][/div][div class=\'quotemain\'][!--quotec--]
For starters:

this:
[code]
if (mem_id=1 and (username AND depid >5);
[/code]
I'd change to:
[code]
if (mem_id==1 && username >= 6 &&  depid >= 6);
[/code]

Also, you can't thow exception like that... If you throw them, you need to catch them, etc... read the manual for more... I'm no expert on that

Make these changes, then see where you are at.

BTW: You have to put a closeing ) when nesting... (xxx(yyy))
[/quote]
,
Thanks for the nesting thing, I didnt catch that,
After looking at it some more I am confusing myself even more,
It doesnt help that I cant find much in these books I bought. What I am looking at is throwing errors from a form so thats didnt help
I think that part of the problem comes in with the query-

$query="SELECT COUNT(*) FROM 'username' AND 'DEPID'
$result = mysql_query($query);

I dont know how to tell it, hey check the table"username" and see what the membership type is, then take that value and compare it to the table mydepartments and if its standard then you cant enter more then 5.
Any suggestions would be greatly appreciated!
Link to comment
Share on other sites

Have you ever used php before?

I can't even begin to list the basic syntax errors that are in your code...no $ before your variables, your if statements are written, incorrectly, in pseudocode. Pretty much I can sum up your code in one word...FUBAR.

Please read at least one tutorial on this website on the basics of php. Please read at least one tutorial [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]anywhere[!--colorc--][/span][!--/colorc--] on the basics of php.
Link to comment
Share on other sites

[!--quoteo(post=353804:date=Mar 10 2006, 05:50 PM:name=hitman6003)--][div class=\'quotetop\']QUOTE(hitman6003 @ Mar 10 2006, 05:50 PM) [snapback]353804[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Have you ever used php before?

I can't even begin to list the basic syntax errors that are in your code...no $ before your variables, your if statements are written, incorrectly, in pseudocode. Pretty much I can sum up your code in one word...FUBAR.

Please read at least one tutorial on this website on the basics of php. Please read at least one tutorial [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]anywhere[!--colorc--][/span][!--/colorc--] on the basics of php.
[/quote]
well I guess I wasnt clear on my original post, Im new, and no I havent done this before. I have managed to muddle my way through most of my website, I am reading tutorials as fast as I can, I am starting to be able to read the code and understand what something is doing but Im not to the point that I can say hey I want to do this and write it out.
I did look everywhere for example or something that does "limit" ,I did run accross one thing and I thought it was similar to what I was doing, I guess from your reaction that it isnt.
Im not asking anyone to write code for me or anything but if anyone knows a tutorials that covers how to limit, I was also told its select count. I would be grateful to hear where because I havent found it.
Thanks, Michelle



Link to comment
Share on other sites

[!--quoteo(post=353941:date=Mar 11 2006, 11:09 AM:name=AV1611)--][div class=\'quotetop\']QUOTE(AV1611 @ Mar 11 2006, 11:09 AM) [snapback]353941[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Ouch...
[/quote]
yeah...I'm a jerk...
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Hitman... At least the guy posted in the NEWBIE forum... not the regular forum...[/quote]
Sometimes I forget which one I'm on....

I can only assume that you aren't posting all your code. What are you trying to limit...I know you said the number of jobs, but I don't see that value being defined anywhere. I'm guessing that you are trying to prevent them from adding another "watched job" if they are not at least a gold member...so you would need to do your limiting check before adding the job.

I cleaned up your code below, but I still can't really make sense of what your trying to do. How are you adding the job to be watched? When they select it, and ask that it be watched for them, that's where you need to do your check for their membership level...then use an if statement to determine the action:

[code]$sql = "SELECT watchedjobs FROM table WHERE username = '$username';
$result = mysql_query($sql);
if (mysql_num_rows($result) > 25 && $member_level != 'Gold') {
  do whatever to disallow access
} else {
  allow access
}[/code]

[code]
<?php
//if you are going to use a session, make sure you have session_start() at the top...

/*
    //what's all this?
    SELECT membershipcategory.userid AS userid_1, login.userid, mydepartments.username, mydepartments.idcode, mydepartments.depid, membershipcategory.mem_id
    FROM ((mydepartments
    LEFT JOIN login ON login.username=mydepartments.username)
*/

//why are you doing this query?  You don't use it anywhere.
$query="SELECT COUNT(*) FROM 'username' AND 'DEPID'"; //you missed the closing quote and semicolon here
$result = mysql_query($query);

//= sets the value, == compares the values, use == in this case
if ($mem_id == 1 && $username > 5 && $depid > 5) //don't put a semicolon here
{
    //throw is not a php command, nor is exception...use die to do the same thing
    //throw new Exception('You have reached your limit of Departments to add');
    die("You have reached your limit of Departments to add");
}

//follow the same comments as above to fix this part
if (mem_id=12 and (username AND depid >10);
{
throw new Exception('You have reached your limit of Departments to add');
}

//I removed the block of code that was here cause it was the same as the first if statement

//What's this?
//if (depid='gold') then limit 25;

//make sure you close your php tags before going back to html...
//the code below here looks pretty good...
?>

<form id="form2" name="form2" method="POST" action="<?php echo $editFormAction; ?>">
<label>depid</label>
<label>username
<input name="textfield" type="text" value="<?php echo $_SESSION['MM_Username']; ?>" />
</label>
<p>
<label>
<input name="textfield2" type="text" value="<?php echo $row_rs_mydepartment['depid']; ?>" />
</label>

<input type="submit" name="Submit" value="Submit" />
</label>
</p>
<input type="hidden" name="MM_insert" value="form2">
</form>

[/code]
Link to comment
Share on other sites

What you'll want to do is a simple thought process.. think of it this way.

- Grab the number of 'Watched Jobs' the user has.
- Grab the users's membership status.
- Once both of those are defined, then allow insertion only if the number of Watched Jobs is less than what the membership status allows ( should not be hardcoded, but should be in a variable somewhere, to make it more expandable )
Link to comment
Share on other sites

OK guys/gals I did some reading over the weekend, and I had no idea what I was doing,. Still dont but Im hoping Im getting better at it in some way. Hitman your comments were right on cue.
With that being said, Im still stuck Im starting with just one membership level at a time to figure it out.
I am trying to limit the #of jobs being entered per membership level.
Here's what I did-

<?php
$mem_type=$_POST['mem_type']
?> this is after the session start stuff

then I have

<form action="<?php echo $editFormAction; ?>" id="form2" name="form2" method="POST">

//do I put this here?

<?php
$mysql_query = "SELECT depid FROM mydepartments WHERE username = '$MM_Username'";
$result = mysql_query($mysql_query);

if (mysql_num_rows($result)<=5 && $mem_type == 'standard' )

{
die("You have reached your limit of departments you may add, Please go edit Your departments before you try to add more departments");

}
else
{
echo("your department has been added");
}
?>

//I want it to process the form and say "your department has been added"[/color]
</a><a href="../mydepartment/mydepartments.php" target="_blank"></a>
<input name="textfield" type="text" value="<?php echo $row_Recordset2['mem_type']; ?>" />
<a href="../mydepartment/mydepartments.php" target="_blank">
<input type="text" name="username2" id="username2" value="<?php echo KT_escapeAttribute($row_rsmydepartments['username']); ?>" size="32" />
</a></label>
<p>
<label>depid<a href="../mydepartment/mydepartments.php" target="_blank">
<input type="text" name="depid2" id="depid2" value="<?php echo KT_escapeAttribute($row_rsmydepartments['depid']); ?>" size="32" />
</a></label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</p>
<input type="hidden" name="MM_insert" value="form2">
</form>

So what its doing is saying your department has been added even if you have more then 5 and your membership type is standard. I know Im close, any ideas, suggestions, etc? Thanks everybody, Michelle
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.