am writing a program using php and mysql. it is giving this error "querry was

  • Thread starter Thread starter enala c
  • Start date Start date
E

enala c

Guest
empty". what does it mean? here is the code
<?php
$con = mysql_connect("localhost","root", "" );
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db = mysql_select_db(project);
$fullname=$_POST["NAME"];
$address=$_POST["ADDRESS"];
$nationality=$_POST["NATIONALITY"];
$date=$_POST["DATE"];
$contact=$_POST["CONTACT"];
$service=$_POST["SERVICE"];
$location=$_POST["LOCATION"];
$licencedate=$_POST["LICENCE"];
$query= mysql_query("insert into new_app values ('$fullname','$address', '$nationality', '$date', '$contact', '$service, '$location', '$licence'");
$result=mysql_query($query);
If ($result)
{
print "information sent";
}
else
print mysql_error();
?>
 
Well, first things first ... you are using the "root" account and A) not passing in a password, B) maybe you don't have a password set (which is a bit dangerous)

And, I'm not sure where 'project' is defined, because that's what you pass in to the "mysql_select_db()". I'm not sure if you were using a variable like "$project", or a macro (as you may be using).

The other thing is that an SQL INSERT statement doesn't return any records.

You should also make sure that the values passed in are ready to be put into the database. For example, what if someone's name was "John Q. O'Donnelly"? Your query would die early because the apostrophe ( ' ). To avoid this, it has to be escaped like this 'John Q. O\'Donnelly'. To avoid a problem like this, pass the value through a function like this: mysql_real_escape_string(), or if your PHP is older, use mysql_escape_string()

http://us2.php.net/manual/en/function.mysql-real-escape-string.php
 
$query = "insert into new_app values ('$fullname','$address', '$nationality', '$date', '$contact', '$service, '$location', '$licence'";
Why you use mysql_query() method ? when your code suggests you just wanted to make query string there.
According to your code $query contains recordset not he query :)
Also a very common practice to know whats going wrong where is to echo strings/data/post data etc in your page just for testing purpose. Later you can just comment that out.
Immediately you got that error you could have checked
echo $query;
Have Phun!
 
$query = "insert into new_app values ('$fullname','$address', '$nationality', '$date', '$contact', '$service, '$location', '$licence'";
Why you use mysql_query() method ? when your code suggests you just wanted to make query string there.
According to your code $query contains recordset not he query :)
Also a very common practice to know whats going wrong where is to echo strings/data/post data etc in your page just for testing purpose. Later you can just comment that out.
Immediately you got that error you could have checked
echo $query;
Have Phun!
 
means query is not fetching any date. If u r using the insert sql statement where is column name u MUST give the column name of the table like this

INSERT INTO table name ({coulmn name]) values (['values'])
 
Back
Top