0

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());
5
Contributors
19
Replies
20
Views
4 Years
Discussion Span
Last Post by GliderPilot
0

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

1

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());
}
1

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());

0

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");
 }
 ?>
0

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");
}
?>
0

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

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

0

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

0

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());
}
0

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());

Edited by veedeoo: info added

0

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

Edited by GliderPilot

0

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;

?>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.