Archive for the ‘programming with php’ Category
Need help with this PHP code!?
i am having trouble getting the ands between the coins to work properly, if someone could help that would be awesome! i am new to php programming.
<html>
<head>
<title>Coins Program</title>
<style>
body {font-family: sans-serif; font-size:x-large;}
</style>
</head>
<body>
<?php
// get the number of quarters and the number of dimes from the querystring
$quarters = $_GET['q'];
$dimes = $_GET['d'];
$nickels = $_GET['n'];
$pennies = $_GET['p'];
// compute the dollar value of these coins
$dollars = (.25 * $quarters) + (.10 * $dimes) + (.05 * $nickels) + (.01 * $pennies);
// and print the result
if (isset($_GET['q']))
{
echo "$quarters quarters";
}
if (isset($quarters) AND ($dimes))
{
echo " and ";
}
if (isset($_GET['d']))
{
echo "$dimes dimes ";
}
if (isset($quarters) OR ($dimes) AND ($nickels))
{
echo " and ";
}
if (isset($_GET['n']))
{
echo "$nickels nickels ";
}
if (isset($quarters) OR ($dimes) AND ($nickels))
{
echo " and ";
}
if (isset($_GET['p']))
{
echo "$pennies pennies ";
}
if ($dollars == 0)
{
echo "Please enter values into the querystring";
}
else
{
echo "is $$dollars";
}
?>
</body>
</html>
I think your referring to how the ‘and’ echos when you aren’t really wanting it to.
I’ve been sitting here copying and pasting non-stop, its just very very very long coded to do what your doing.
Too many checks going on.
You should just do something like this to see your results
You used:
Quarters: 1
Dimes: 1
Nickels: 1
Pennies: 1
Grand Total: 4
and do a if (!isset($quarters)) { $quarters = "0"; } if a value isn’t being used.
I do understand what your trying to do, the long code that your wanting to do is possible. But your going to be spending hours sitting there programming this little script.
——————
Here’s a demo I did of what I would be using, then again I don’t know what your using this for.
<?php
// Lets Gather Variables
if (!isset($_GET['q'])) { // Quarters
$quarters = "0";
} else if(isset($_GET['q'])) {
$quarters = $_GET['q'];
}
if (!isset($_GET['d'])) { // Dimes
$dimes = "0";
} else if(isset($_GET['d'])) {
$dimes = $_GET['d'];
}
if (!isset($_GET['n'])) { // Nickels
$nickels = "0";
} else if(isset($_GET['n'])) {
$nickels = $_GET['n'];
}
if (!isset($_GET['p'])) { // Pennies
$pennies = "0";
} else if(isset($_GET['p'])) {
$pennies = $_GET['p'];
}
// compute the dollar value of these coins
$dollars = (.25 * $quarters) + (.10 * $dimes) + (.05 * $nickels) + (.01 * $pennies);
// Lets check our results
echo "Quarters used: " .$quarters. "</br> Dimes Used: " .$dimes. "</br> Nickels Used: " .$nickels. "</br> Pennies used: " .$pennies. "</br><span style=’font-weight: bold;’>Grand Total: " .$dollars. "</span>";
?>
how to read excel file (.xls) format with php?
I’m new to php programming,
i search yahoo and google for this solution but all i found was a class to read the excel but with a crappy documentation or example.
right now i’m learning excellreader from sourceforge.net and MS-Excel Stream Handler from phpclasses.org, but i’m still confuse because lack of example and documentary. so i don’t know how to play much with the offered variable
is there any alternative beside this two solution that i get, which is free or open source?
or could someone tell me any website that help me to solve this problem?
thx b4
If you can Administer your server, try installing PEAR Package or ask your service providers administrator if they can install PEAR.
PEAR is easy to use because they are already CLASSES. You don’t need to read the entire class, all you need to do is a 2 or 5 lines of code to retrieve it.
Good book to learn php (Mainly for editing phpbb and developing programs to work with it.)?
I plan on messing with php, mainly because I want to help with a game server. Mainly website design, development, and to maintain it. I plan on using phpbb, but I have no programming knowledge, I want to be able to mod the heck out of phpbb, I would like to be able to change/add quite a few things. I would also like to make my own programs to run with it. I’m looking at a program that manages support tickets, which a user can sumbit one when they go to the correct webpage of the site if they have logged into the phpbb forum, another one that manages donations, IE, tracks would gave them, how much, sends emails with a generated link to confirm after pay has been done via paypal, let them monitor their donation credits, etc. I was looking at "head first into php" will this book teach me how to do these things? Any other recommendations, books to read with that one, etc? All help aprecaited, thanks.
PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide by Larry Ullman
I Need Help with PHP code…
hi all…please solve my simple problem…actually im making a php script for my web page and its not working….how would you make it if you have to enter two different words saperately in a text box and press submit using get method..and as a result, saperate page opens for saperate word….for example,if i enter YES in a text box and press submit, it opens page-1….then i go back ….and if i enter NO..then it opens page-2….
what would be the simplest php programming for that???
yes i can see that code but what code you put in if{} then(????) i mean code in php (if then) statement about page location???
<?php
if ($_GET['val']) {
if($_GET['val'] == "yes") {
//do this if it was yes(DO WHAT? WHAT IS THE CODE FOR MOVING TO PAGE-1)
} else {
//do this if it wasn’t yes(DO WHAT? WHAT IS THE CODE FOR MOVING TO PAGE-2)
}
is there any command like (goto) in php??
There are many ways to accomplish what you mentioned. Here is one of them:
Create a redirect page
This page can be called anything, e.g. redirect.php
<?php
$whereto = $_GET[ 'whereto' ];
switch( $whereto )
{
case "yes":
header( "Location: page1.html" );
exit( 0 );
case "no":
header( "Location: page2.html" );
exit( 0 );
case "yada":
header( "Location: yada.html" );
exit( 0 );
default:
header( "Location: error-bad-choice.html" );
exit( 0 );
}
?>
On the page where user has to enter yes/no/whatever, create a form with method=get and action=redirect.php
Making an inventory system with PHP?
Hi! How do I make a good interface with PHP? I’m kind of new to the language. Can I make one like the Java stand-alone program (with all the buttons and forms) only it’s web based and its PHP?
Yes, I know. I already have MySQL working. My question is, how do I make a nice interface to run with it? Are there templates available for this? The only HTML templates I’ve seen are web templates.
PHP is a server side script. Which means you need a webserver with PHP enabled to develop PHP sites. Great PHP enabled servers are the XAMPP project from ApacheFriends.
This is a bundle of applications that instantly enables your computer with Apache Webserver, PHP 4/5 script support, MySQL 4/5 database support, FTP server, POP3/SMTP server and other stuff like Perl etc.
To code in PHP, all you need is Notepad. Its convenient to have a PHP Editor though. PHP program pages have a .PHP extension.
To run a PHP program, just copy it to a folder on the webserver hosting directory and call it in the browser. For ex: if your webserver root is c:\web\root, you can dump the PHP file in c:\web\root\myprograms. To call the page in browser, just goto http://localhost/myprograms/myprogram.php
HTH
Do you have to be good at math to program with Php?
If you do I’ll have to look for a new career.
Seriously, the most difficult "math" I ever used in writing code was some formulas. If you’re writing PHP to calculate something like a Fourier transform, of course you have to know how to do it before you can write code to do it. But for general programming, you’ll probably be using 4th grade arithmetic.
How do you make a login system with PHP?
Please, no MySQL, I would like this to be connected to a txt file- I know this is less secure, but I don’t know MySQL at all, and I know there is a way to create a login system with just a txt file.
PS
An explanation of the code would be good as well, because I am not a great programmer (I am an eighth grader who took a two week course on java and php programming).
Download the free "Login script" from http://www.web2coders.com
It is more complete than the one described above, and it is commented.
PHP Programming Help!?
Ok, I’m doing an assignment for school that is really confusing me. I made an htm form that is supposed to leave a box for you to enter a grade letter, and after doing so, you will get a different result depending on the letter you typed. I made the PHP file, but no matter what grade I type, it gives me the same result every time, "Your grade is excellent!". I need help with making it give me different results depending on what I type, and I think the main problem is my call statement.
This is my html form (which is fine):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Letter Grades</title>
</head>
<body>
<form action="LetterGrades.php" method="get">
<p>Grade: <input type="text" name="Grade" />
<input name="Submit" type="submit" id="Submit" />
</p>
</form>
</body>
</html>
And this is my PHP file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Letter Grades</title>
</head>
<body>
<?php
function checkGrade($Grade) {
switch ($Grade) {
case "A":
echo "Your grade is excellent.";
break;
case "B":
echo "Your grade is good.";
break;
case "C":
echo "Your grade is fair.";
case "D":
echo "You are barely passing.";
case "F":
echo "You failed.";
default:
echo "You did not enter a valid letter grade.";
}
}
echo checkGrade("A");
?>
</body>
</html>
Could someone please help me?
Thanks, Frank! I think it’s a step in the right direction, but the only problem now is that it’s giving me the default answer everytime now, which is, "You did not enter a valid letter grade."
Do I need to define the A, B, C, D, F variables anywhere?
Ok, it works now, thank you, Frank!!! ![]()
I think you wrote a good script. The problem with this script i think will be at the last statement (echo checkGrade("A");).
Instead of you writing echo checkGrade("A"); I suggest you write
echo checkGrade("$Grade");
Ooh plus you haven’t linked the form with the php script
write something like:
<?php
function checkGrade($Grade) {
$Grade = $_GET['Grade'];
switch ($Grade) {
case "A":
echo "Your grade is excellent.";
break;
case "B":
echo "Your grade is good.";
break;
case "C":
echo "Your grade is fair.";
case "D":
echo "You are barely passing.";
case "F":
echo "You failed.";
default:
echo "You did not enter a valid letter grade.";
}
}
echo checkGrade("$Grade");
?>