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

PHP MySql

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">

<html>


<title>eol</title>


<head>

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


</head>



<body>




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

<div class="datcon">
<?PHP
$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>";


include("../authentication/connect.inc");
$db;
$tab;
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')");
}
}

mysql_close();
?>

<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= "">
</div>

</form>

<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>

<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= "">
</form>
</div>
</div>

</body>

</html>
0
calmchess
Asked:
calmchess
  • 3
  • 2
1 Solution
 
Michael701Commented:
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')";
$ok=mysql_query($sql_command);
if (mysql_errno() or $debug)
  echo $sql_command."<br />\n".mysql_errno() . ": " . mysql_error(). "<br />\n";

Michael

0
 
calmchessAuthor Commented:

1045: Access denied for user 'apache'@'localhost' (using password: NO)
0
 
calmchessAuthor Commented:
weird that the php debugger didn't give me that errror code.
0
 
calmchessAuthor Commented:
ok i  granted all privleges to user apache and now i get the error .....................1065: Query was empty
0
 
Michael701Commented:
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.

Michael
0
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