i have updated this script hoping i am on the right trail any thoughts?
hey all, i wrote a submission counter this mornign and was wondering if one of you php gurus could proof read it for me and tell em if i am on the right track.
what it is suppose to do is, track how many times users submit a form on my website, and if they have already done it than it will not track them more than once. but it tracks how many people have submitted through the function and a session id, and if it reaches x amount than it will produce a error when they submit saying sorry contest is over. i am very thankfull for all the help. i am still working on this but figured i would toss it out for review by some of you pro's.
so here is the php and sql
PHP Code:
<?php
$dbhost = 'localhost';
dbuser = 'session';
$dbpass = '123456';
$dbname = 'session';
?>
<?php
/////////////////////Connect to Database///////////////
function dbconnect () {
global $dbhost, $dbuser, $dbpass, $dbname;
global $MYSQL_ERRNO, $MYSQL_ERROR;
$link_id = mysql_pconnect ($dbhost, $dbuser, $dbpass);
if(!$link_id) {
$MYSQL_ERRNO = 0;
$MYSQL_ERROR = "Could not connect to the host $dbhost.";
return 0;
} else if (empty($dbname) && !mysql_select_db($dbname)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
return 0;
} else {
return $link_id;
}
}
?>
<?php
dbconnect();
session_start();
?>
<?php
/////////////////////////Submission Counter///////////////////////
function submissionCounter(){
$check = mysql_query(ppl_submitted);
if(!session_is_registered('submitted')){
$check("INSERT INTO ppl_submitted (session_id, ip_address, user_agent) <br> VALUES ('".session_id()."', '{$_SERVER['REMOTE_ADDR']}', '{$_SERVER['HTTP_USER_AGENT']}')");
session_register('submitted');
} else {
if(session_is_registered('user_id')){
$check("UPDATE ppl_submitted, total_visit SET member='1' WHERE session_id='".session_id()."'");
}
}
if(session_is_registered('submitted')){
$check("UPDATE ppl_submitted WHERE session_id='".session_id()."'");
}
if(session_is_registered('complete')){
$check("SELECT function(SUM(total_visit)) FROM ppl_submitted")
}
}
?>
<?php
//this would go on the submit form
if (isset($_POST["Submit"]))
{
submissionCounter();
for ($i = 0; $i < 0; $i++)
{
if (!empty($check[$i]))
{
echo "contest is over";
}
}
}
?>
<html>
<head>
</head>
<body>
<form action="" method="post">
<input name="test" type="text" maxlength="5" value="" size="5" >
<input name="test2" type="text" maxlength="3" value="" size="4" >
<input type="submit" value="Submit" >
</form>
</body>
</html>
<!--sqlsqlsqlsqlsqlsqlsqlsqlsqlsqlsqlsqlsql--
CREATE TABLE ppl_submitted (
session_id varchar(255) NOT NULL default '',
total_visit varchar(150) NOT NULL default '0',
member enum('1','0') default '0',
ip_address varchar(255) NOT NULL default '',
user_agent varchar(255) default NULL,
PRIMARY KEY (session_id),
KEY session_id (session_id)
) TYPE=MyISAM;
-------------------------------------------->
feel free to tell me where i am wrong and help out in any way
Bookmarks