Help me solve this?

I have made this with materialized css and am facing a little error but i cannot find out the error help me to solve this.Here’s the code
HTML.

<form method="post" action="#">
  <div class="row">
    <div class="input-field col s12">
      <textarea id="txta1" class="materialize-textarea" name="desc" id="word_count" cols="1" rows="1" length="120" ></textarea>
      <label for="txta1" name="txt_Script">Describe Here</label>max 200characters
    </div>
  </div>
 <input type="submit"  class="btn" value="submit" name="register">

Code for php

<?php	
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("job",$con);
if(isset($_POST['submit']))
{
   $a=$_POST['ID'];
   $b=$_POST['desc'];
   $sql="INSERT INTO describepost(ID,post) VALUES ('$a','$b')";
	if(mysql_query($sql,$con))
		echo "Thanks ";
	else
		echo "Error : ";
	
	}
?>

I Have database name as job,
inside of this database i have created table named as “describepost”
and inside of this table i have 2 fields named as 1.ID 2.pst
help me please…

Try to insert this code so that it help us to find the error.

<?php	
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("job",$con);
if(!$db){
  die(mysql_error());
}
if(isset($_POST['submit']))
{
   $a=$_POST['ID'];
   $b=$_POST['desc'];
   $sql="INSERT INTO describepost(ID,post) VALUES ('$a','$b')";
	if(mysql_query($sql,$con)){
		echo "Thanks ";
	else
		echo "Error : ";
	}
	}
?>

The die(mysql_error()); will show us if you have problem to connect with your db.

PS
What message do you have when checking the mysql_query?

What is the error? do you have error reporting on?

Where is this field in your form?

   $a=$_POST['ID'];
1 Like

I am getting error
Parse error: syntax error, unexpected ‘else’ (T_ELSE) in C:\xampp\htdocs\job\ifpost.php on line 66
help me to solve it

I see it plain as day now you show the error message.
You are missing some brackets { }.

	if(mysql_query($sql,$con)){
		echo "Thanks ";
	else
		echo "Error : ";
	}
	}

Instead try:-

	if(mysql_query($sql,$con)){
		echo "Thanks ";
        }
	else {
		echo "Error : ";
	}
1 Like

OP is trying to use shorthand, but doesn’t know how to do it right. Saw this already, but wanted to see if anyone else caught it.

Error has gone but there is no change inside of the database

Can you answer the question from @droopsnoot ?

I don’t see any input named “ID”.

There is no field named ID but i have inserted flelds name as ID and PST in my table(describepost)

I have removed ID from the table and from the code but its still not working

Did you give any thought to my comments in the other topic?

I would not expect that code to work on any server that had an up-to-date version of PHP.
You need to update your methods for both future present -proofing and to remove the gaping security holes.

1 Like

Yippie done it here was the query i have not defined the name of the field inside of the code.

A more help please.
What to do if my data is not inserted in sequence form?

Would anyone please help me i am not getting any of the ideas to solve this if possible please help me
I want to create 2 dropdowns named as 1.category 2.subcategory in my website for example if a user selects a category and after selecting any of the category he wolud select its cubcategory and selected results should store inside of my database so please help me.

Can you expand on that question please? You don’t generally have a lot of control over what sequence the data is stored, instead you would sort it in the appropriate order when you are retrieving it for display.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.