|
I don't understand this... "filled the hidden value with a meaningless value (and one coming from an undefined variable)?"
Also, how would I fix this..."However, "Poll Results.php" is another story altogether. That poor file should be taken out into a field and shot!
Have you had a look at "votes.txt" - it's nothing but a whole bunch of new-line separated 1s.
That's some seriously flawed logic in there my friend."
Thanks. I am truely greatful.
|
|
|
|
|
1] Perhaps I can put this another way, which do you find clearer, and 'better'?
(a)
<input type="hidden" name="vote" id="pollChoice" value=""/>
(b)
<input type="hidden" name="vote" id="pollChoice" value="thisIsJustSomeRandomJunkValue"/>
2]( )
(1) Get code
(2) get gun
(3) Find quiet place
(4) Shoot code(repeatedly) in the <body>
Ha, ha - no, to be serious - are you familiar with the term "desk-check", it seems it's gone out of fashion these days, but once upon a time we used to run programs first (before typing) by hand with pen and paper. This forces you to think about the code you're writing and to examine it logically.
As it stands, the logic in your "Poll Results.php" file is terribly flawed. Have you tried writing pseudo-code, then converting that to php - or how about converting your current code to pseudo code - then you'll see why I've been having a bit of a laugh with the whole thing.
It is a problem of logic from here. That's up to you. I decline any further invitation to fix it.
|
|
|
|
|
Okay, sorry, but I just started with PHP in November, and I just got a good book on it, but it doesn't have polls in it, I made the poll from a tutorial, and it worked fine originally, but now it doesn't seem to work. Sorry. But now I am going back to an earlier post of which stated this... "Surely it would be easier to simply add the chosen option(in text) to the file each time a vote is made, followed by adding up the number of instances of each." I am now asking how I would do that. Thanks, and hopefully you will make an exception this once. Thanks!!
|
|
|
|
|
No need to apologize - (not for you anyway - sorry if I was unpleasant)
Yeah, I found php a bit interesting at first - but I found out that I could interface to COM objects so long as the server was running windows (linux xampps doesn't support COM objects, while the windows one does) This was of interest to me, because this means that you can create a website that (for example) that creates office documents based on user entered data, before making the custom and newly created document available for download. (word, excel, powerpoint, access etc)
But in my case, I had a desire to interface to a school/university timetabling program (syllabus+), that as luck would have it offered it's own com server. The massive advantage being that anyone could view a timetable so long as they had a network(or internet) accessible pc(or phone or ps3, etc). Thus freeing users from having to have the software installed on their machines.
Anyhow, the point is that with a large enough motivation I made a start with php back around August sometime(i forget), and have since gone on to write a reasonably functional pdf creation class in php. I realize that there are others available - many for free, though none did what I wanted AND were entirely free of copyright restrictions. I now have some code that will create (semi-optimized) pdfs, with images and attachments that runs under both windows and linux.
Without the help of others, I'd know very little.
Try this on for size:
"Poll Results.php"
<body>
<h3 style="color: rgb(255, 0, 0);">Poll Results</h3>
<span style="color: rgb(255, 0, 0);">
<p>
<?php
$choices = array("Firefox", "Chrome", "Navigator", "Safari", "Opera", "Internet Explorer");
$file = "votes.txt";
$total = 0;
$vote = $_POST["vote"];
print("You voted for: $vote<br>");
$handle = fopen($file,"a+");
$outStr = sprintf("%s\r\n", $vote);
fputs($handle, $outStr);
fclose($handle);
$votes = file($file);
$i = 0;
$totals = array("Firefox"=>0, "Chrome"=>0, "Navigator"=>0, "Safari"=>0, "Opera"=>0, "Internet Explorer"=>0);
$ffx=0; $chr=0; $nav=0; $saf=0; $opr=0; $iex=0;
foreach ($votes as $curLine)
{
if (!strcmp($curLine, "Firefox\r\n"))
$ffx++;
if (!strcmp($curLine, "Chrome\r\n"))
$chr++;
if (!strcmp($curLine, "Navigator\r\n"))
$nav++;
if (!strcmp($curLine, "Safari\r\n"))
$saf++;
if (!strcmp($curLine, "Opera\r\n"))
$opr++;
if (!strcmp($curLine, "Internet Explorer\r\n"))
$iex++;
$i++;
}
printf("%s has %d votes<br>", $choices[0], $ffx);
printf("%s has %d votes<br>", $choices[1], $chr);
printf("%s has %d votes<br>", $choices[2], $nav);
printf("%s has %d votes<br>", $choices[3], $saf);
printf("%s has %d votes<br>", $choices[4], $opr);
printf("%s has %d votes<br>", $choices[5], $iex);
?>
</p>
</span>
<p>Total: <?php echo $i; ?> votes.</p>
</body>
Produces an output of (after a few runs):
Poll Results
You voted for: Opera Firefox has 0 votes Chrome has 1 votes Navigator has 0 votes Safari has 1 votes Opera has 1 votes Internet Explorer has 0 votes
Total: 3 votes.
And creates a file "votes.txt" with the following content:
Chrome
Safari
Opera
Yeah, I know it's not particularly extensible nor neat - but hey look at the time of year - I never did program very well when drunk
|
|
|
|
|
Thank you very much for all your help. I couldn't get anyone else to actually put the time and effort into helping me with this, thanks very much. It's currently 3:43 AM here, on the 1st of January, and the poll is finally finished. Thanks!!
|
|
|
|
|
Hi all,
I have a problem finding the differences between two arrays:
$first_array = array("a"=>"1", "b"=>"7", "c"=>"4", "d"=>"4");
$second_array = array("a"=>"1", "b"=>"10", "c"=>"10", "d"=>"4", "e"=>"7");
I'm trying to subtract the old array from the new one and find any new values. So the output should be:
$new_array = array("b"=>"3", "c"=>"6", "e"=>"7");
I tried using array_diff() and array_diff_assoc(). But they give me the wrong output. Any ideas?
Thanks.
|
|
|
|
|
I'm unaware of any library function that would do that, however you can easily iterate over the first array using
foreach ($first_array as $key => $value) {...}
and then look up the key in the second array, and adjust the value.
|
|
|
|
|
Hi all,
I want to know down to use the postback in php.For example i am using a list box when i select an item i want to display the data in same page.
As in asp.net there is auto post back just similar to that i want to use.
Thanks in advance.....
|
|
|
|
|
form.php:
<form id="form1" action="form.php" method="post">
<select id="mydropdown" name="mydropdown">
<option value="hello">hello</option>
<input type="submit" value="submit" />
</select>
</form>
<?php
if(isset($_POST['mydropdown'])) echo $_POST['mydropdown'];
?>
or you can use ajax such as jquery's $.POST to do it without refreshing the page
|
|
|
|
|
Hi all,
I need help since im new for php.How to display warning message at html label using php script.
Please help to solve this problem.
Thank You.
%#&kmpYrlHSGYG5@#($_+!@!(*JASnjshdk,cm_0ashjhdbn@#$!48mkhfbchsh))^%#W%&@YW7wsdfjw789';'][]\`~JKJQ4$!@#~)-HSKS^&*1)JK12@#@$~!1`DFGkqp][]\]?Zas;EWRG%!@~)(^&BVAG
|
|
|
|
|
kamalesh5743 wrote: How to display warning message at html label using php script.
<label> Warning: blah blah blah </label>
|
|
|
|
|
Imagine the following class that is inherited from std::vector
template<typename ObjType>
class myclass : public std::vector<ObjType*>
{ ... fancy stuff ... }
This class is basically an extended vector; it compiles fine under VS 2005, but fails to compile under Linux. It always throws an error about missing type specifiers when using an iterator, like iterator it = begin(); .
Anyone has an idea what the cause might be? I think it is trying to use std::iterator, even though the function exists in myclass, and so it should have the iterator type (if I don't include using namespace std; , the code fails with an unknown type "iterator", that's why I'm assuming the above).
Again, it compiles fine under Windows.
|
|
|
|
|
Hello All,
I am using the imap_search function and I want to return a list of all mail ids flagged as important. I am using the function this way.
$rst = imap_search($mbox,"FLAGGED");
if($rst===false)
{
echo "miss";
}
else
{
$cnt = count($rst);
for ($i=0; $i<$cnt; $i++)
{
echo "Match found in Msg#: $rst[$i]\n";
}
}
The output from above produces "miss".
I suspect my search string is wrong, but for all my searching I can not find a valid example of its propper usage. The mailbox I am using has 5 email messages in it with one marked as important.
Any ideas?
Thanks in advance!
|
|
|
|
|
nm, I was looking for the wrong thing to begin with. I needed to find emails witha return receipt so I can move them to a different folder.
Do this was easy enough with the strpos function looking for "Return-Receipt-To" in the returned string from imap_fetchheader().
From here it is easy enough to use the imap_mail_move() function (also using the imap_expunge before you close the imap connection).
...cause I share
|
|
|
|
|
Hi,
In a nut shell I'm trying to post some data to a file on a server, and I am having problems.
Since this is a project from a college class that finished on Friday, I need some help to finish it before I forget what the assignment was about. It is somewhat goofy what we were doing, so I will leave most of what already works out of my story.
We are supposed to take a file that is nothing but a text file and is a list of some data. The Perl/CGI file reads that data, constructs a web page that shows that data using a form and input tags. It also, using JavaScript, shows the data in a tree structure. All that code works great and is not my problem.
We are supposed to use the same Perl/CGI file to update the text file on the server using a POST by saving to that text file any changes we make to our data. I can not get the post to work. I do not know if my form is the problem or the problem is in the Perl Script code that detects when I need to make the changes to the text file. I think it is in the form, but I am not sure what properties I need to declare in the form tag except for method="POST".
I could include the code, but it is unnecessary to do so right now. If you could suggest a good tutorial on what you need to do to make a post using perl that would even be ok. I will post the code if nothing else is working for me. Thanks.
PS - In other words, I don't want you to write my code, just explain to me what steps I need to take or guide me to the right solution. Thanks.
|
|
|
|
|
Additional---
I kept trying different things and I have now got everything to work except the file is appended data to the txet file. Here is the code I am using:
open (myCourses, "+<courses.txt") or="" die="" $!;
i="" read="" the="" file="" into="" an="" array="" using="" this="" code:
="" my="" @lines="&<myCourses">;
I then manipulate the data and write it back to the same file inside a foreach loop using the @lines variable. What I get is a duplication of the existing data. I want the data to be removed from the file and then new data added back. The instructor said we are suppossed to use the open statement above, not a read and then a write. Should not this line behave the same as using an open read, and then an open write? I have tried everything, I think. Please help.
|
|
|
|
|
The code is:
open (myCourses, "+<courses.txt") or die $!;
my @lines = <myCourses>;
Sorry for the mess up.
|
|
|
|
|
Not really sure if this will help you,
perl docs - open
"You can put a '+' in front of the '>' or '<' to indicate that you want both read and write access to the file; thus '+<;' is almost always preferred for read/write updates--the '+>;' mode would clobber the file first. You can't usually use either read-write mode for updating textfiles, since they have variable length records."
|
|
|
|
|
Hi every one,
I am getting Gateway Timeout Error when running php script.Script was running fine before after some hours it is giving this error.Don't know why.The script was to connect to DB and insert some data into tables.It is getting timeout even before connecting to DB.
Can any one tell me any reason why this happening.
Regards,
Pavan,Independent Programmer.
|
|
|
|
|
a quick google came up with this...
504 Gateway Timeout
ErrorDocument Gateway Timeout | Sample 504 Gateway Timeout
The server was acting as a gateway or proxy and did not receive a timely request from the upstream server.
If the script was working fine and then it is not, I would look into newly installed software and/or changes to the server configuration.
|
|
|
|
|
Hello sir,
i have some knowledge of C
but can u tell me how can i Start programing for software and Internet Application software....and OS making software ? Which programing languages are best for me to start.
and other program....
Please gave me some support.
Thank you for your support
|
|
|
|
|
Buy a book on <insert language="" here="">
I prefer C++, C, C# and VisualBasic.Net
|
|
|
|
|
thank you for your response and help.
|
|
|
|
|
Can anyone show me a short perl test script to print a crystal report?
Thanks,
Steve
|
|
|
|
|
|