Code en html qui appelle une page en php
Je d'installer un block libre dans prestashop dans lequel j'ai rentrer un code en html qui appelle cette page en php dont le code est le suivant.
<?php
/* déclaration de quelques variables */
$host = "localhost";
$user = "root";
$pass = "";
$bdd = "prestashop";
$table="ps_order_confirmation";
/* connection avec MySQL */
MYSQL_CONNECT($host,$user,$pass) or die("Impossible de se connecter à la base de données");
@mysql_select_db("$bdd") or die("Impossible de se connecter à la base de données");
$valid_confirmation = $_POST["valid"];
$message_confirmation = $_POST["message"];
$img1_confirmation = $_POST["img1"];
$img2_confirmation = $_POST["img2"];
$img3_confirmation = $_POST["img3"];
$submit_confirmation = $_POST["submit"];
if ($submit = 1)
{
/* stockage dans la bdd */
$query = "INSERT INTO $table VALUES('1','$valid_confirmation','$message_confirmation','$img1_confirmation','$img2_confirmation','$img3_confirmation','$submit_confirmation')";
$result = MYSQL_QUERY($query);
print "Les information sont enrégistrées." ;
}
else ($submit =0)
{
print "Vous ne désirez pas de carte personnalisée."
}
?>
Quand je clique sur le bouton envoyer le fichier, au lieu d'avoir une page qui que le fichier à bien été envoyé, j'ai tout simplement un error 404.
Que faire ?
Merci par avance de votre aide.
édit : titre
4 réponses
Un bloc libre Prestashop renvoie une erreur 404 lors de l'envoi du formulaire et le code PHP fourni se connecte à la base MySQL avec des fonctions obsolètes. Il affiche des failles typiques: utilisation de mysql_connect et MYSQL_QUERY obsolètes, affectation dans if ($submit = 1) au lieu d'une comparaison, et indices POST non vérifiés entraînant des notices. Plusieurs réponses suggèrent de vérifier que le bouton transmet une valeur via isset($_POST['...']), de remplacer l'affectation par une comparaison et d'utiliser mysqli ou PDO à la place des appels mysql. D'autres éléments notent que les erreurs 404 peuvent venir d'un chemin de fichier ou d'un script mal écrit, et recommandent d’organiser les envois et de tester pas à pas la logique conditionnelle.
-
L'erreur viendrai de la ligne 29 soit la ligne qui ouvre l'accolade après le Else.
Quelle est cette erreur ? -
l'erreur vient du fait qu'un else n'accepte pas de conditions.
-
En effet, quelle erreur ! x)
Mais les erreurs suivent :
Notice: Undefined index: valid in C:\Program Files\EasyPHP-5.3.6.0\www\prestashop\modules\freeblock\sql-freeblock.php on line 14
Notice: Undefined index: message in C:\Program Files\EasyPHP-5.3.6.0\www\prestashop\modules\freeblock\sql-freeblock.php on line 15
Notice: Undefined index: img2 in C:\Program Files\EasyPHP-5.3.6.0\www\prestashop\modules\freeblock\sql-freeblock.php on line 17
Notice: Undefined index: img3 in C:\Program Files\EasyPHP-5.3.6.0\www\prestashop\modules\freeblock\sql-freeblock.php on line 18
Les information sont enr?gistr?es.
Que faire ?-
-
-
-
<form action="modules/freeblock/sql-freeblock.php" method="post" enctype="multipart/form-data"> <input type="checkbox" name="valid" id="valid" value="1"/> <label for="valid">Désirez-vous recevoir une carte postale personalisé?</label><br /> <p>Veuillez saisir le message que vous souhaitez joindre.</p> <input type="text" name="message"> <br> <p>Pour optimiser la personnalisation de votre carte postale nous vous proposons :</p> <br> <input type="checkbox" name="img1" id="img1" value="1"/> <label for="img1">Thème océan</label><br /> <img src="modules/freeblock/ocean.jpg" alt="ocean.jpg"/> <br> <input type="checkbox" name="img2" id="img2" value="1"/> <label for="img2">Thème montagne</label><br /> <img src="modules/freeblock/montagne.jpg" alt="montagne.jpg"/> <br> <input type="checkbox" name="img3" id="img3" value="1"/> <label for="img3">Thème campagne</label><br /> <img src="modules/freeblock/campagne.jpg" alt="campagne.jpg"/> <br><br> <input type="submit" name="submit" value="Envoyer le fichier" /> </form>
Elles sont a 1 quand c'est coché -
-
-
Mon block carte postale :
<?php
/**
* Free block class, freeblock.php
* Free block Module
*
* @author Atwill Europe <contact@atwill-europe.com>
* @copyright Atwill Europe <www.atwill-europe.com>
* @version 1.2
*
* History:
* 1.0 - Initial version - Free contribution to Prestashop project
* 1.1 - Added german translation (by Henrik Pantle <pantle@gmx.de>)
* 1.2 - Added possibility of deleting free block for a specific language by saving empty fields
*/
class FreeBlock extends Module
{
/* @var boolean error */
protected $error = false;
/**
* Module constructor
*/
public function __construct()
{
$this->name = 'freeblock';
$this->tab = 'Blocks';
$this->version = '1.1';
parent::__construct();
$this->displayName = $this->l('Carte Postale');
$this->description = $this->l('Personalisez votre carte postale');
$this->confirmUninstall = $this->l('Are you sure that you want to delete your free blocks?');
}
/**
* Module installer
* Create tables
*/
public function install()
{
if (parent::install() == false OR $this->registerHook('leftColumn') == false)
return false;
$query = 'CREATE TABLE '._DB_PREFIX_.'freeblock ('id_lang' int(2) NOT NULL, 'title' varchar(255) NOT NULL, 'content' text NOT NULL, PRIMARY KEY('id_lang')) ENGINE=MyISAM default CHARSET=utf8';
if (!Db::getInstance()->Execute($query))
return false;
return true;
}
/**
* Module uninstaller
* Drops tables
*/
public function uninstall()
{
if (parent::uninstall() == false)
return false;
if (!Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'freeblock'))
return false;
return true;
}
/**
* Left column hook
*/
public function hookOrderConfirmation($params)
{
global $cookie, $smarty;
$freeblock = $this->getFreeblock($cookie->id_lang);
$smarty->assign(array(
'title' => $freeblock['title'],
'freeblock_content' => $freeblock['content']
));
if (!$freeblock)
return false;
return $this->display(__FILE__, 'freeblock.tpl');
}
/**
* Right column hook
*/
public function hookRightColumn($params)
{
return $this->hookLeftColumn($params);
}
/**
* Retrieves free block content for specific language
*
* @param integer $lang Specific language
* @return string Free block content
*/
public function getFreeblock($lang)
{
$result = array();
/* Get content */
if (!$result = Db::getInstance()->getRow('SELECT 'title', 'content' FROM '._DB_PREFIX_.'freeblock WHERE 'id_lang'='.$lang))
return false;
return $result;
}
/**
* Adds a new free block content in db or updates an existing one
*/
public function addFreeblock()
{
/* Multilingual freeblock */
$languages = Language::getLanguages();
$defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
if (!$languages)
return false;
foreach ($languages AS $language)
if ((!empty($_POST['content_'.$language['id_lang']])) || (!empty($_POST['title_'.$language['id_lang']])))
{
if (!Db::getInstance()->Execute('REPLACE INTO '._DB_PREFIX_.'freeblock VALUES ('.intval($language['id_lang']).', \''.($_POST['title_'.$language['id_lang']]).'\', \''.($_POST['content_'.$language['id_lang']]).'\')'))
return false;
}
else
if (!Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'freeblock WHERE 'id_lang'='.intval($language['id_lang'])))
return false;
return true;
}
/**
* Displays free block help
*/
private function _displayFreeblockHelp()
{
$this->_html .= '<b>'.$this->l('This module allows you to insert any text or HTML content on your site.').'</b><br /><br />
'.$this->l('For each language, you can setup a title and a content for you free block, and manage its position through the standard position management page.').'
'.$this->l('Just copy/paste your text or HTML code in the content area to have it displayed on your site.').'<br />
'.$this->l('Once saved, a preview of your content will be displayed at the bottom of this page.').'<br /><br />
'.$this->l('Hints:').'<br />
'.$this->l('- A free block will be displayed in a specific language only if a content for this specific language has been entered here. Use the flags to switch from one language to another.').'<br />
'.$this->l('- To delete a free block for a language, just empty the fields and save the block.').'<br /><br />';
}
/**
* Back office control panel for free blocks
*/
public function getContent()
{
$this->_html = '<h2>'.$this->displayName.'</h2>';
/* Add a free block */
if (isset($_POST['submitFreeblockAdd']))
{
if ($this->addFreeblock())
$this->_html .= $this->displayConfirmation($this->l('The free block has been added successfully'));
else
$this->_html .= $this->displayError($this->l('An error occured during free block creation'));
}
$this->_displayFreeblockHelp();
$this->_displayForm();
return $this->_html;
}
/**
* Displays the free block and title management form
*/
private function _displayForm()
{
global $cookie;
/* Language */
$defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
$languages = Language::getLanguages();
$divLangName = 'titlediv¤contentdiv¤previewdiv';
/* Form */
$this->_html .= '
<script type="text/javascript">
id_language = Number('.$defaultLanguage.');
</script>
<fieldset>
<legend><img src="'.$this->_path.'logo.gif" alt="" title="" /> '.$this->l('Manage your free blocks').'</legend>
<form method="post" action="'.$_SERVER['REQUEST_URI'].'">
<label>'.$this->l('Title:').'</label>
<div class="margin-form">';
foreach ($languages as $language)
{
/* Grab free block title */
$freeblock = $this->getFreeblock($language['id_lang']);
$this->_html .= '
<div id="titlediv_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').'; float: left;">
<input type="text" name="title_'.$language['id_lang'].'" value="'.$freeblock['title'].'" />
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'titlediv', true);
$this->_html .= '
<div class="clear"></div>
</div>
<label>'.$this->l('Content:').'</label>
<div class="margin-form">';
foreach ($languages as $language)
{
/* Grab free block content */
$freeblock = $this->getFreeblock($language['id_lang']);
$this->_html .= '
<div id="contentdiv_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').'; float: left;">
<textarea name="content_'.$language['id_lang'].'" id="contentInput_'.$language['id_lang'].'" cols="100" rows="20">'.$freeblock['content'].'</textarea>
</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'contentdiv', true);
$this->_html .= '
<div class="clear"></div>
</div>
<div class="margin-form">';
$this->_html .= '<input type="submit" class="button" name="submitFreeblockAdd" value="'.$this->l('Save this free block').'" id="submitFreeblockAdd" />';
$this->_html .= '
</div>
<label>'.$this->l('Preview:').'</label>
<div class="margin-form">';
foreach ($languages as $language)
{
/* Grab free block title */
$freeblock = $this->getFreeblock($language['id_lang']);
$this->_html .= '
<div id="previewdiv_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').'; float: left;">'.$freeblock['content'].'</div>';
}
$this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'previewdiv', true);
$this->_html .= '
</div>
</form>
</fieldset>';
}
}
?>
Au sein duquel figure mon html suivant
<form action="modules/freeblock/sql-freeblock.php" method="post" enctype="multipart/form-data">
<input type="checkbox" name="valid" id="valid" value="1"/> <label for="valid">Désirez-vous recevoir une carte postale personalisé?</label><br />
<p>Veuillez saisir le message que vous souhaitez joindre.</p>
<input type="text" name="message">
<br>
<p>Pour optimiser la personnalisation de votre carte postale nous vous proposons :</p>
<br>
<input type="checkbox" name="img1" id="img1" value="1"/> <label for="img1">Thème océan</label><br />
<img src="modules/freeblock/ocean.jpg" alt="ocean.jpg"/>
<br>
<input type="checkbox" name="img2" id="img2" value="1"/> <label for="img2">Thème montagne</label><br />
<img src="modules/freeblock/montagne.jpg" alt="montagne.jpg"/>
<br>
<input type="checkbox" name="img3" id="img3" value="1"/> <label for="img3">Thème campagne</label><br />
<img src="modules/freeblock/campagne.jpg" alt="campagne.jpg"/>
<br><br>
<input type="submit" name="submit" value="Envoyer la carte" />
</form>
Qui appelle cette page :
<?php
/* déclaration de quelques variables */
$host = "localhost";
$user = "root";
$pass = "";
$bdd = "prestashop";
$table="ps_order_confirmation";
/* connection avec MySQL */
MYSQL_CONNECT($host,$user,$pass) or die("Impossible de se connecter à la base de données");
@mysql_select_db("$bdd") or die("Impossible de se connecter à la base de données");
$valid_confirmation = $_POST["valid"];
$message_confirmation = $_POST["message"];
if($_POST["img1"])
$img1_confirmation = $_POST["img1"];
if($_POST["img2"])
$img1_confirmation = $_POST["img2"];
if($_POST["img3"])
$img1_confirmation = $_POST["img3"];
$submit_confirmation = $_POST["submit"];
if ($submit = 1)
{
/* stockage dans la bdd */
$query = "INSERT INTO $table VALUES('$valid_confirmation','$message_confirmation','$img1_confirmation','$img2_confirmation','$img3_confirmation')";
$result = MYSQL_QUERY($query);
print "Les information sont enrégistrées." ;
}
?>
Bon courage =)
Et encore une fois : Thx