Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7029409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:32:07+00:00 2026-05-28T00:32:07+00:00

pretty simple code in php and mysql: code inserting data in mysql table :

  • 0

pretty simple code in php and mysql:

code inserting data in mysql table :

<?php

include("config.php");

$sql="INSERT INTO messages_sent (to) VALUES (35)";

$result=mysql_query($sql);

if(!$result)
{
    echo("<br>Sorry the message could not be inserted into table messages_sent</br><br>");
    die(mysql_error());     
}else{      
    echo("<br>Message Inserted</br>");
}    

?>

table creation code follows:

$sql="CREATE TABLE IF NOT EXISTS `messages_sent`(
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`to` INT(11) NOT NULL,
`from` INT(11) NOT NULL,
`msg` TEXT NOT NULL,
`viewed` TINYINT(2)NOT NULL,
`time` DATETIME NOT NULL
)";

$result=mysql_query($sql);

if(!$result)
{
    echo("Sorry the create query for table messages_sent could not be executed ");
    die(mysql_error());     
}

if i insert data in msg column, it is no prob but if the column is to or from then syntax error problem occurs.

Solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:32:08+00:00Added an answer on May 28, 2026 at 12:32 am

    in the schema of your table, you are setting NOT NULL with none DEFAULT value to other fields. so basically you cannot execute

    INSERT INTO messages_sent (to) VALUES (35)

    because you are leaving other fields NULL and ALSO FROM and TO are Reserved Word in mySQL. Or instead use back ticks ` inside your query.

    ex.

    INSERT INTO `tableName` (`colName`) VALUES (valueHere)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a pretty simple code : $query = RENAME TABLE myOldTableName TO myNewTableName;
I have the following piece of code, executing a pretty simple MySQL query: $netnestquery
I have a pretty simple AJAX and PHP code. While calling the PHP through
the php code is pretty simple : <?php $my_bn_num=number_bangla(0123); function number_bangla($num1){ echo (<br>num =.$num1);
Client code is pretty simple: <form action=DDServlet method=post> <input type=text name=customerText> <select id=customer> <option
I'm trying to add some simple user data into a database via a webpage
I have a mysql table with over 4 million of data; well the problem
I am pretty new to both php and SQL. I have a login page
Guess this is a pretty simple problem. I've got a regex and php that
I'm new to ASP.NET and to SQL Server. I'm from the PHP/MySQL world, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.