$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>I am using wpdb but it not working perfectly.but if I dont use form data its work|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

I am using wpdb but it not working perfectly.but if I dont use form data its work

matteradmin10PV0评论
 <?php

 if (isset($_POST['submit'])) {
 global $wpdb;

$table_name = $wpdb->prefix . "table_booky";
$wpdb->insert($table_name, array(
    "Name" => $_POST['name'],
    "dep" =>  $_POST['age'];
    "age"  =>  $_POST['dep'];
 ));

  }
  ?>
 <form class="" action="<?php home_url(); ?>" method="POST">


    <input type="text" name="name" value="">
    <input type="text" name="age" value="">
    <input type="text" name="dep" value="">
    <input type="submit" name="submit" value="submit">

 </form>
 <?php

 if (isset($_POST['submit'])) {
 global $wpdb;

$table_name = $wpdb->prefix . "table_booky";
$wpdb->insert($table_name, array(
    "Name" => $_POST['name'],
    "dep" =>  $_POST['age'];
    "age"  =>  $_POST['dep'];
 ));

  }
  ?>
 <form class="" action="<?php home_url(); ?>" method="POST">


    <input type="text" name="name" value="">
    <input type="text" name="age" value="">
    <input type="text" name="dep" value="">
    <input type="submit" name="submit" value="submit">

 </form>
Share Improve this question edited Nov 28, 2018 at 21:17 shanebp 5,0857 gold badges28 silver badges40 bronze badges asked Nov 28, 2018 at 19:39 ReazReaz 1 2
  • It's hard to tell from your post - if you could go back please and wrap everything in code, which looks like a curly braces symbol, that should help - but it looks like in your array you have semicolons where you need to use commas instead. – WebElaine Commented Nov 28, 2018 at 20:15
  • Welcome to WPSE, Reaz. You may want to consider revising your question for clarity. Make your title a little more concise and be descriptive in the content area. Right now all you really have is a code snippet without a description of what is not working for you. – butlerblog Commented Nov 28, 2018 at 21:53
Add a comment  | 

1 Answer 1

Reset to default 0

While your question isn't entirely clear on the issue you're having, I'm guessing that it's the way that you defined the elements of the array you were trying to insert.

You had a mix of commas and semicolons separating the elements.

I revised your code to correct that - and to aid readability of your code so you can see it, I pulled this out into a variable - $data_array.

<?php

if ( isset( $_POST['submit'] ) ) {
    global $wpdb;

    $table_name = $wpdb->prefix . "table_booky";

    $data_array = array(
        "Name" => $_POST['name'],
        "dep"  => $_POST['age'],  // Note the comma, and not semicolon
        "age"  => $_POST['dep'],  // Same here...
    );

    $wpdb->insert( $table_name, $data_array );

}
?>
<form class="" action="<?php home_url(); ?>" method="POST">


<input type="text" name="name" value="">
<input type="text" name="age" value="">
<input type="text" name="dep" value="">
<input type="submit" name="submit" value="submit">

</form>

Now, this doesn't address other issues such as the fact that you are not sanitizing your input data. So you should look into that after you get your code working.

Post a comment

comment list (0)

  1. No comments so far