PDA

View Full Version : sql not functioning on submit



pkcidstudio
08-01-2006, 08:14 PM
hey all the php is correct but now i need a guru to test the sql or please advise as how to fix it. i dont belive it is working correctly becasue i am not getting any data into my database. i hope this isnt double posting i belive it is two diferent questions. thankx for your help sql pros

<?php
/////////////////////Connect to Database///////////////
$link = mysql_connect('localhost', 'session', '123456');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//echo 'Connected successfully';

?>
<?php
session_start();
?>
<?php
/////////////////////////Submission Counter///////////////////////
function submissionCounter(){

$submissionCounter = "SELECT * FROM submissionCounter";
$check = mysql_query($submissionCounter);

if(!session_is_registered('submitted')){
$check("INSERT INTO submissionCounter (session_id, ip_address, user_agent) VALUES ('".session_id()."', WHERE ip_address='{$_POST['REMOTE_ADDR']}', AND user_agent='{$_POST['HTTP_USER_AGENT']}')");
mysql_query($check);
session_register('submitted');
} else {
if(session_is_registered('user_id')){
$check("UPDATE submissionCounter, total_visit SET member='1' WHERE session_id='".session_id()."'");
mysql_query($check);

}
}
if(session_is_registered('submitted')){
$check("UPDATE submissionCounter WHERE session_id='".session_id()."'");
mysql_query($check);

}
if(session_is_registered('complete')){
$check("SELECT function(SUM(total_visit)) FROM submissionCounter");
mysql_query($check);

}
//echo 'function works';
}
?>
<?php
//this would go on the submit form
if (isset($_POST["Submit"]))
{
submissionCounter();
$xamount = "1";
for ($i = 0; $i < $xamount; $i++)
{
if (!empty($xamount[$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 submissionCounter (
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;
-------------------------------------------->
<?php
mysql_close($link);
?>

Twey
08-01-2006, 08:26 PM
What the heck? Is that a <br> tag in the middle of your SQL?

pkcidstudio
08-02-2006, 02:40 PM
my bad, my hand slipped i have since taken it out. any other thoughts on how to get this up and running before i leave town for a few days. thankx all fro the help.

Twey
08-02-2006, 02:47 PM
Well, add:
or die(mysql_error());after your mysql_query() calls (remove the existing semicolons) and give us the output.

pkcidstudio
08-02-2006, 04:03 PM
if i am doing this right i am getting blank screens

<?php
/////////////////////Connect to Database///////////////
$link = mysql_connect('localhost', 'session', '123456');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//echo 'Connected successfully';

?>
<?php
session_start();
?>
<?php
/////////////////////////Submission Counter///////////////////////
function submissionCounter(){

$submissionCounter = "SELECT * FROM submissionCounter";
$check = mysql_query($submissionCounter);

if(!session_is_registered('submitted')){
$check("INSERT INTO submissionCounter (session_id, ip_address, user_agent) VALUES ('".session_id()."', WHERE ip_address='{$_POST['REMOTE_ADDR']}', AND user_agent='{$_POST['HTTP_USER_AGENT']}')");
mysql_query($check);
or die(mysql_error());
session_register('submitted');
} else {
if(session_is_registered('user_id')){
$check("UPDATE submissionCounter, total_visit SET member='1' WHERE session_id='".session_id()."'");
mysql_query($check);
or die(mysql_error());

}
}
if(session_is_registered('submitted')){
$check("UPDATE submissionCounter WHERE session_id='".session_id()."'");
mysql_query($check);
or die(mysql_error());

}
if(session_is_registered('complete')){
$check("SELECT function(SUM(total_visit)) FROM submissionCounter");
mysql_query($check);
or die(mysql_error());

}

//echo 'function works';
}
?>
<?php
//this would go on the submit form
if (isset($_POST["Submit"]))
{
submissionCounter();
$xamount = "1";
for ($i = 0; $i < $xamount; $i++)
{
if (!empty($xamount[$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 submissionCounter (
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;
-------------------------------------------->
<?php
mysql_close($link);
?>

Twey
08-03-2006, 08:48 PM
(remove the existing semicolons)
mysql_query($check);
or die(mysql_error());