php-windows Digest 25 Nov 2003 12:24:34 -0000 Issue 2015

Topics (messages 22181 through 22184):

Re: Online Polls
        22181 by: Robin Stoker

Error opening files sent via PHP script with IE on XP
        22182 by: Jarl E. Gjessing
        22183 by: Jarl E. Gjessing

insert syntax
        22184 by: Rinku Shivnani

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Hey Nik

Try this little piece of code (I've put in a few tips to help you with
your website coding):

========================================================================
=====================================
// config.inc.php
// here you can put website config options
// such as database config details
// this file, as well as the dbconnect.inc.php file, will be "included"
in the rest of the scripts
// by doing it this way, if any of your database connection details
change, then you only have to 
// change them in one place, the config.inc.php file, instead of
changing every single one of your scripts!

<?php

 $db_host = 'localhost';
 $db_user = 'freaknik';
 $db_password = '';
 $db = 'survey';

?>

// end config.inc.php
========================================================================
=====================================


// dbconnect.inc.php
// this script will connect to the db

<?

 $db_srv_conn = mysql_pconnect($dbhost,$db_user,$db_password)
      or die("Could not connect to the server");

 $db_conn = mysql_select_db($db,$db_srv_conn)
              or die("Could not connect to the database");

?>

// end dbconnect.inc.php
========================================================================
=====================================

// vote.php
// this is the form used for voting
<?php

 include 'config.inc.php';
 include 'dbconnect.inc.php';

 $getpollquery = "SELECT * FROM poll ORDER BY date DESC"; // THIS WILL
GET THE LATEST POLL FROM THE DATABASE
 $getpollquery_handle = mysql_query($getpollquery);
 $getpollquery_result = mysql_fetch_row($getpollquery_handle)

?>

<form method="POST" action="regvote.php">
  <p>
  <?php echo $getpollquery_result[1]; ?></p>
  <p><input type="radio" name="R1" value="response1" checked><?php echo
$getpollquery_result[2]; ?></p>
  <p><input type="radio" name="R1" value="response2"><?php echo
$getpollquery_result[3]; ?></p>
  <p><input type="radio" name="R1" value="response3"><?php echo
$getpollquery_result[4]; ?></p>
     <input type="hidden" name="poll_id" value="<?php echo
$getpollquery_result[0]; ?>">
  <p><input type="submit" value="Submit" name="submit"></p>
</form>

// end vote.php
========================================================================
=====================================

// regvote.php
// this is to process the form and insert data into the database

<?php

 include 'config.inc.php';
 include 'dbconnect.inc.php';

if (array_key_exists("R1", $_POST)) {

        switch ($_POST['R1']) {                 // check which option
was selected and create sql query
                case "response1": 

                        $updatequery = "UPDATE poll SET votes1 WHERE
id=".$_POST['poll_id'];

                case "response2": 

                        $updatequery = "UPDATE poll SET votes2 WHERE
id=".$_POST['poll_id'];

                case "response3": 

                        $updatequery = "UPDATE poll SET votes3 WHERE
id=".$_POST['poll_id'];

        } 

}

if (mysql_query($updatequery)) {

        print "Thank-you, your vote was added successfully.";

}
else {

        print "Sorry, could not add your vote.";

}
?>

// end regvote.php
========================================================================
=====================================

Hope it works ... didn't have time to test it

Good Luck :)
 - Robin



-----Original Message-----
From: Nik [mailto:[EMAIL PROTECTED] 
Sent: 23 November 2003 11:19 PM
To: [EMAIL PROTECTED]
Subject: [PHP-WIN] Online Polls

OK! now I am attempting to develop a small online polling system. I set
up
my tables and html pages. However, I don't seem to understand how to
update
the information in the polling system. I know how to update using sql
but
something about this polling system I don't understand. This is my code
below.
My Table Structure
CREATE TABLE poll (

   id int(10) unsigned NOT NULL auto_increment,  //id of the question

   question varchar(255) NOT NULL,  //question

   response1 varchar(255) NOT NULL, //the first possible answer

   response2 varchar(255) NOT NULL, //the second possible answer

   response3 varchar(255) NOT NULL, //the third possible answer

   votes1 int(10) unsigned DEFAULT '0' NOT NULL, //   It is these three
I am having a problem

   votes2 int(10) unsigned DEFAULT '0' NOT NULL, //   putting the data
into when the user clicks the form

   votes3 int(10) unsigned DEFAULT '0' NOT NULL, //  to post their
choice.

   date date DEFAULT '0000-00-00' NOT NULL, //date of the poll

   PRIMARY KEY (id)

);


*********** start of code ****************

$db_host = 'localhost';
 $db_user = 'freaknik';
 $db_password = '';
 $db = 'survey';

 $db_srv_conn = mysql_pconnect($dbhost,$db_user,$db_password)
      or die("Could not connect to the server");

 $db_conn = mysql_select_db($db,$db_srv_conn)
              or die("Could not connect to the database");

 //Vote.php

 $submit = $_POST['submit'];
 $response = $_POST['response'];
 if (!$submit)
  {
   echo "kindly click submit";

  }
 else
  {
   echo "u're gett there nik<br>";
   $query = mysql_query("UPDATE survey SET vote=$vote+1 WHERE
response=$response"); //I don't quite understand how to get the correct
response to go into the correct field.

   if (!$query)
    {
     echo "Unable to cast vote";
    }
   else
    {
     echo "Thank you for voting";
    }


  }


?>

*********** end of code *****************
Thanks in advance
Nik

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
--- Begin Message ---
I have made a website where registered users can download
documents from a protected area.
Only problem is, that users using windows XP and internet explorer cannot
use the Open, when they klik the link.
I have tried various browsers under Linux and Windows 2000, they dont have
any problems.
I pass a URL like:
http://<SERVERNAME>/index.php?file=/Individuelopgave_uge45/HA/Document.doc
To the server. The PHP script then tages the file argument, and fetches the
file from the server in a location like:
/var/lib/webcol/<filepath>

Sends it to the browser in this way:
header("Content-Type: ".$mime);
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Content-Description: File Downloaded from webcol");
header("Content-Length: ".filesize($ROOT.$_GET['file']));
$fd=fopen($ROOT.$_GET['file'], "r");
fpassthru($fd); 
fclose($fd);
return;

Where $ROOT could be:
/var/lib/webcol/<filepath>
mime is determined from a mimetype template we've made.
An example would in this case be:
applications/msword

The problem is, that when clicking the link, Word starts as expected, but
then reports, that it cannot find the temporary file that Internet Explorer
tells Word that it has been stored as.
And this is true. It does not exist

Any help would be appreciated, thanks

--- End Message ---
--- Begin Message ---
Never mind I found a sollution.
I'm using sessions and thereby sending 
header("Cache-control: private");
Fixed the problem!
Jarl E. Gjessing wrote:

> I have made a website where registered users can download
> documents from a protected area.
> Only problem is, that users using windows XP and internet explorer cannot
> use the Open, when they klik the link.
> I have tried various browsers under Linux and Windows 2000, they dont have
> any problems.
> I pass a URL like:
> http://<SERVERNAME>/index.php?file=/Individuelopgave_uge45/HA/Document.doc
> To the server. The PHP script then tages the file argument, and fetches
> the file from the server in a location like:
> /var/lib/webcol/<filepath>
> 
> Sends it to the browser in this way:
> header("Content-Type: ".$mime);
> header("Content-Disposition: attachment; filename=\"".$filename."\"");
> header("Content-Description: File Downloaded from webcol");
> header("Content-Length: ".filesize($ROOT.$_GET['file']));
> $fd=fopen($ROOT.$_GET['file'], "r");
> fpassthru($fd);
> fclose($fd);
> return;
> 
> Where $ROOT could be:
> /var/lib/webcol/<filepath>
> mime is determined from a mimetype template we've made.
> An example would in this case be:
> applications/msword
> 
> The problem is, that when clicking the link, Word starts as expected, but
> then reports, that it cannot find the temporary file that Internet
> Explorer tells Word that it has been stored as.
> And this is true. It does not exist
> 
> Any help would be appreciated, thanks

--- End Message ---
--- Begin Message ---
Dear All,

I want to insert data from one table to another one. But I don't 
remember the syntax properly. Can you pls help me ?

Insert into tablename2 as select * from tablename1


Thank you.

--- End Message ---

Reply via email to