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
https://forums.phpfreaks.com/topic/4914-data-form-info-into-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.