?
Solved

PHP MySql

Posted on 2006-04-05
5
Medium Priority
?
467 Views
Last Modified: 2006-11-18
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
Comment
Question by:calmchess
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Michael701
ID: 16385014
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
 

Author Comment

by:calmchess
ID: 16385052

1045: Access denied for user 'apache'@'localhost' (using password: NO)
0
 

Author Comment

by:calmchess
ID: 16385112
weird that the php debugger didn't give me that errror code.
0
 

Author Comment

by:calmchess
ID: 16385529
ok i  granted all privleges to user apache and now i get the error .....................1065: Query was empty
0
 
LVL 19

Accepted Solution

by:
Michael701 earned 2000 total points
ID: 16385966
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question