PHP SELECT AND INSERT

I get an error

You have an error in your SQL syntax near 'add,edit,name) VALUES('2005-08-06','ppt','30','15','JAMES')' at line 1

and it will not select any thing from the database that i have inserted


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Addvert Information</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<?php

if (isset($_POST['Submit'])) {
mysql_connect("localhost", "", "") or die( "Unable to select database" . mysql_error());
mysql_select_db("orderform")or die("Could not select database");
 $sql = "INSERT INTO test(date,media,add,edit,name) VALUES('".$_POST['date']."','".$_POST['media']."','".$_POST['add']."','".$_POST['edit']."','".$_POST['name']."')";
 $result = mysql_query($sql) or die(mysql_error());
}
?>
</head>

<body>
<table width="100%" border="1">
  <tr>
    <td width="1056"><table width="100%" border="1">
      <tr>
        <td bgcolor="#0099FF"><form name="form1" method="post" action="">
          <div align="center">Date :
              <input name="date" type="text" id="date">
  Media Format :
  <input name="media" type="text" id="media">  
  Cost Of Add :
  <input name="add" type="text" id="add">
   Cost Of Edit :
   <input name="edit" type="text" id="edit">
   Name :
   <input name="name" type="text" id="name">
   <input type="submit" name="Submit" value="Submit">
          </div>
        </form></td>
      </tr>
      <tr>
        <td height="134" bgcolor="#0099FF"> <table width="100%" border="1">
          <tr>
            <td>ID</td>
            <td>Date</td>
            <td>Media Format </td>
            <td>Cost Of Add (&pound;) </td>
            <td>Cost Of Edit (&pound;) </td>
            <td>Name</td>
          </tr>
              <?php
              mysql_connect("localhost", "", "") or die( "Unable to select database" . mysql_error());
mysql_select_db("orderform")or die("Could not select database");
             
              $result = mysql_query("SELECT * FROM test")
                  or die(mysql_error());

        echo "<tr><td>";
        echo $row['id'];
        echo "</td><td>";
      echo $row['date'];
        echo "</td><td>";
        echo $row['media'];
        echo "</td><td>";
        echo $row['add'];
        echo "</td><td>";
        echo $row['edit'];
        echo "</td><td>";
        echo $row['name'];
        echo "</td></tr>";
        ?>
                  
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
ace5342Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
I assume because of reserved words...

try this:
$sql = "INSERT INTO test([date],[media],[add],[edit],[name])

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BatalfCommented:
As mentioned, the word "add" is a reserved word in mySQL

The best solution is to rename that column

example:

alter table test change `add`newName varchar(255);

where "newName" is the new name of the column

Another solution is to put in backticks in your query

i.e.

$sql = "INSERT INTO test(`date`,`media`,`add`,`edit`,`name`) VALUES('".$_POST['date']."','".$_POST['media']."','".$_POST['add']."','".$_POST['edit']."','".$_POST['name']."')";
hernst42Commented:
Yes some of your columns are reserver words See http://dev.mysql.com/doc/mysql/en/reserved-words.html To access those use ` as fieldname-escape char

$sql = "INSERT INTO test(`date`,`media`,`add`,`edit`,`name`) ...

@angellll [column] is used in SQL-Server for column escapes, but mysql uses `
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Sorry, indeed it is ``  instead of [] (confusing MSSQL and MYSQL)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.