Jump to content

Data Form info Into Database


chuddyuk

Recommended Posts

I have a form which submits info into a database, it is very simple at the moment once i have solved this problem i will add the rest of my feilds.

It submits, but on the variable name like it will show $title an $news in the database, i know its somethin v simple but cant figure it out please help, here is the page::





[code]
<?


if(isset($_GET['commented']))
{


// Tell the user it has been submitted (optional)
echo('Your comment has been posted.');

include "common.php";

// Set global variables to easier names
$titles = $_GET['title'];
$new = $_GET['news'];

// Connect to Mysql, select the correct database, and run teh query which adds the data gathered from the form into the database
mysql_connect($dbhost,$dbuser,$dbpasswd) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$add_all = 'INSERT INTO `news` (`title`, `news`) VALUES (\'$titles\', \'$new\')';
mysql_query($add_all) or die(mysql_error());

}
else
{

// If the form has not been submitted, display it!
?>
<form method="get" action="<?php echo $PHP_SELF?>">
Title : <input type='text' name='title'><br><br>
News : <input type='textarea' name='news'><br><br>
<input type='hidden' name='commented' value='set'>
<input name='submit' type='submit' value='Post your comment'>
</form>
<?
}
?>

[/code]Thanks
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.