PHP Code not saving to MySQL Database

Hi all,

I am having a problem with some code. It's not saving to the database.

As far as values are concerned it's all posting and it actually says that it's save successfully but nothing is saving.

Can anyone spot any problems please?

Here is the code.
 
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

$date = $_POST["date"];
$textarea = $_POST["textarea"];

$query = "INSERT INTO YOUR_TABLE (date,textarea) VALUES ('" . mysql_real_escape_string($date) . "','" . mysql_real_escape_string($textarea) . "')";

$result = mysql_query($query,$link);

echo "form saved successfully!";

?>

...and this is the table

CREATE TABLE IF NOT EXISTS `tbl_calendar` (
  `id` int(11) NOT NULL auto_increment,
  `date` text NOT NULL,
  `textarea` mediumtext NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Open in new window

error77Asked:
Who is Participating?
 
APNFSSCCommented:
Hi

Replace YOUR_TABLE with the name of the table in your insert statement.

 
$query = "INSERT INTO tbl_calendar (date,textarea) VALUES ('" . mysql_real_escape_string($date) . "','" . mysql_real_escape_string($textarea) . "')";

Open in new window


Also you need to select the database after your connect statement.

replace the word databasename with the name of the mysql database that contains the tbl_calendar table.

mysql_select_db('databaasename',$link);
0
 
Greg AlexanderLead DeveloperCommented:
This may be a typo, but shouldn't

$query = "INSERT INTO YOUR_TABLE (date,textarea) VALUES ('" . mysql_real_escape_string($date) . "','" . mysql_real_escape_string($textarea) . "')";

be

$query = "INSERT INTO tbl_calendar (date,textarea) VALUES ('" . mysql_real_escape_string($date) . "','" . mysql_real_escape_string($textarea) . "')";

Although that may have been an example for EE
0
 
error77Author Commented:
Yes, it's an example to EE ... the fields are all corrent but not saving ... I don't understand why :o/
0
 
error77Author Commented:
Thanks ... DB was missing.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.