8791 sujets

Développement web côté serveur, CMS

Je tente vainement de construire le code suivant:

if (condition1)
alors echo "message d'erreur1"
if (condition2)
alors echo "message d'erreur2"
if (condition3)
alors echo "message d'erreur3"
sinon echo "message de réussite"

Je ne souhaite montrer qu'un seul message d'erreur donc si cond1=OK, 2 et 3 échouent, seul le message 2 doit apparaître et ainsi de suite.

Voilà où je suis rendu
$css = !file_exists('styleinstall.css');
$spryjs = !file_exists('js/SpryValidationTextField.js');
$install = !file_exists('install.php');
$installation = !file_exists('installation.php');
$configfile = '../config.php';
$configfilesample = '../config-sample.php';
$installationmessage = '<h2>Follow the instructions to install Wordpress.</h2><p>The file <code>config.php</code> does not exist. I need this before we can get started. You can create a <code>config.php</code> file through a web interface, but this does not work for all server setups. The safest way is to manually create the file.</p><a href="install.php" class="button">Create a configuration file</a>';

//Testing the absence of config.php
if (file_exists($configfile)) {
		echo '<p class="warning">The file <code>config.php</code> exists and I cannot override it. The system may already be installed. If you wish to reinstall then remove the file <code>config.php</code> and refresh the page.</p>'; '<p class="warning">The file <code>config-sample.php</code> does not exist. Upload a copy from the original package and refresh the page.</p>';
	
	//Testing the presence of config-sample.php
	if (!file_exists($configfilesample)) {
		echo '<p class="warning">The file <code>config-sample.php</code> does not exist. Upload a copy from the original package and refresh the page.</p>';
		// Testing the presence of all the required files
		if ($css || $spryjs || $install || $installation) {
			echo '<p class="warning">A few required files are missing. Upload the <code>install</code> folder from a fresh copy and refresh the page.</p>';

}
}
}
else {
 echo $installationmessage;
}

Modifié par olimart (13 Dec 2010 - 20:21)
Salut Smiley cligne

C'est simple !

if (condition1)
alors echo "message d'erreur1"
elseif (condition2)
alors echo "message d'erreur2"
elseif (condition3)
alors echo "message d'erreur3"
else
alors echo "message de réussite"

Sinon, en code ça donne ceci :

//Testing the absence of config.php 
if (file_exists($configfile)) { 
        echo '<p class="warning">The file <code>config.php</code> exists and I cannot override it. The system may already be installed. If you wish to reinstall then remove the file <code>config.php</code> and refresh the page.</p>'; '<p class="warning">The file <code>config-sample.php</code> does not exist. Upload a copy from the original package and refresh the page.</p>'; 
}
     
    //Testing the presence of config-sample.php 
    elseif (!file_exists($configfilesample)) { 
        echo '<p class="warning">The file <code>config-sample.php</code> does not exist. Upload a copy from the original package and refresh the page.</p>'; 
}
        // Testing the presence of all the required files 
        elseif ($css || $spryjs || $install || $installation) { 
            echo '<p class="warning">A few required files are missing. Upload the <code>install</code> folder from a fresh copy and refresh the page.</p>'; 
} 
else { 
 echo $installationmessage; 
}
Salut,

comme tu dis c'est simple. je ne comprends même pas que je n'ai pas réussi à le faire fonctionner. C'était sous mes yeux.

Sinon j'ai un peu plus compliqué Smiley cligne si tu recherches un "challenge" un tantinet plus élevé
http://forum.alsacreations.com/topic-20-52644-1-Multiple-conditions-et-logique-PHP.html#p364027

Super_baloo8 a écrit :
Salut Smiley cligne

C'est simple !

if (condition1)
alors echo &quot;message d'erreur1&quot;
elseif (condition2)
alors echo &quot;message d'erreur2&quot;
elseif (condition3)
alors echo &quot;message d'erreur3&quot;
else
alors echo &quot;message de réussite&quot;

Sinon, en code ça donne ceci :

//Testing the absence of config.php 
if (file_exists($configfile)) { 
        echo '&lt;p class=&quot;warning&quot;&gt;The file &lt;code&gt;config.php&lt;/code&gt; exists and I cannot override it. The system may already be installed. If you wish to reinstall then remove the file &lt;code&gt;config.php&lt;/code&gt; and refresh the page.&lt;/p&gt;'; '&lt;p class=&quot;warning&quot;&gt;The file &lt;code&gt;config-sample.php&lt;/code&gt; does not exist. Upload a copy from the original package and refresh the page.&lt;/p&gt;'; 
}
     
    //Testing the presence of config-sample.php 
    elseif (!file_exists($configfilesample)) { 
        echo '&lt;p class=&quot;warning&quot;&gt;The file &lt;code&gt;config-sample.php&lt;/code&gt; does not exist. Upload a copy from the original package and refresh the page.&lt;/p&gt;'; 
}
        // Testing the presence of all the required files 
        elseif ($css || $spryjs || $install || $installation) { 
            echo '&lt;p class=&quot;warning&quot;&gt;A few required files are missing. Upload the &lt;code&gt;install&lt;/code&gt; folder from a fresh copy and refresh the page.&lt;/p&gt;'; 
} 
else { 
 echo $installationmessage; 
}