Jump to content

php bugs please help


orealeye

Recommended Posts

Hello,I am following books trying to learn php...sometimes it works, sometimes no....I have got this error on all my pagesthe web page shows 戼䌾尺灡捡敨桜摴捯屳牏慥Here the code for example : <?php include("maboutique.php"); include("vars.php"); Init_boutique(); $mypanier =new panier; $aujourdhui=date("z"); $auj="DELETE FROM visiteur WHERE NbreDate < $aujourdhui-$keep_time"; $result=mysql_query("$auj") or die ("requete impossible");$req = "SELECT NumdansPanier,Date FROM panier"; $result=mysql_query("$req"); $mypanier->getnum($result); while ($mypanier->z <$mypanier->num) { $mypanier->readrow($result); $WNumDansPanier=$mypanier->NumDansPanier; $WDate=$mypanier->Date; if($WDate<$aujourdhui-$keep_time) { mysql("$db","DELETE FROM panier WHERE NumDansPanier ='$WNumDansPanier'"); } } if ($C_ID) { $Identifiant= $C_ID; } $Identifiant=get_id($Identifiant); Header("Location: $Base_R/selection_groupe.php?Identifiant=$Identifiant");?>I don't understand....please help !!!The html shows :<?phpfunction Connect_to_db($vars.inc){ include($vars.inc); $cxn=mysqli_connect($host,$user,$password) or die ("connexion au serveur impossible");$db=mysqli_select_db($database,$cxn) or die ("la base de données ne peut pas etre selectionnée");return $cxn;?>????????????†???????›???????????????????????????????????????????????????????????????????????????†???›????????????????????????????????????????????????????????????????????????????????????????

Link to comment
Share on other sites

You probably have this on a Japanese server showing Japanese error messages.I'm not sure what the specific problem is, but this is definately wrong:

<?phpfunction Connect_to_db($vars.inc){include($vars.inc);$cxn=mysqli_connect($host,$user,$password) or die ("connexion au serveur impossible");$db=mysqli_select_db($database,$cxn) or die ("la base de données ne peut pas etre selectionnée");return $cxn;?>

For one, you can't have a parameter called "$vars.inc". Periods are not allowed in variable names. Just call it $vars, or $include or something. If the variable contains the entire filename, then you can do this:include ($vars);Or, if you need to add a .inc extension or something, you can do this:include ($vars . ".inc");BTW, .inc is not a good extension to use for PHP includes. They should end in .php. If you want, you can call it .inc.php to indicate an include file, but it should end in .php. Such as functions.inc.php.Next. In this line:$cxn=mysqli_connect($host,$user,$password) or die ("connexion au serveur impossible");The $host, $user, and $password variables have not been declared or initialized in the function scope. If you want to use the global versions of those variables, you need to say so:global $host, $user, $password;$cxn=mysqli_connect($host,$user,$password) or die ("connexion au serveur impossible");The same thing goes for the $database variable you use on the next line. And there's no point to saving the return value into a $db variable, because you don't use the $db variable for anything.Finally, the function never ends. After the return statement, there is no closing }, so that will be a parse error and the file won't run at all.

Link to comment
Share on other sites

Thank you for your answer...I have replace the original file (I wanted to include the connextion to the db fr easiest use). But I don't understand it still doesn't want to connect to the base or It is the right user and there is no password. ( or it says using password = yes ?)Warning: mysql_connect(): Access denied for user: 'root@localhost' (Using password: YES) in c:\program files\easyphp1-8\www\orealeye-boutique\entree.php on line 5requete impossiblethe code : (can it be the path to $base and $base_R ?...thank you ...<?php$societe="***";$rue="**";$ville="**";$pays="**";$codepostal=""**;$http ="localhost";$TVA=19.6/100;$host="localhost";$user="root";$password=" "; $keep_time=30;$keep = FALSE;$ssl = 0;$ssl_host="https://myhost.fr";$Base="C:\Program Files\EasyPHP1-8\www";$Base_R="/Orealeye-boutique";$Server="localhost";$Chbl="#6699FF";$Cdbl="#0000A0";$blk="#000000";$red="#FF0000";/*desigantions et menus*/$w=array("Cat"=>"Catalogue","Basquet"=>"Panier","Order"=>"Commande","Entry"=>"entrée","Exit"=>"Sortie","ArtNr"=>"NumArt","Art"=>"Article","Number"=>"Quantité","Price"=>"Prix","Tax"=>"TVA","Sum"=>"Montant","Total"=>"Total TTC");?>

Link to comment
Share on other sites

another code which gives 㸯㰊㹢潎楴 (and I don't think it is because of japonese because I also got the errors : 'parse error ...and so on....<?phpinclude_once("functions_main.inc");$page = array( "title" => "Page d'identification", "top" => "", "bottom" => "Envoyez vos questions et commentaires à admin@mondomaine.com", );$elements_1 = array( "top" => "Déjà inscrit : <span style=\"font-size: 80%; font-weight: 100%\"> <i>Identification</i></span>", "bottom" => "", "submit" => "Identification" );$elements_2 = array("top" => "Nouveaux-venus: <span style=\"font-size: 80%; font-weight: 100%\"> <i>Inscrivez-vous</i></span>", "bottom" => "", "submit" => "Inscription" );$fields_1 = array("fusername" => "Nom utilisateur", "fpassword" => "Mot de passe" );$length_1 = array("fusername" => "10", "fpassword" => "10" );$fields_2 = array("user_name" => "Nom utilisateur", "password" => "Mot de passe", "email" => "Adresse électronique", "first_name" => "Prénom", "last_name" => "Nom", "dept_id" => "Service" );$length_2 = array("user_name" => "20", "password" => "8", "email" => "55", "first_name" => "40", "last_name" => "40", "dept_id" =>"40" );$options = array();$connection = Connect_to_db("vars.inc");$results = mysql_query($connection, "SELECT dept_id, name FROM Department ORDER BY name");while($row = mysql_fetch_assoc($results)) { $options['dept_id'][$row['dept_id']] = $row['name'];}?>this is a code from a book for beginners...?!! without any change ...thanks ..

Link to comment
Share on other sites

$host="localhost";$user="root";$password=" ";

Check and see if there is a 'space' in the password variable, because it may be that the 'space' is different than 'null' or empty, so double-check the actual passord value for this user.Also, it is a really bad idea to use 'root' as the database user. I hope you understand the risks and change the user for this application.

Link to comment
Share on other sites

thanks ...it was the space....and I use root only on my computer....I ve got other pb may you can help...with try / catchI have a parse error : Parse error: parse error in c:\program files\easyphp1-8\www\phpmysql\chap13\oo\login-oo.php on line 19ligne 19 where the try starts....thanks :) here the code :<?php /* Programme : Login-OO.php * Description : Script d'application d'identification * d'utilisateur. Le programme affiche la * page Web d'identification. Les informations * d'inscription d'un nouvel utilisateur sont * validées et stockées dans une base de * données. Le mot de passe d'un client existant * est comparé au mot de passe valide stocké * dans la base de données. */require_once("WebForm.class"); #9require_once("Account.class");require_once("Database.class");require_once("Session.class");require_once("Email.class");try{ $form = new WebForm("double_form.inc","fields_login.inc",$_POST);}catch(Exception $e){ echo $e->getMessage(); exit();}//Le formulaire est affiché pour la première fois, vierge.//if (!isset($_POST['Button'])) #26{ $form->displayForm(); exit();}// Traite le formumaire qui a été soumis avec des infos utilisateur //else #32{ $sess = new Session(); #34 try { $db = new Database("Vars.inc"); #37 $db->useDatabase("CustomerDirectory"); #38 $acct = new Account($db->getConnection(),"Customer"); } catch(Exception $e) { echo $e->getMessage()."\n<br>"; exit(); } // Le formulaire d'identification a été soumis // if (@$_POST['Button'] == "Identification") #48 { try { $blanks = $form->checkForBlanks(); #52 } catch(Exception $e) { echo $e->getMessage(); exit(); } if(is_array($blanks)) #59 { $GLOBALS['message_1'] = "User name or Password was blank. Please enter both."; $form->displayForm(); exit(); } try { if(!$acct->selectAccount($_POST['fusername'])) #69 { $GLOBALS['message_1'] = $acct->getMessage(). " Réessayez."; $form->displayForm(); exit(); } if(!$sess->login($acct,$_POST['fpassword'])) #76 { $GLOBALS['message_1'] = $acct->getMessage(). " Réessayez."; $form->displayForm(); exit(); } header("Location: SecretPage.php"); #83 exit(); } catch(Exception $e) { echo $e->getMessage(); } } // Le formulaire d'inscription a été soumis // elseif($_POST['Button'] = "Inscription") #93 { $not_required[] = "fax"; #95 try { $form->setFieldsNotRequired($not_required); #98 $blanks = $form->checkForBlanks(); #99 } catch(Exception $e) { echo $e->getMessage(); } if(is_array($blanks)) #105 { $GLOBALS['message_2'] = "Les champs obligatoires suivants sont vierges. Merci de saisir les informations obligatoires : "; foreach($blanks as $value) { $GLOBALS['message_2'] .="$value, "; } $form->displayform(); exit(); } $form->trimData(); #117 $form->stripTagsFromData(); #118 try { $errors = $form->verifyData(); #121 } catch(Exception $e) { echo $e->getMessage(); } if(is_array($errors)) #127 { $GLOBALS['message_2'] = ""; foreach($errors as $value) { $GLOBALS['message_2'] .="$value<br> "; } $form->displayform(); exit(); } $newdata = $form->getAllFields(); #137 try { if($acct->selectAccount($newdata['user_name'])) #140 { $GLOBALS['message_2'] = "Nom d'utilisateur déjà utilisé. Choisissez-en un autre."; $form->displayForm(); exit(); } if(!$acct->createNewAccount($newdata)) #148 { echo "Impossible de créer le nouveau compte. Réessayez."; exit(); } $sess->storeVariable("auth","yes"); #154 $sess->storeVariable("logname",$newdata['user_name']); $em = new Email(); #156 $em->setAddr($newdata['email']); $em->setSubj("Votre inscription client"); $emess = "Votre inscription s'est correctement déroulée."; $emess .= " Vos nom d'utilisateur et mot de passe sont : "; $emess .= "\n\n\t{$newdata['user_name']}\n\t"; $emess .= "{$newdata['password']}\n\n"; $emess .= "Si vous avez des questions ou problèmes,"; $emess .= " écrivez à service@notreboutique.com"; $em->setMessage($emess); #$em->sendEmail(); #167 } catch(Exception $e) { echo $e->getMessage(); exit(); } header("Location: SecretPage.php"); }}?>

Link to comment
Share on other sites

Remove the line break on line 19 after the $form = , it should all be on one line.Also, about the other parse error, this code is wrong:

$page = array( "title" => "Page d'identification","top" => "","bottom" => "Envoyez vos questions et commentairesà admin@mondomaine.com",);

There is a comma at the end that shouldn't be there.

Link to comment
Share on other sites

the parse error is on the loginOO.php. Ii si on line just under the first try...even with the $form ..on one line...it doesn't change....Thanks<?php /* Programme : Login-OO.php * Description : Script d'application d'identification * d'utilisateur. Le programme affiche la * page Web d'identification. Les informations * d'inscription d'un nouvel utilisateur sont * validées et stockées dans une base de * données. Le mot de passe d'un client existant * est comparé au mot de passe valide stocké * dans la base de données. */require_once("WebForm.class"); #9require_once("Account.class");require_once("Database.class");require_once("Session.class");require_once("Email.class");try #15{ $form = new WebForm("double_form.inc","fields_login.inc",$_POST);}catch(Exception $e){ echo $e->getMessage(); exit();}//Le formulaire est affiché pour la première fois, vierge.//if (!isset($_POST['Button'])) #26{ $form->displayForm(); exit();}// Traite le formumaire qui a été soumis avec des infos utilisateur //else #32{ $sess = new Session(); #34 try { $db = new Database("Vars.inc"); #37 $db->useDatabase("intranetcms"); #38 $acct = new Account($db->getConnection(),"Dept_User"); } catch(Exception $e) { echo $e->getMessage()."\n<br>"; exit(); } // Le formulaire d'identification a été soumis // if (@$_POST['Button'] == "Identification") #48 { try { $blanks = $form->checkForBlanks(); #52 } catch(Exception $e) { echo $e->getMessage(); exit(); } if(is_array($blanks)) #59 { $GLOBALS['message_1'] = "Le nom d'utilisateur ou le mot de passe. est vierge. Saisissez les deux informations."; $form->displayForm(); exit(); } try { if(!$acct->selectAccount($_POST['fusername'])) #69 { $GLOBALS['message_1'] = $acct->getMessage(). " Réessayez."; $form->displayForm(); exit(); } if(!$sess->login($acct,$_POST['fpassword'])) #76 { $GLOBALS['message_1'] = $acct->getMessage(). " Réessayez."; $form->displayForm(); exit(); } header("Location: CompanyHome-OO.php"); #83 exit(); } catch(Exception $e) { echo $e->getMessage(); } } // Le formulaire d'inscription a été soumis // elseif($_POST['Button'] = "Inscription") #93 { $not_required[] = "fax"; #95 try { $form->setFieldsNotRequired($not_required); #98 $blanks = $form->checkForBlanks(); #99 } catch(Exception $e) { echo $e->getMessage(); } if(is_array($blanks)) #105 { $GLOBALS['message_2'] = "Les champs obligatoires suivants sont vierges. Merci de saisir les informations obligatoires : "; foreach($blanks as $value) { $GLOBALS['message_2'] .="$value, "; } $form->displayform(); exit(); } $form->trimData(); #117 $form->stripTagsFromData(); #118 try { $errors = $form->verifyData(); #121 } catch(Exception $e) { echo $e->getMessage(); } if(is_array($errors)) #127 { $GLOBALS['message_2'] = ""; foreach($errors as $value) { $GLOBALS['message_2'] .="$value<br> "; } $form->displayform(); exit(); } $newdata = $form->getAllFields(); #137 try { if($acct->selectAccount($newdata['user_name'])) #140 { $GLOBALS['message_2'] = "Nom d'utilisateur déjà utilisé. Choisissez-en un autre."; $form->displayForm(); exit(); } if(!$acct->createNewAccount($newdata)) #148 { echo "Impossible de créer le nouveau compte. Réessayez."; exit(); } $sess->storeVariable("user_name",$newdata['user_name']); #154 $sess->storeVariable("user_dept",$newdata['dept_id']); $em = new Email(); #156 $em->setAddr($newdata['email']); $em->setSubj("Votre inscription client"); $emess = "Votre inscription s'est correctement déroulée."; $emess .= " Vos nom d'utilisateur et mot de passe sont : "; $emess .= "\n\n\t{$newdata['user_name']}\n\t"; $emess .= "{$newdata['password']}\n\n"; $emess .= "Si vous avez des questions ou problèmes,"; $emess .= " écrivez à service@notreboutique.com"; $em->setMessage($emess); #$em->sendEmail(); #167 } catch(Exception $e) { echo $e->getMessage(); exit(); } header("Location: CompanyHome-OO.php"); }}?>

Link to comment
Share on other sites

I replace :try{ $form =new WebForm("double_form.inc","fields_login.inc",$_POST);}catch(Exception $e){echo $e->getMessage();exit();}by :if ($form = new WebForm("double_form.inc","fields_login.inc",$_POST)){ echo $e->getMessage(); exit();}and it seems to work (no parse error but I don't know if it worksWith what can I replace : try { $db = new Database("Vars.inc"); #37 $db->useDatabase("intranetcms"); #38 $acct = new Account($db->getConnection(),"Dept_User"); } catch(Exception $e) { echo $e->getMessage()."\n<br>"; exit(); }Thanks...and this one pleasetry { if(!$acct->selectAccount($_POST['fusername'])) #69 { $GLOBALS['message_1'] = $acct->getMessage(). " Réessayez."; $form->displayForm(); exit(); } if(!$sess->login($acct,$_POST['fpassword'])) #76 { $GLOBALS['message_1'] = $acct->getMessage(). " Réessayez."; $form->displayForm(); exit(); } header("Location: CompanyHome-OO.php"); #83 exit(); } catch(Exception $e) { echo $e->getMessage(); }

Link to comment
Share on other sites

Whenever you are creating a class, you can put it in an if statement to check if it got created. An object with no properties or methods will evaluate to false.

if (!$db = new Database("Vars.inc")){  echo "Database class could not be created";  exit();}

Other then that, you will probably want to put the error handling inside the class itself rather then doing error checking every time to call a member of the class.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...