load.php
Code: Select all
<?php
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
// -----------------------
// SEND TO FLASH FILE
// -----------------------
require_once 'conf/config.inc.php';
// -----------------
// show active poll
// -----------------
function show_all()
{
GLOBAL $db, $questions, $answers, $HTTP_COOKIE_VARS, $SSPoll;
$today = date("Y-m-d");
$query = "SELECT * FROM $questions WHERE '$today' >= date_init AND '$today' <= date_end AND online = 'y' LIMIT 0,1";
$result = mysql_query($query);
$votable = 'true';
if(mysql_num_rows($result) < 1)
{
// no poll active
// other query
$query = "SELECT * FROM $questions WHERE '$today' > date_init AND online = 'y' LIMIT 0,1";
$result = mysql_query($query);
$votable = 'false';
}
$row = mysql_fetch_assoc($result);
$my_id = $rowї'id'];
if (isset ($SSPoll))
{
if($HTTP_COOKIE_VARSї"SSPoll"]==$my_id)
{
$votable='false';
}
}
print "id=$rowїid]&question=$rowїquestion]&online=$votable";
mysql_free_result($result);
$query = "SELECT * FROM $answers WHERE id_poll = '$my_id'";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
$a++;
print "&answer_" . ($a<10 ? '0' . $a : $a) . "=$rowїanswer]&votes_" . ($a<10 ? '0' . $a : $a) . "=$rowїvotes]";
print "&ids_" . ($a<10 ? '0' . $a : $a) . "=$rowїid]";
}
mysql_free_result($result);
}
function send_vote($q,$a)
{
GLOBAL $db, $questions, $answers, $add_cookie;
add_cookie($q);
$query = mysql_query("UPDATE $answers SET votes = votes+1 WHERE id = '$a' AND id_poll = '$q'");
print "output=true";
}
function add_cookie($q)
{
GLOBAL $cookie_life_time;
setcookie ("SSPoll", $q,time()+(3600*24*$cookie_life_time));
}
// -----------------
// connect to mysql
// -----------------
$db = mysql_connect($host,$dbuser,$dbpwd);
mysql_select_db($dbname);
switch($action)
{
case 'send_vote':
send_vote($questionID,$answerID);
break;
default:
show_all();
break;
}
// close connection
mysql_close($db);
?>Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/public_html/load.php on line 21
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/public_html/load.php on line 29
id=&question=&online=false
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/public_html/load.php on line 39
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/public_html/load.php on line 42
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/public_html/load.php on line 48
than the
admin.php
Code: Select all
<?php
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
// -----------------------
// ADMIN FILE
// -----------------------
require_once '../conf/config.inc.php';
// -----------------
// show all records
// -----------------
function show_all()
{
GLOBAL $db, $questions, $answers;
$query = mysql_query("SELECT * FROM $questions ORDER BY date_init DESC", $db);
if(mysql_num_rows($query)>0)
{
while($row = mysql_fetch_assoc($query))
{
$a++;
print "&id_$a=$rowїid]&date_init_$a=$rowїdate_init]&date_end_$a=$rowїdate_end]&question_$a=$rowїquestion]&online_$a=$rowїonline]";
}
mysql_free_result($query);
} else {
print "code=No.Results";
}
}
// -------------------- MODIFY POLL ---------------- //
function modify_question($id,$question,$data1,$data2,$online)
{
GLOBAL $db, $questions, $answers;
if($online == 'true')
$online = 'y';
else
$online = 'n';
$query = "UPDATE $questions SET question = '$question', date_init = '$data1', date_end = '$data2', online = '$online' WHERE id = '$id'";
$result = mysql_query($query);
echo "code=Updated";
}
// ---------------- ERASE POLL ---------------- //
function delete_question($id)
{
GLOBAL $db, $questions, $answers;
$query = mysql_query("DELETE FROM $questions WHERE id = '$id'");
$query_2 = mysql_query("DELETE FROM $answers WHERE id_poll = '$id'");
echo "code=Deleted";
}
// ---------------- ADD POLL ------------------ //
function save_poll()
{
GLOBAL $db, $questions, $answers;
$domanda = $GLOBALSї'HTTP_GET_VARS']ї'question'];
$online = $GLOBALSї'HTTP_GET_VARS']ї'online'];
$valid_from = $GLOBALSї'HTTP_GET_VARS']ї'valid_from'];
$valid_to = $GLOBALSї'HTTP_GET_VARS']ї'valid_to'];
// add the answers...
$first_query = "INSERT INTO $questions (question,date_init,date_end,online) VALUES ('$domanda','$valid_from','$valid_to','$online')";
$first_result = mysql_query($first_query);
$first_id = mysql_insert_id();
$x = 1;
while($GLOBALSї'HTTP_GET_VARS']ї'answer_' . ($x<10 ? '0' . $x : $x)]!= '')
{
$answer_add = $GLOBALSї'HTTP_GET_VARS']ї'answer_' . ($x<10 ? '0' . $x : $x)];
$second_query = "INSERT INTO $answers (id_poll,answer) VALUES ($first_id,'$answer_add')";
$second_result = mysql_query($second_query);
$x++;
}
print "output=true";
}
function show_detail($id)
{
GLOBAL $db, $questions, $answers;
$query = mysql_query("SELECT * FROM $answers WHERE id_poll = '$id'");
while($row = mysql_fetch_assoc($query))
{
$a++;
print "&answer_" . ($a < 10 ? '0' . $a : $a) . "=$rowїanswer]";
}
}
function remove_answer($answer,$id)
{
GLOBAL $db, $questions, $answers;
$query = mysql_query("DELETE FROM $answers WHERE answer = '$answer' AND id_poll = '$id'");
print "output=true";
}
function add_answer($answer,$id)
{
GLOBAL $db, $questions, $answers;
$query = mysql_query("INSERT INTO $answers (answer,id_poll) VALUES ('$answer','$id')");
print "output=true";
}
function update_poll($id,$question,$valid_from,$valid_to,$online)
{
GLOBAL $db, $questions, $answers;
$query = mysql_query("UPDATE $questions SET question = '$question', date_init = '$valid_from', date_end = '$valid_to', online = '$online' WHERE id = '$id'");
print "output=true";
}
// -----------------
// connect to mysql
// -----------------
$db = mysql_connect($host,$dbuser,$dbpwd);
mysql_select_db($dbname);
switch($action)
{
case 'modify_question':
modify_question($id,$question,$data1,$data2,$online);
break;
case 'delete_question':
delete_question($id);
break;
case 'save_poll':
save_poll();
break;
case 'show_detail':
show_detail($id);
break;
case 'remove_answer':
remove_answer($answer,$id);
break;
case 'add_answer':
add_answer($answer,$id);
break;
case 'update_poll':
update_poll($id,$question,$valid_from,$valid_to,$online);
break;
default:
show_all();
break;
}
// close connection
mysql_close($db);
?>Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/public_html/admin/admin.php on line 19
code=No.Results
Now I can't figure out the problem it connects to database and everything but after I create a poll it won't save it.