• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 469
  • Last Modified:


The following code used to work  for me but i went away for a week and now it doesn't work at all .....will somebody please tell me why i can't insert data into the database? I can connect to the database and the error codes  work fine it just won't insert for some odd reason. YES the database is set up correctly and i can access it from the php command line interface.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">




<link href="../common_css/eol.css" rel="stylesheet" type="text/css" media ="screen">



<?php require("../common_code/navncon.inc"); ?>

<div class="datcon">
$assettag = $_POST['assettag'];
$serial = $_POST['serial'];
$location = $_POST['location'];
$department = $_POST['department'];
$office = $_POST['office'];
$issues = $_POST['issues'];
$collected = $_POST['collected'];
$submit = $_POST['submit'];

$error = "<div class= \"error\">please fill in all form fields</div>";

$success = "<div class= \"error\">data inserted correctly</div>";

if ($submit){
 if (!$assettag || !$serial || !$location || !$department || !$office || !$issues || !$collected){

echo $error;

} else {

echo $success;
 mysql_query("INSERT INTO EOL (assettag, serial, location, department, office, issues, collected) VALUES('$assettag','$serial','$location','$department','$office','$issues','$collected')");


<form id= "" name= "form1" method= "post" action= "">

<div class= "formbox1">asset tag #&nbsp<input type= "text"  name="assettag"  id= "" value= "" label="" size= "" maxlength= ""></div>

<div class= "formbox1">serial # &nbsp<input  type= "text" name= "serial"  id= ""  value= "" label= "" size= "" maxlength= ""></div>

<div class= "formbox1">location &nbsp<input  type= "text" name= "location" id= "" value= "" label= "" size= "" maxlength= ""></div>

<div class= "formbox1">department &nbsp<input  type= "text" name= "department"  id= "" value= "" label= "" size= "" maxlength= ""></div>


<div class= "formbox1">office &nbsp<input  type= "text" name= "office"  id= ""    value= "" label= "" size= "" maxlength= "" ></div>

<div class= "textformbox">issues &nbsp<textarea rows= "1" cols= "17" name= "issues"    id="" value="" label="" size="" maxlength="" ></textarea></div>

<div class ="formbox1">collected? &nbsp yes <input type= "checkbox" name= "collected" action= " " id= "" value= "1" label= "" size= "" maxlength= ""></div>

<div class="buttbox">
<div class="bubox0">

<input src="../common_images/insert.jpg" alt= "insert" type= "image"  name = "submit" action= "" id= "" value= "insert" label= "" size= "10" maxlength= "">


<form class="bubox1" method="link" action= "home.php" id= "">

<input src="../common_images/bak.jpg" alt= "back" type= "image"  name = "back" action= "home.php" id= "" value= "insert" label= "" size= "10" maxlength= "" tabindex="">

<form class="bubox2" method="link" action=home.php id= "">
<input src="../common_images/can.jpg" alt= "cancel" type= "image"  name = "submit" action= "home.php" id= "" value= "insert" label= "" size= "10" maxlength= "">


  • 3
  • 2
1 Solution
well, let's ask the computer what error is being generated.

$sql_command="INSERT INTO EOL (assettag, serial, location, department, office, issues, collected) VALUES('$assettag','$serial','$location','$department','$office','$issues','$collected')";
if (mysql_errno() or $debug)
  echo $sql_command."<br />\n".mysql_errno() . ": " . mysql_error(). "<br />\n";


calmchessAuthor Commented:

1045: Access denied for user 'apache'@'localhost' (using password: NO)
calmchessAuthor Commented:
weird that the php debugger didn't give me that errror code.
calmchessAuthor Commented:
ok i  granted all privleges to user apache and now i get the error .....................1065: Query was empty
odd little issue, let's try adding a ; at the end of the sql_command

$sql_command="INSERT INTO EOL (assettag, serial, location, department, office, issues, collected) VALUES('$assettag','$serial','$location','$department','$office','$issues','$collected');";

there are some threads and comments about this issue in older versions of mysql.

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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now