Jump to content


Photo

Data Form info Into Database


  • Please log in to reply
2 replies to this topic

#1 chuddyuk

chuddyuk
  • Members
  • PipPip
  • Member
  • 28 posts
  • LocationEngland

Posted 14 March 2006 - 11:48 AM

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::





<? 


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> 
<?
}
?> 

Thanks

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 14 March 2006 - 12:00 PM

Instead of

$add_all = 'INSERT INTO `news` (`title`, `news`) VALUES (\'$titles\', \'$new\')';

use

$add_all = "INSERT INTO `news` (`title`, `news`) VALUES ('$titles', '$new')";

And thats it :)
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 chuddyuk

chuddyuk
  • Members
  • PipPip
  • Member
  • 28 posts
  • LocationEngland

Posted 14 March 2006 - 12:29 PM

Works a Treat thanks


!!!!Knew it was something really simple!!!!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users