Query error need help please

2004-09-14 Thread Soheil Shaghaghi
Hello.
I have a subroutine which checks for multiple entries and if a user has
voted once in the same day, it will not calculate the vote. However, I
found out that it does not really do this.
What it does is only look at the last entry. If the user IP address is
the last entry it does not calculate the vote, but if it is not, it goes
ahead and let the user vote.
So, basically it only looks at the very last entry.
Can someone please tell me what needs to be done to fix this?
Thanks so much.


if(isset($_POST['submit_rating'])  isset($_POST['user_id'])  
($_POST['submit_rating'] = 3  $_POST['submit_rating'] =
10)){

$user_id = (int) $_POST['user_id'];

if(isset($_SESSION['ra'])){
$_SESSION['ra'] .= $user_id . ,;
} else {
$_SESSION['ra'] = $user_id . ,;
}

$rating = (int) $_POST['submit_rating'];
$rater_id = isset($_SESSION['userid']) ? $_SESSION['userid'] :
0;

$check_ip_sql = 
select
*
from
$tb_ratings
where
user_id = '$user_id'
order by
timestamp desc
;

$check_ip_query = mysql_query($check_ip_sql) or
die(mysql_error());
$last_rater_ip = @mysql_result($check_ip_query, 0,
rater_ip);
$last_rater_id = @mysql_result($check_ip_query, 0,
rater_id);
$last_rated = @mysql_result($check_ip_query, 0, timestamp);

$yesterday = date(YmdHis,
mktime(date(H), date(i), date(s),
date(m), date(d)-10, date(Y)));

$same_ip = false;
$too_soon = false;
$same_user = false;

if($last_rater_ip == $HTTP_SERVER_VARS['REMOTE_ADDR']) $same_ip
= true;
if($last_rated  $yesterday) $too_soon = true;
if($user_id == $rater_id) $same_user = true;

if(!$same_user  (!$same_ip || !$too_soon)){
$rating_accepted = true;

$is_sql = 
insert into $tb_ratings (
id,
user_id,
rating,
rater_id,
rater_ip
) values (
'',
'$user_id',
'$rating',
'$rater_id',
'$_SERVER[REMOTE_ADDR]'
)
;

$is_query = mysql_query($is_sql) or die(mysql_error());

$gs_sql = 
select
total_ratings,
total_points,
average_rating
from
$tb_users
where
id = '$user_id'
;

$gs_query = mysql_query($gs_sql) or die(mysql_error());
$total_ratings = mysql_result($gs_query, 0,
total_ratings);
$total_points = mysql_result($gs_query, 0,
total_points);

$total_ratings++;
$total_points += $rating;
$average_rating = $total_points / $total_ratings;

$ps_sql = 
update
$tb_users
set
total_ratings = '$total_ratings',
total_points = '$total_points',
average_rating = '$average_rating'
where
id = '$user_id'
;

$ps_query = mysql_query($ps_sql) or die(mysql_error());

}
}



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Query error need help please

2004-09-14 Thread Greg Donald
On Tue, 14 Sep 2004 19:55:42 -0700, Soheil Shaghaghi [EMAIL PROTECTED] wrote:
 I have a subroutine which checks for multiple entries and if a user has
 voted once in the same day, it will not calculate the vote. However, I
 found out that it does not really do this.
 What it does is only look at the last entry. If the user IP address is
 the last entry it does not calculate the vote, but if it is not, it goes
 ahead and let the user vote.
 So, basically it only looks at the very last entry.
 Can someone please tell me what needs to be done to fix this?
 Thanks so much.


This is fixed in the latest version:

http://sourceforge.net/projects/destiney/

If not, let me know and I'll look into it.  I'm still maintaining the
0.3 series.


-- 
Greg Donald
http://destiney.com/

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Need help please!

2002-02-14 Thread Richard C Rossy

 
Ok I can't seem to get this. Now is it possible to have MySQL on a other
computer and run the script.
In other words  the perl script is on foo.com and MySQL database is on
foo2.com. What is need to make the script work. What I have in the
script is:
 
Configure.pl
 
sub configure {

# CGI CONFIGURATION VARIABLES

$mailprogram = /usr/sbin/sendmail -t;
$mysqlhost = mysql.foo2.com 3306;
$mysqldatabase = matchpro;
$mysqlusername = username;
$mysqlpassword = password;
add.pl 
 
#!/usr/bin/perl -s
use Socket;
use DBI;
 
require configure.pl;
configure; 
open (HEADERHTML, $headerhtml);
@header = HEADERHTML;
close HEADERHTML;
open (FOOTERHTML, $footerhtml);
@footer = FOOTERHTML;
close FOOTERHTML;
 
$orderid = generateorderid;
$profilenumber = $orderid;
 
form_parse;
   $AdHeadline = $FORM{'AdHeadline'};
   $EmailAddress = $FORM{'EmailAddress'};
   $TelephoneAreaCode = $FORM{'TelephoneAreaCode'};
   $City = $FORM{'City'};
   $StateProvince = $FORM{'StateProvince'};
   $Zip = $FORM{'Zip'};
   $Country = $FORM{'Country'};
   $RelationshipPreference = $FORM{'RelationshipPreference'};
   $SexualPreference = $FORM{'SexualPreference'};
   $Username = $FORM{'Username'};
   $Password = $FORM{'Password'};
   $VerifyPassword = $FORM{'VerifyPassword'};
   $SmokingPreference = $FORM{'SmokingPreference'};
   $DrinkingPreference = $FORM{'DrinkingPreference'};
   $MaritialStatus = $FORM{'MaritialStatus'};
   $HaveChildren = $FORM{'HaveChildren'};
   $BodyBuild = $FORM{'BodyBuild'};
   $Height = $FORM{'Height'};
   $Religion = $FORM{'Religion'};
   $Race = $FORM{'Race'};
   $AstrologicalSign = $FORM{'AstrologicalSign'};
   $Age = $FORM{'Age'};
   $Occupation = $FORM{'Occupation'};
   $MiscComments = $FORM{'MiscComments'};
   $MiscComments =~ s/ /\|/g;
   $MiscComments =~ s/\s/\|/g;
   $MiscComments =~ s/\|+/ /g;
 
 
$dbh = DBI-connect(DBI:mysql:$mysqldatabase,
$mysqlhost,$mysqlusername, $mysqlpassword) || die(Couldn't
connect to database!\n);
print Content-type: text/html\n\n;
printheader;
errcheck;
checkuniqueusernames;
checkuniqueemails;
savedata;
printconfirmation;
printfooter;
emailmember;
 
$dbh-disconnect;
 
There is more but the script never gets past $dbh = DBI
 


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail mysql-unsubscribe-##L=##[EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: Need help please!

2002-02-14 Thread Brian Reichert

On Thu, Feb 14, 2002 at 01:05:24PM -0500, Richard C Rossy wrote:
  
 Ok I can't seem to get this. Now is it possible to have MySQL on a other
 computer and run the script.
 In other words  the perl script is on foo.com and MySQL database is on
 foo2.com. What is need to make the script work. What I have in the
 script is:

Have you actually read the perl docs for DBI?

   DBI Class Methods

   ...

   connect

 $dbh = DBI-connect($data_source, $username, $password)
   or die $DBI::errstr;

   ...

   Examples of $data_source values are:

 dbi:DriverName:database_name
 dbi:DriverName:database_name@hostname:port
 dbi:DriverName:database=database_name;host=hostname;port=port

   There is no standard for the text following the driver
   name. Each driver is free to use whatever syntax it
   wants.

So - compare the documentation with what your effort was, and note
the difference:

 $dbh = DBI-connect(DBI:mysql:$mysqldatabase,
 $mysqlhost,$mysqlusername, $mysqlpassword) || die(Couldn't
 connect to database!\n);

-- 
Brian 'you Bastard' Reichert[EMAIL PROTECTED]
37 Crystal Ave. #303Daytime number: (603) 434-6842
Derry NH 03038-1713 USA Intel architecture: the left-hand path

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: [QUERY] Problem with Syntax/Query. Need Help Please.

2001-11-17 Thread Tore Van Grembergen

I don't now ich language you are using to perform this query.
But as mysql does not know any stored procedures, you will have to do it in
code with different call's.

the value of the id (seed in mssql) can be obtained with the SQL function
LAST_INSERT_ID()

a little hint.  in your stored procedure in case of non existance of a
personid, personid has a value of null on mssql.
so it is better to cheque on mssql personid IS NULL.





- Original Message -
From: Pure Krome [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, November 17, 2001 9:02 AM
Subject: [QUERY] Problem with Syntax/Query. Need Help Please.


 G'Day All.

 I'm trying to do the following in a query, in mySQL.
 All my previous years of SQL has been on MS-SQL, and i'm having some
little
 problems with tricky sql statements.

 *
 i'm trying to insert a new record if the name doesn't exist in the table.
If
 i insert, return ID, else return 0
 *

 pseduo -sql syntax

 SET NOCOUNT ON

 DECLARE @intPersonID   INTEGER

 SELECT PersonID from tbl_PERSON WHERE Name = @strName
 SELECT @intPersonID = @@IDENTITY

 IF @intPersonID  1
BEGIN
   INSERT tbl_PERSON (Name, Surname) VALUES ('TestName', 'TestSurname')
   SELECT @intPersonID = @@IDENTITY
END
 ELSE
SET @intPERSONID = 0

 end psedu untested code

 I have NO idea how i can do this on MYSQL..

 Any help would be extreamly appreciated.

 -Regards : Pure Krome-


 -
 Before posting, please check:
http://www.mysql.com/manual.php   (the manual)
http://lists.mysql.com/   (the list archive)

 To request this thread, e-mail [EMAIL PROTECTED]
 To unsubscribe, e-mail [EMAIL PROTECTED]
 Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




[QUERY] Problem with Syntax/Query. Need Help Please.

2001-11-16 Thread Pure Krome

G'Day All.

I'm trying to do the following in a query, in mySQL.
All my previous years of SQL has been on MS-SQL, and i'm having some little
problems with tricky sql statements.

*
i'm trying to insert a new record if the name doesn't exist in the table. If
i insert, return ID, else return 0
*

pseduo -sql syntax

SET NOCOUNT ON

DECLARE @intPersonID   INTEGER

SELECT PersonID from tbl_PERSON WHERE Name = @strName
SELECT @intPersonID = @@IDENTITY

IF @intPersonID  1
   BEGIN
  INSERT tbl_PERSON (Name, Surname) VALUES ('TestName', 'TestSurname')
  SELECT @intPersonID = @@IDENTITY
   END
ELSE
   SET @intPERSONID = 0

end psedu untested code

I have NO idea how i can do this on MYSQL..

Any help would be extreamly appreciated.

-Regards : Pure Krome-


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php