WordPress me custom database kese insert karte hai
1.step
Function.php File open karege hum or usme ye database ka function code
rakh dege .
function elh_insert_into_db() {
global $wpdb;
global $wpdb;
// creates my_table in database if not exists
$table = $wpdb->prefix . "my_table";
//my_table phpmyadmin database me ye table show hogi
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE IF NOT EXISTS $table (
`id` mediumint(9) NOT NULL AUTO_INCREMENT,
`name` text NOT NULL,
UNIQUE (`id`)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
// starts output buffering
ob_start();
?>
<?php
// does the inserting, in case the form is filled and submitted
if($_POST["submit_form"] != '' && $_POST["visitor_name"] != '') {
$table = $wpdb->prefix."my_table";
$name = strip_tags($_POST["visitor_name"], ""); <!-$name,$lname,$mob verible define karege->
$lname = strip_tags($_POST["visitor_lname"], "");
$mob = strip_tags($_POST["visitor_mob"], "");
<!-ye id se show hoge jo hamne form me diye hai visitor_name visitor_lname visitor_mob->
$wpdb->insert(
$table,
array(
'name' => $name, <!--name,lname,mob he ye jo ham database se name dege jo database me create kare hai-->
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE IF NOT EXISTS $table (
`id` mediumint(9) NOT NULL AUTO_INCREMENT,
`name` text NOT NULL,
UNIQUE (`id`)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
// starts output buffering
ob_start();
?>
<?php
// does the inserting, in case the form is filled and submitted
if($_POST["submit_form"] != '' && $_POST["visitor_name"] != '') {
$table = $wpdb->prefix."my_table";
$name = strip_tags($_POST["visitor_name"], ""); <!-$name,$lname,$mob verible define karege->
$lname = strip_tags($_POST["visitor_lname"], "");
$mob = strip_tags($_POST["visitor_mob"], "");
<!-ye id se show hoge jo hamne form me diye hai visitor_name visitor_lname visitor_mob->
$wpdb->insert(
$table,
array(
'name' => $name, <!--name,lname,mob he ye jo ham database se name dege jo database me create kare hai-->
'lname' => $lname,
'mob' => $mob
<!--$name,$lname,$mob he ye jo upare veribale defien kiye hai wo hai-->
)
);
}
// echoes a success message to the visitor
if($_POST["submit_form"] != '' && $_POST["visitor_name"] != '') {
$name = strip_tags($_POST["visitor_name"], "");
echo "<p> Your name <strong>".$name."</strong>,your last name <strong>".$lname."</strong> and your mobile<strong>".$mob."</strong> was successfully inserted into our database. Thanks!!</p>";
}
// outputs everything
return ob_get_clean();
}
// adds a shortcode you can use: [insert-into-db]
add_shortcode('insert-into-db', 'elh_insert_into_db');
?>
Shorcode hai
[insert-into-db]
[insert-into-db]
<!===============SIGNUP PAGE=======================>
WordPress me jake signup page create karege or waha ye code rakha dege or database me dekhege
ki waha ye file table bani ki nhi "my_table"
MY_TABEL show hogi ushi me data show hoga jo hum insert karege
<form method="post" id="v_form">
<label for="v_name">FUll DETAILS</label>
<br />
<input type="text" name="visitor_name" id="v_name" />
<input type="text" name="visitor_lname" id="visitor_lname" />
<input type="text" name="visitor_mob" id="visitor_mob" />
<p class="btn01"><input type="submit" name="submit_form" value="submit" />
<p> <input type="reset" name="reset" value="reset" /></p>
[insert-into-db]
</form>
<label for="v_name">FUll DETAILS</label>
<br />
<input type="text" name="visitor_name" id="v_name" />
<input type="text" name="visitor_lname" id="visitor_lname" />
<input type="text" name="visitor_mob" id="visitor_mob" />
<p class="btn01"><input type="submit" name="submit_form" value="submit" />
<p> <input type="reset" name="reset" value="reset" /></p>
[insert-into-db]
</form>
<---------------------------------------------------------------------------->
0 comments:
Post a Comment