PHP Code not saving to MySQL Database

Posted on 2011-04-18
Last Modified: 2012-05-11
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.
$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

  `id` int(11) NOT NULL auto_increment,
  `date` text NOT NULL,
  `textarea` mediumtext NOT NULL,
  PRIMARY KEY  (`id`)

Open in new window

Question by:error77
    LVL 18

    Expert Comment

    by:Greg Alexander
    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) . "')";


    $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
    LVL 10

    Accepted Solution


    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.


    Author Comment

    Yes, it's an example to EE ... the fields are all corrent but not saving ... I don't understand why :o/

    Author Closing Comment

    Thanks ... DB was missing.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now