Flash PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

timka
Forum Commoner
Posts: 26
Joined: Sat Feb 14, 2004 5:11 pm

Flash PHP

Post by timka »

Ok I downloaded a cool Flash PHP Poll but there is somthing wrong with it it won't let me save the poll, Here are the PHP codes that are giving me errors.
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()
&#123;
   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)
   &#123;
      // 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';
   &#125;
   $row = mysql_fetch_assoc($result);
   $my_id = $row&#1111;'id'];
   if (isset ($SSPoll))
   &#123;
      if($HTTP_COOKIE_VARS&#1111;"SSPoll"]==$my_id)
      &#123;
         $votable='false';
      &#125;
   &#125;
   print "id=$row&#1111;id]&question=$row&#1111;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))
   &#123;
      $a++;
      print "&answer_" . ($a<10 ? '0' . $a : $a) . "=$row&#1111;answer]&votes_" . ($a<10 ? '0' . $a : $a) . "=$row&#1111;votes]";
      print "&ids_" . ($a<10 ? '0' . $a : $a) . "=$row&#1111;id]";
   &#125;
   mysql_free_result($result);
&#125;

function send_vote($q,$a)
&#123;
   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";
&#125;

function add_cookie($q)
&#123;
   GLOBAL $cookie_life_time;
   setcookie ("SSPoll", $q,time()+(3600*24*$cookie_life_time));
&#125;

// -----------------
// connect to mysql
// -----------------
$db = mysql_connect($host,$dbuser,$dbpwd);
mysql_select_db($dbname);

switch($action)
&#123;
   case 'send_vote':
      send_vote($questionID,$answerID);
      break;
   default:
      show_all();
      break;
&#125;
// close connection
mysql_close($db);
?>
error it gives me
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()
&#123;
   GLOBAL $db, $questions, $answers;
   $query = mysql_query("SELECT * FROM $questions ORDER BY date_init DESC", $db);
   if(mysql_num_rows($query)>0)
   &#123;
      while($row = mysql_fetch_assoc($query))
      &#123;
         $a++;
         print "&id_$a=$row&#1111;id]&date_init_$a=$row&#1111;date_init]&date_end_$a=$row&#1111;date_end]&question_$a=$row&#1111;question]&online_$a=$row&#1111;online]";
      &#125;
      mysql_free_result($query);
   &#125; else &#123;
      print "code=No.Results";
   &#125;
&#125;

// -------------------- MODIFY POLL ---------------- //
function modify_question($id,$question,$data1,$data2,$online)
&#123;
   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";
&#125;

// ---------------- ERASE POLL ---------------- //
function delete_question($id)
&#123;
   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";
&#125;

// ----------------  ADD POLL ------------------   //
function save_poll()
&#123;
   GLOBAL $db, $questions, $answers;
   $domanda = $GLOBALS&#1111;'HTTP_GET_VARS']&#1111;'question'];
   $online = $GLOBALS&#1111;'HTTP_GET_VARS']&#1111;'online'];
   $valid_from = $GLOBALS&#1111;'HTTP_GET_VARS']&#1111;'valid_from'];
   $valid_to = $GLOBALS&#1111;'HTTP_GET_VARS']&#1111;'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&#1111;'HTTP_GET_VARS']&#1111;'answer_' . ($x<10 ? '0' . $x : $x)]!= '')
   &#123;
      $answer_add = $GLOBALS&#1111;'HTTP_GET_VARS']&#1111;'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++;
   &#125;
   print "output=true";
&#125;

function show_detail($id)
&#123;
   GLOBAL $db, $questions, $answers;
   $query = mysql_query("SELECT * FROM $answers WHERE id_poll = '$id'");
   while($row = mysql_fetch_assoc($query))
   &#123;
      $a++;
      print "&answer_" . ($a < 10 ? '0' . $a : $a) . "=$row&#1111;answer]";
   &#125;
&#125;

function remove_answer($answer,$id)
&#123;
   GLOBAL $db, $questions, $answers;
   $query = mysql_query("DELETE FROM $answers WHERE answer = '$answer' AND id_poll = '$id'");
   print "output=true";
&#125;

function add_answer($answer,$id)
&#123;
   GLOBAL $db, $questions, $answers;
   $query = mysql_query("INSERT INTO $answers (answer,id_poll) VALUES ('$answer','$id')");
   print "output=true";
&#125;

function update_poll($id,$question,$valid_from,$valid_to,$online)
&#123;
   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";
&#125;

// -----------------
// connect to mysql
// -----------------
$db = mysql_connect($host,$dbuser,$dbpwd);
mysql_select_db($dbname);

switch($action)
&#123;
   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;
&#125;
// close connection
mysql_close($db);
?>
error it gives me
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.
timka
Forum Commoner
Posts: 26
Joined: Sat Feb 14, 2004 5:11 pm

Post by timka »

anyone? 8O
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

basically, your queryies are failing. Use the or die mysql_error();. This will display the problem.

Mark
timka
Forum Commoner
Posts: 26
Joined: Sat Feb 14, 2004 5:11 pm

Post by timka »

im a nOOb so how do I do the "or die mysql_error();. "??
timka
Forum Commoner
Posts: 26
Joined: Sat Feb 14, 2004 5:11 pm

Post by timka »

Bech can u help me.
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

Post by uberpolak »

Wherever you have

Code: Select all

mysql_query('something');
Change it to

Code: Select all

mysql_query('something') or die(mysql_error());
timka
Forum Commoner
Posts: 26
Joined: Sat Feb 14, 2004 5:11 pm

Post by timka »

Ok did that now it says

No Database Selected

What do I do now?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Basically what you are doing is attempting to access your database and doing whatever with it, and THEN your are trying to connect to it... make sure you are connected first THEN do what your trying to do
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Just curious, man, you posted this at Flashkit and was pretty anxious to get it done. What is this for, if I may ask?
timka
Forum Commoner
Posts: 26
Joined: Sat Feb 14, 2004 5:11 pm

Post by timka »

well how do I know if im connected, the admin file it says im connected but when I add the pole it won't show up.
Steveo31 yah Im looking for a flash poll, and like I said in flashkit the other once that I found don't work, so Im trying to fix this one, but it would be better to get a working one don't u think. :P
timka
Forum Commoner
Posts: 26
Joined: Sat Feb 14, 2004 5:11 pm

Post by timka »

here is the .sql file if that helps.

Code: Select all

# phpMyAdmin MySQL-Dump
# version 2.2.3
# http://phpwizard.net/phpMyAdmin/
# http://phpmyadmin.sourceforge.net/ (download page)
#
# Host: localhost
# Generato il: 05 Apr, 2002 at 05:09 PM
# Versione MySQL: 3.23.47
# Versione PHP: 4.1.1
# Database : `test`
# --------------------------------------------------------

#
# Struttura della tabella `poll_answers`
#

DROP TABLE IF EXISTS poll_answers;
CREATE TABLE poll_answers (
  id int(20) NOT NULL auto_increment,
  id_poll int(20) NOT NULL default '0',
  answer char(255) NOT NULL default '',
  votes int(20) NOT NULL default '0',
  PRIMARY KEY  (id),
  KEY id (id)
) TYPE=MyISAM;

#
# Dump dei dati per la tabella `poll_answers`
#

# --------------------------------------------------------

#
# Struttura della tabella `poll_questions`
#

DROP TABLE IF EXISTS poll_questions;
CREATE TABLE poll_questions (
  id int(20) NOT NULL auto_increment,
  date_init date NOT NULL default '0000-00-00',
  date_end date NOT NULL default '0000-00-00',
  question text NOT NULL,
  online enum('y','n') NOT NULL default 'n',
  PRIMARY KEY  (id),
  KEY id (id)
) TYPE=MyISAM;

#
# Dump dei dati per la tabella `poll_questions`
#
I tought I might have this problem because the names of the tables in .sql file don't match the once in the load.php and admin.php any one thinks that might be the problem???

cuz look at the load.php and admin.php in them it says

Code: Select all

GLOBAL $db, $questions, $answers, $HTTP_COOKIE_VARS, $SSPoll;
But when I uploaded the .sql file to my database it created tables called poll_questions and poll_answers.
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Phenom wrote:Basically what you are doing is attempting to access your database and doing whatever with it, and THEN your are trying to connect to it... make sure you are connected first THEN do what your trying to do
Based on what this guy said, you need to throw a

Code: Select all

mssql_connect(servername, user, password)
in the php file.

...right?
timka
Forum Commoner
Posts: 26
Joined: Sat Feb 14, 2004 5:11 pm

Post by timka »

how do I do that be more specific guys im new in this, just trying to learn
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Code: Select all

// with mysql 

$usr = "root";
$pwd ="root";
$host ="localhost",

mysql_connect($host, $usr, $pwd)
      or die (couldnt connect: .mysql_error());

//mssql microsoft sql
mssql_connect($host, $usr, $pwd)
      or die (couldnt connect );
timka
Forum Commoner
Posts: 26
Joined: Sat Feb 14, 2004 5:11 pm

Post by timka »

deam it now this error

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE '02-19-2004' > date_init AND '02-19-2004' = date_end AND
Post Reply