Can't add data to the database

Page 1 of 1

3 Replies - 834 Views - Last Post: 25 January 2010 - 08:26 PM Rate Topic: -----

#1 James Bond C++ Spy   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 132
  • Joined: 03-October 07

Can't add data to the database

Posted 25 January 2010 - 02:17 PM

I had this working and now after some changes it will not add the data to the database. I get no error. When I run the MySQL in phpMyAdmin it adds it. Here is what I can run via phpMyAdmin:
INSERT INTO `employee`(`Emp_Id`, 
   `FirstName`,
   `LastName`,
   `Dept`,
   `Shift`
  )
VALUES('$Emp_Id',
   '$FirstName',
   '$LastName',
   '$Dept',
   '$Shift'
);



Here is the php code:
<?php

$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("training_db", $con);

	$Emp_Id = $_POST['Emp_Id'];
	$FirstName = $_POST['FirstName'];
	$LastName = $_POST['LastName'];
	$Dept = $_POST['Dept'];
	$Shift = $_POST['Shift'];

mysql_query("INSERT INTO `employee`(`Emp_Id`, 
   `FirstName`,
   `LastName`,
   `Dept`,
   `Shift`
  )
VALUES('$Emp_Id',
   '$FirstName',
   '$LastName',
   '$Dept',
   '$Shift'
)");

mysql_close($con);
  
?>


Anyone have any ideas???

This post has been edited by James Bond C++ Spy: 25 January 2010 - 02:19 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Can't add data to the database

#2 Elbrus   User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 107
  • Joined: 22-July 08

Re: Can't add data to the database

Posted 25 January 2010 - 02:28 PM

make mysql_query("INSERT INTO `employee`(`Emp_Id`,`FirstName`,`LastName`,`Dept`,`Shift`)

In to mysql_query("INSERT INTO employee (`Emp_Id`,`FirstName`,`LastName`,`Dept`,`Shift`)

For my self I never add "'" into my query and I don't get error or wrong output.
Was This Post Helpful? 0
  • +
  • -

#3 Auzzie   User is offline

  • D.I.C Addict
  • member icon

Reputation: 43
  • View blog
  • Posts: 573
  • Joined: 20-January 09

Re: Can't add data to the database

Posted 25 January 2010 - 04:32 PM

its the same thing we told you last time.... phpmyadmin will accept it but mysql_query wont
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6875
  • View blog
  • Posts: 31,665
  • Joined: 10-May 07

Re: Can't add data to the database

Posted 25 January 2010 - 08:26 PM

** Topic closed **

James Bond C++ Spy : Stop wasting peoples time with asking this repetitive question. If you have not gotten it by now, I don't know what to tell you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1