0
if (!empty($name) || !empty($degree) || !empty($college)|| !empty($gender) || !empty($mail) || !empty($phone) || !empty($city)) 
{
    mysql_query($con,
        "INSERT INTO regstration(name,degree,college,gender,mail,phone,city)
        VALUES('$name','$degree','$college','$gender','$mail','$phone','$city')"
    ) or die("error");  
}

The error message is:

mysql_query() expects parameter 1 to be string given resource C://...... line 21

GMB
  • 216,147
  • 25
  • 84
  • 135

2 Answers2

5

The first problem with your query is that you have inverted the query string and the connection object in your call to mysql_query.

Also, you commented that mobile number its an integer format other resources are varchar. You should then adapt the insert query to not quote the integer value :

$sql= 
    "INSERT INTO regstration(name,degree,college,gender,mail,phone,city) 
     VALUES('$name','$degree','$college','$gender','$mail',$phone,'$city')";
mysql_query($sql, $con) or die("error : " . mysql_error());

Important remarks :

  • when a mysql error happens, you can access the error message using mysql_error() (see the above code) ; it is important to have full error messages in order to analyze the error, instead of a generic error mention.

  • anyone on SO will strongly suggest to use prepared statements and parameterized queries, to protect your code from SQL injection and make your queries more readable and maintainable. Such typo is far much easier to detect when using parameterized queries.

  • mysql extension is deprecated : you should consider migrating to mysqli or PDO.

GMB
  • 216,147
  • 25
  • 84
  • 135
1

Notice that mysql_query first argument is the query and not $con.

It can take $con as second argument:

$query = "INSERT INTO regstration(name,degree,college,gender,mail,phone,city) VALUES('$name','$degree','$college','$gender','$mail','$phone','$city')";
mysql_query($query, $con) or die("error");

And notice also:

This extension was deprecated in PHP 5.5.0

dWinder
  • 11,597
  • 3
  • 24
  • 39