PHP

bayans Messages postés 14 Date d'inscription mardi 17 novembre 2009 Statut Membre Dernière intervention 2 décembre 2012 - 1 déc. 2010 à 17:16
bodo2011 Messages postés 9 Date d'inscription mardi 25 janvier 2011 Statut Membre Dernière intervention 11 juin 2012 - 3 févr. 2011 à 14:28
Je n’avais jamais entendu parler de PHP jusqu’a ce que mon professeur en parle. Un travail nous a déjà était donne par mon professeur mais mon code me donne toujours les même erreurs et je ne sais pas du tout quoi faire même si je suis les instructions qui m’on était donne. Voici le code et que j’ai écrit ci-dessous ainsi que les erreurs que je ne cesse d’avoir. Les erreurs ceux trouvent a la fin du code.

1:<hmtl>
2:<head>
3:<title> Order confirmation</title>
4:
5: Your order has been successfully confirmed

6:<marquee>Thank you!!!!</marquee>

<?php
$suitqty = $HTTP_POST_VARS['suitqty']; //These are a new variables
$shoeqty = $HTTP_POST_VARS['shoeqty'];
$jacketqty=$HTTP_POST_VARS['jacketqty'];
$beltqty = $HTTP_POST_VARS['beltqty'];
$waistcoatqty = $HTTP_POST_VARS['waistcoatqty'];
$address = $HTTP_POST_VARS['address'];
?>

<?php
echo ' Order processed at'; // I passed string to the date function and it will display the time, date and month of the customer's order
echo date('H:i, jS F');
echo '

';

echo'Your order is as follows:

'; //The customer will be able to see the items that he/she order
echo $suitqty.'suits
';
echo $shoeqty.'shoes
';
echo $jacketqty.'jackets
';
echo $beltqty .'belts
';
echo $waistcoatqty .'waistcoat
';
echo 'Customer Address: '.$address. '
';

$totalqty = 0; // I assigned a values to those variables
$totalqty = $suitqty + $shoeqty + $jacketqty + $beltqty + $waistcoatqty;//The totalqty variable will calculate the total number of items
echo 'Items ordered: '.$totalqty.'
'; //It will display the total amount

if( $totalqty ==0 ) //The condition will be true if $totalqty is equal to zero,
{
echo'';
echo'You did not order anything on the previous page!
';
echo'';
exit;// It stops PHP from executing remainder of the script
}
else
{
if ( $suitqty < 0 )
$discount = 0;

elseif ( $suitqty >= 5 && $suitqty <= 10 )
$discount = 5;

elseif ( $suitqty >= 15 && $suitqty <= 20 )
$discount = 10;

if ( $shoeqty <0 )
$discount = 0;

elseif ( $shoeqty >= 5 && $shoeqty <= 10 )
$discount = 5;

elseif ( $shoeqty >= 15 && $shoeqty <= 20 )
$discount = 10;


if ( $jacketqty<0 )
$discount = 0;

elseif ( $jacketqty >= 5 && $jacketqty <= 10 )
$discount = 5;

elseif ( $jacketqty >= 15 && $jacketqty <= 20 )
$discount = 10;


if ( $beltqty<0 )
$discount = 0;

elseif ( $beltqty >= 5 && $beltqty <= 10 )
$discount = 5;

elseif ( $beltqty >= 15 && $beltqty <= 20 )
$discount = 10;


if ( $waistcoatqty < 0 )
$discount = 0;

elseif ( $waistcoatqty >= 5 && $waistcoatqty <= 10 )
$discount = 5;

elseif ( $waistcoatqty >= 15 && $waistcoatqty <= 20 )
$discount = 10;
}

if (isset($discount)){
echo "you will get\t" , $discount , " % off your order";
}

$totalamount = 0.00;

define('SUITPRICE', 150); // I define constants using the define function and I stored the price for each item
define;
define('SHOEPRICE', 60);
define('JACKETPRICE', 20);
define('BELTPRICE', 20);
define('WAISTCOATPRICE', 35);

$totalamount = $suitqty * SUITPRICE
+$shoeqty * SHOEPRICE
+$jacketqty * JACKETPRICE;
+$beltqty * BELTPRICE;
+$waistcoatqty * WAISTCOATPRICE;

echo'Subtotal: £'.number_format($totalamount,2).'
';

$taxrate = 0.10;
$totalamount = $totalamount * (1 + $taxrate);
echo'Total including tax: £'.number_format($totalamount,2).'
';

switch($find)
{
case 'a' :
echo 'This customer is regular.

';
break;
case 'b' :
echo 'Customer referred by TV ad.

';
break;
case 'c' :
echo 'Customer referred by News paper.

';
break;
case 'd' :
echo 'Customer referred by Lecture notes.

';
break;
case 'e' :
echo 'This customer never heard about Maxwell & Son.

';
break;
}
?>

Distance,
Cost,

<?php
$distance = 50;
while ($distance <= 250 )
{
echo \"----
\n $distance, \n\";
echo \" ". $distance / 10
.", \n\n\";
$distance +=50;
}
?>


<?php
$myfile = fopen('orders.txt', 'a');
if (!$myfile)
flock($myfile, LOCK_EX); //Lock the file for writing
$outputstring = date('H:i jS F'). "|\t Suit: ".$suitqty." |\t Shoe: ".$shoeqty."|\t Jacket: ".$jacketqty." |\t Belt: ".$belt."|\t Waistcoat: ".$waistcoatqty." \n";
fwrite($myfile, $outputstring);
flock($myfile, LOCK_UN); // Release write lock
fclose($myfile);
if (!$myfile)
{
echo ' Your order could not be processed at this time. Please try again later.

';
exit;
}
echo '

';
?>

</html>
</head>


Erreurs:

Warning: fopen(orders.txt) [function.fopen]: failed to open stream: Permission denied in /u2.bristol/s09/abkh536/public_html/ee2505/processorder.php on line 164

Warning: flock() expects parameter 1 to be resource, boolean given in /u2.bristol/s09/abkh536/public_html/ee2505/processorder.php on line 166

Warning: fwrite(): supplied argument is not a valid stream resource in /u2.bristol/s09/abkh536/public_html/ee2505/processorder.php on line 168

Warning: flock() expects parameter 1 to be resource, boolean given in /u2.bristol/s09/abkh536/public_html/ee2505/processorder.php on line 169

Warning: fclose(): supplied argument is not a valid stream resource in /u2.bristol/s09/abkh536/public_html/ee2505/processorder.php on line 170

3 réponses

cod57 Messages postés 1653 Date d'inscription dimanche 7 septembre 2008 Statut Membre Dernière intervention 11 septembre 2013 19
1 déc. 2010 à 19:13
bonsoir
a++

$HTTP_POST_VARS n'est plus utilisé en php5


1:<hmtl>
2:<head>
3:<title> Order confirmation</title>
4:
5: Your order has been successfully confirmed

6:<marquee>Thank you!!!!</marquee>

<?php

/*$suitqty = $HTTP_POST_VARS['suitqty']; //These are a new variables
$shoeqty = $HTTP_POST_VARS['shoeqty'];
$jacketqty=$HTTP_POST_VARS['jacketqty'];
$beltqty = $HTTP_POST_VARS['beltqty'];
$waistcoatqty = $HTTP_POST_VARS['waistcoatqty'];
$address = $HTTP_POST_VARS['address']; */


if(isset($_POST['suitqty'],$_POST['shoeqty'],$_POST['jacketqty'],$_POST['beltqty'],$_POST['waistcoatqty'],$_POST['address'])){
$suitqty = $_POST['suitqty']; //These are a new variables
$shoeqty = $_POST['shoeqty'];
$jacketqty=$_POST['jacketqty'];
$beltqty = $_POST['beltqty'];
$waistcoatqty = $_POST['waistcoatqty'];
$address = $_POST['address'];
} else {
$suitqty = "";//These are a new variables
$shoeqty = "";
$jacketqty="";
$beltqty = "";
$waistcoatqty = "";
$address ="";
}
?>

<?php
echo ' Order processed at'; // I passed string to the date function and it will display the time, date and month of the customer's order
echo date('H:i, jS F');
echo '

';

echo'Your order is as follows:

'; //The customer will be able to see the items that he/she order
echo $suitqty.'suits
';
echo $shoeqty.'shoes
';
echo $jacketqty.'jackets
';
echo $beltqty .'belts
';
echo $waistcoatqty .'waistcoat
';
echo 'Customer Address: '.$address. '
';

$totalqty = 0; // I assigned a values to those variables
$totalqty = $suitqty + $shoeqty + $jacketqty + $beltqty + $waistcoatqty;//The totalqty variable will calculate the total number of items
echo 'Items ordered: '.$totalqty.'
'; //It will display the total amount

if( $totalqty ==0 ) //The condition will be true if $totalqty is equal to zero,
{
echo'';
echo'You did not order anything on the previous page!
';
echo'';
exit;// It stops PHP from executing remainder of the script
}
else
{
if ( $suitqty < 0 )
$discount = 0;

elseif ( $suitqty >= 5 && $suitqty <= 10 )
$discount = 5;

elseif ( $suitqty >= 15 && $suitqty <= 20 )
$discount = 10;

if ( $shoeqty <0 )
$discount = 0;

elseif ( $shoeqty >= 5 && $shoeqty <= 10 )
$discount = 5;

elseif ( $shoeqty >= 15 && $shoeqty <= 20 )
$discount = 10;


if ( $jacketqty<0 )
$discount = 0;

elseif ( $jacketqty >= 5 && $jacketqty <= 10 )
$discount = 5;

elseif ( $jacketqty >= 15 && $jacketqty <= 20 )
$discount = 10;


if ( $beltqty<0 )
$discount = 0;

elseif ( $beltqty >= 5 && $beltqty <= 10 )
$discount = 5;

elseif ( $beltqty >= 15 && $beltqty <= 20 )
$discount = 10;


if ( $waistcoatqty < 0 )
$discount = 0;

elseif ( $waistcoatqty >= 5 && $waistcoatqty <= 10 )
$discount = 5;

elseif ( $waistcoatqty >= 15 && $waistcoatqty <= 20 )
$discount = 10;
}

if (isset($discount)){
echo "you will get\t" , $discount , " % off your order";
}

$totalamount = 0.00;

define('SUITPRICE', 150); // I define constants using the define function and I stored the price for each item
define;
define('SHOEPRICE', 60);
define('JACKETPRICE', 20);
define('BELTPRICE', 20);
define('WAISTCOATPRICE', 35);

$totalamount = $suitqty * SUITPRICE
+$shoeqty * SHOEPRICE
+$jacketqty * JACKETPRICE;
+$beltqty * BELTPRICE;
+$waistcoatqty * WAISTCOATPRICE;

echo'Subtotal: £'.number_format($totalamount,2).'
';

$taxrate = 0.10;
$totalamount = $totalamount * (1 + $taxrate);
echo'Total including tax: £'.number_format($totalamount,2).'
';

switch($find)
{
case 'a' :
echo 'This customer is regular.

';
break;
case 'b' :
echo 'Customer referred by TV ad.

';
break;
case 'c' :
echo 'Customer referred by News paper.

';
break;
case 'd' :
echo 'Customer referred by Lecture notes.

';
break;
case 'e' :
echo 'This customer never heard about Maxwell & Son.

';
break;
}
?>

Distance,
Cost,

<?php
$distance = 50;
while ($distance <= 250 )
{
echo \"----
\n $distance, \n\";
echo \" ". $distance / 10
.", \n\n\";
$distance +=50;
}
?>


<?php
$myfile = fopen('orders.txt', 'a');
if (!$myfile)
flock($myfile, LOCK_EX); //Lock the file for writing
$outputstring = date('H:i jS F'). "|\t Suit: ".$suitqty." |\t Shoe: ".$shoeqty."|\t Jacket: ".$jacketqty." |\t Belt: ".$belt."|\t Waistcoat: ".$waistcoatqty." \n";
fwrite($myfile, $outputstring);
flock($myfile, LOCK_UN); // Release write lock
fclose($myfile);
if (!$myfile)
{
echo ' Your order could not be processed at this time. Please try again later.

';
exit;
}
echo '

';
?>

</html>
</head>
0
kohntark Messages postés 3705 Date d'inscription lundi 5 juillet 2004 Statut Membre Dernière intervention 27 avril 2012 30
2 déc. 2010 à 10:11
encore et toujours à filer du code tout fait qui ne sera dans 95% des cas pas pédagogique ... et qui ne règle en rien le problème.

L'erreur le dit clairement : le script PHP n'a pas la permission d'ouvrir le fichier orders.txt

Cordialement,


Kohntark -
0
bodo2011 Messages postés 9 Date d'inscription mardi 25 janvier 2011 Statut Membre Dernière intervention 11 juin 2012
3 févr. 2011 à 14:28
je vous demande de l'aide car je veux que ma page ne se dilate pas en enlevant un contenu dans cette page
0
Rejoignez-nous