if have checked this query several times but it aint passing the data to database..in other way every thing seems fine in this query kindly please sort out ths problem.

$qry="Insert into `postjob` (jobtitle,positions,category)
      VALUES('".$_POST['title']."','".$_POST['position']."','".$_POST['cate']."')";
      printf mysql_query($qry) or die(mysql_error());

What error do you get ?

Parse error: syntax error, unexpected 'mysql_query' (T_STRING) in D:\xampp\htdocs\jobtest\post.php on line 10

Try replacing your code with the following. If it works, tell me and I'll explain why.

$qry = mysql_query('INSERT INTO `postjob` (jobtitle, positions, category) VALUES ("'.$_POST['title'].'", "'.$_POST['position'].'", "'.$_POST['cate'].'")');

if(!$qry)
{
    die(mysql_error());
}

The printf function expects a string passed to it as a parameter to output. i.e. printf('Hello Word') you don't need it, you can just run the query.

$qry="Insert into `postjob` (jobtitle,positions,category)
VALUES('".$_POST['title']."','".$_POST['position']."','".$_POST['cate']."')";

mysql_query($qry) or die (mysql_error());

yehuda2001 its not working my bro..:(

Post all of your code, including the code for the method I suggested.

im gonna upload the files which i have actually created

This is post.php file

<?php
include "db.php";
 $action =isset($_POST['action']) ? trim ($_POST['action']):NULL;


 if($action=='postjob')
 {
 $qry="Insert into `postjob` (jobtitle,positions,category)
VALUES('".$_POST['title']."','".$_POST['position']."','".$_POST['cate']."')";
mysql_query($qry) or die (mysql_error());
      header("Location:jobpost.php");
 }
 ?>

this is db.php file

<?php
$con = mysql_connect("localhost","root",""); 
if($con)
{ 
  mysql_select_db("jobtest") or die (mysql_error());
}
else
{
 exit("Error connecting to server");
}
?>

this my index.php file

<html>
<title>My Test</title>
<head>
</head>

<body>
<form action="post.php" method="post">
Job title:<input type="text" name="title" value="">
<br>
Positions: <input type="text" name="position" value="">
<br>
<select name ="cate">
<option>Accounting</option>
<option>Maths</option>
<option>Banking</option>
</select>
<input type ="submit" name="" value="submit">
<input type ="hidden" name="action" value="postjop">
</form>
</body>
</html>

Are you getting a different error now that you got rid of the printf?

GliderPilot bro i had written the printf to display the actual mysql error.if dnt use it i get the blank page.

some how others told me to echo the query to get a error.although ths query seems fine.
but creating the hidden error which is not being shown

You cannot echo a "mysql_query", it isn't a text string. To get the error, you need to do as I said:

$qry = mysql_query('SELECT id FROM tableName');
if(!$qry)
{
    die(mysql_error());
}

Check your server's error logs for the error that's occuring or turn on error reporting to E_ALL

hi,

what others meant by echo your query is something like this.

    <?php
        $title = 'this title';
        $position = 'this position';
        $cate = 'this cate';
            $qry="Insert into postjob (jobtitle,positions,category)
            VALUES('".$title."','".$position."','".$cate."')";
            //printf mysql_query($qry) or die(mysql_error());

            echo $qry;

Isolate the codes where you are having problems with. On the codes above... disable the database connection first, and make sure to replace the $title, position, and cate with the actual values from the form on post.

try removing the quote on postjob first, before echoing your query. I just don't like how the single quoute is formatted. Sometimes they do create an error like that.

     $qry="Insert into postjob (jobtitle,positions,category)
        VALUES('".$_POST['title']."','".$_POST['position']."','".$_POST['cate']."')";
        mysql_query($qry) or die (mysql_error());

Just noticed something. Change this line:

$action =isset($_POST['action']) ? trim ($_POST['action']):NULL;

To this:

$action = (isset($_POST['action']) ? trim($_POST['action']) : NULL);

The malformed if statement was causing your mysql query to never run

Query is working by this method but not by above mentioned method

<?php
include "db.php";
$title =isset($_POST['title']) ? trim ($_POST['title']):NULL;
$position =isset($_POST['position']) ? trim ($_POST['position']):NULL;
$cate =isset($_POST['cate']) ? trim ($_POST['cate']):NULL;

   $qry="Insert into postjob (jobtitle,positions,category)
   VALUES('".$title."','".$position."','".$cate."')";
   mysql_query($qry) or die (mysql_error());
   echo $qry;

?>

What get's outputted when you echo $qry?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.