Insertion de données dans des tableaux personnalisés
-
-
Vos données correspondent-elles auxtypes de données que vousfournissez?Avez-vous [débogage activé] (http://wordpress.stackexchange.com/questions/95982/where-do-i-get-bug-information-to-add-to-a-question/95983#95983)?Does your data match the data types you are providing? Do you have [debugging enabled](http://wordpress.stackexchange.com/questions/95982/where-do-i-get-bug-information-to-add-to-a-question/95983#95983)?
- 1
- 2014-10-14
- s_ha_dum
-
Je viens de remarquer que vous utilisez `$global $ wpdb` au lieu de`global $ wpdb`,doncje suppose que votre code d'insertionne fonctionnepas.Just noticed you're using `$global $wpdb` instead of `global $wpdb`, so I'm guessing your insert code isn't running.
- 0
- 2016-04-26
- TomC
-
Un autreproblèmepourrait être que lenom de votretable contient unespace,de sorte que le SQLn'apaspu être analysé correctement.Another problem could be that your table name contains a space, so the SQL couldn't be parsed properly.
- 0
- 2016-10-27
- Nimrod
-
1 réponses
- votes
-
- 2015-02-17
Vous avez dit que votreformulaire setrouve dans le dossierprincipal? Je suppose que vous devez définir une URL appropriéepour
action=""
. Vouspouvezessayer:action="<?php echo site_url() . '/setLiquorType.php'; ?>"
Ilestpréférable deplacer le code de votreformulaire dansfunctions.php,puis de laisser leformulaire action="" vide. Ensuite,vouspouvez déclencher votrefonction deformulaire lorsque leformulaireest soumis.
Votreformulaire HTML:
<form method = "post" action = ""> //edited form action <h3>Add a New Liquor Type</h3> //wrapped title with <h3> tags and removed <br> because h3 element will have padding that will separate it from form (if not provided in your style.css it will be assigned by the browser) <p> //wraping field with paragraph to generate automatic space between them without styling it <label for="name">Name:</label> //removed <p> element and used <label> instead <input type="text" name="name"/> </p> <p> <label for="description">Description</label> <input type="text" name="description"/> </p> <hr> //replaced unnecessary --- lines <input type="submit" value="Submit" name="liquor_submit"/> // added name attribute that will be used to check if the form is submitted </form> </br>
Maintenant,dans votrefunctions.php,vouspouvez ajouter quelque chose comme:
//setting up the form function themename_add_new_liquor() { $name = $_POST['name']; $description = $_POST['description']; //You forgot to collect data from "description" field global $wpdb; //removed $name and $description there is no need to assign them to a global variable $table_name = $wpdb->prefix . "liquor_type"; //try not using Uppercase letters or blank spaces when naming db tables $wpdb->insert($table_name, array( 'lq_name' => $name, //replaced non-existing variables $lq_name, and $lq_descrip, with the ones we set to collect the data - $name and $description 'description' => $description ),array( '%s', '%s') //replaced %d with %s - I guess that your description field will hold strings not decimals ); } } //And now to connect the two: if( isset($_POST['liquor_submit']) ) themename_add_new_liquor();
J'espère que celapourra vous aider. Deplus,celane fonctionnerapas si vousn'avezpas créé votretable debase de donnéesen premier lieu (lafonction $ wpdb->insertest utiliséepourinsérer des données dans latableexistante).
Salut! :)
You said your form is in the main folder? I guess you need to set proper URL for
action=""
. You could try:action="<?php echo site_url() . '/setLiquorType.php'; ?>"
It is best practice to put your form code into functions.php and then leave form action="" empty. Then you can trigger your form function when form is submitted.
Your Form HTML:
<form method = "post" action = ""> //edited form action <h3>Add a New Liquor Type</h3> //wrapped title with <h3> tags and removed <br> because h3 element will have padding that will separate it from form (if not provided in your style.css it will be assigned by the browser) <p> //wraping field with paragraph to generate automatic space between them without styling it <label for="name">Name:</label> //removed <p> element and used <label> instead <input type="text" name="name"/> </p> <p> <label for="description">Description</label> <input type="text" name="description"/> </p> <hr> //replaced unnecessary --- lines <input type="submit" value="Submit" name="liquor_submit"/> // added name attribute that will be used to check if the form is submitted </form> </br>
Now in you functions.php you can add something like:
//setting up the form function themename_add_new_liquor() { $name = $_POST['name']; $description = $_POST['description']; //You forgot to collect data from "description" field global $wpdb; //removed $name and $description there is no need to assign them to a global variable $table_name = $wpdb->prefix . "liquor_type"; //try not using Uppercase letters or blank spaces when naming db tables $wpdb->insert($table_name, array( 'lq_name' => $name, //replaced non-existing variables $lq_name, and $lq_descrip, with the ones we set to collect the data - $name and $description 'description' => $description ),array( '%s', '%s') //replaced %d with %s - I guess that your description field will hold strings not decimals ); } } //And now to connect the two: if( isset($_POST['liquor_submit']) ) themename_add_new_liquor();
I hope this can help. Also, non of this will work if you have not created your Database table in the first place ( $wpdb->insert function is used for inserting data in the existing table ).
Cheers! :)
J'essaie de créer destables d'entréepersonnaliséespourenvoyer des données dans destablespersonnalisées sur labase de données wp. Jene peux rienfairefaire àmon script. L'utilisateurentrera untype de liqueur,comme la vodka ou le whisky,fournira une descriptionet l'enverra à labase de données,oùil y a destablespersonnalisées dans labase de données wordpress. J'ai le code html dans unepage wordpresset lephp dans unfichier appelé setLiquorType.php qui setrouve dans le dossier wordpressprincipal.
Formulaire HTML
Mon scriptphp
N'importe quelle aide seraitformidable