Create custom page with table

<?php
/*
Template Name:Custom Page

*/
get_header();?>
<?php
global $wpdb;
$yourtablename =  $wpdb->prefix . ‘rohit’;
$sql = “CREATE TABLE $yourtablename (
id mediumint(9) AUTO_INCREMENT,
album VARCHAR(50),
artist VARCHAR(50),
PRIMARY  KEY (id)
);”;
require_once(ABSPATH . “wp-admin/includes/upgrade.php”);
dbDelta($sql);
if($_POST[‘submit’])
{
$wpdb->insert($yourtablename ,array(‘album’ => $_POST[‘album’],’artist’ => $_POST[‘artist’]),array( ‘%s’,’%s’));
echo ‘success’;
echo ‘<script>window.location.href = “‘.home_url().’/custom.php”</script>’;

}
?>
<form action=”” method=”post”>
Album: <input type=”text” name=”album” />
Artist: <input type=”text” name=”artist” />
<input type=”submit” name=”submit”>
</form>

<?php get_footer();?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s