mysql - Admin page to create new posts -


i created login , admin page.

on admin page created 2 text fields, first 1 title , second content. created submit button.

i have database table called: node.

in table created: id(1,2,3...), author_id (1=me), header (it'd title), text (it'd content) , date(when posted).

now want when push submit button, author, header, text , date appear on page new post. it's pretty same thing when push 'post question' button here.

here's webpage

i've created 3 test news posts sql, it's working, it'd better if admin page. :)

i'd appreciate if write down nicely, i've never done , don't know how one.

before anyone'd offer: not want create joomla or drupal website.

final working version: (thanks bansi)

<?php ob_start(); session_start(); ?> <meta charset="utf-8"> <link rel="stylesheet" href="style.css" type="text/css" media="screen"/> <?php if (isset($_cookie["user"])) {     include('sql.php');     $username =$_cookie["user"];     $user = mysql_fetch_row(mysql_query("select * user     name='$username'"));         if (empty($_get['action']))         {             //this add database             if (!empty($_post['submit']) && $_post['submit']=='submit'){             //do validation if required, not empty header , not empty body etc here             $title = mysql_real_escape_string($_post['title']);             $text = mysql_real_escape_string($_post['text']);             }             //insert database             mysql_query("insert hearthstone.node              ( author_id , title , text , date )              values ( '1', '$title', '$text', now( ) );");         }             ?> <div id="adminmenu">logged in <b> <?php print $user[1];?></b> <span style="margin: 15px;"><br></span> <?php include('logout.php'); ?> <span style="margin: 15px;"></span> <form method="post" action=""> <p>title:</p> <p><input type="text" maxlength="255" name="title" id="title" size="60"></p> <p>body content:</p> <p><textarea cols="60" rows="20" name="text" id="text"></textarea></p> <p><input type="submit" name="submit" id="submit" value="submit"></p> </form> </div>              <?php     } else {         include('login.php'); } ?> 

try this. details below code.

<?php ob_start(); session_start(); ?> <meta charset="utf-8"> <link rel="stylesheet" href="style.css" type="text/css" media="screen"/> <?php if (isset($_cookie["user"])) {     include ('sql.php');     $username = $_cookie["user"];     $user = mysql_fetch_row(mysql_query("select * user     name='$username'"));     if (empty($_get['action'])) {         //this add database         if (!empty($_post['submit']) && $_post['submit']=='submit'){             //do validation if required, not empty header , not empty body etc here             $header = mysql_real_escape_string($_post['header']);             $body = mysql_real_escape_string($_post['body']);             //insert database             mysql_query("insert node (author_id,header,text,`date`) values (1,$header,$body,now());");         } ?> <div id="adminmenu">logged in <b> <?php print $user[1]; ?></b> <span style="margin: 15px;"><br></span> <?php include ('logout.php'); ?> <span style="margin: 15px;"></span> <form method="post" action=""> <p>title:</p> <p><input type="text" maxlength="255" name="header" id="title" size="60"></p> <p>body content:</p> <p><textarea cols="60" rows="20" name="body" id="content"></textarea></p> <p><input type="submit" name="submit button" id="submit" value="submit"></p> </form> </div>              <?php     } } else {     include ('login.php'); } ?> 

important : don't use mysql functions depreciated try use mysqli or pdo

the changed code. have added comment in code save database. have added <form> element html. code not tested server no longer supports mysql functions. have tried best use db name , field names question. note have not added error checking.

please let me know if encounter problems.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -