-3

Possible Duplicate:
PHP Error: mysql_fetch_array() expects parameter 1 to be resource, boolean given

I am trying to insert data from submitted form into database. The data is being successfully inserted into the DB but I keep getting this error message:

mysql_fetch_assoc() expects parameter 1 to be resource, boolean given

And here's the code:

function senddata () {
    $con = mysql_connect("localhost","XXX","XXX");
    if (!$con)
        {
    die('Could not connect: ' . mysql_error());
        }
        mysql_select_db("user", $con);
        $sql="INSERT INTO Employment (CollegeMajor) VALUE('$_POST[collegemajor]')";
        $result=mysql_query($sql) or die(mysql_error());
        $row = mysql_fetch_assoc($result);


    if (!mysql_query($sql,$con))
        {
    die('Error: ' . mysql_error());
        }


    mysql_close($con);
    }

The error message is referring to this line:

$row = mysql_fetch_assoc($result);
Community
  • 1
  • 1
Matthieu McLaren
  • 224
  • 1
  • 4
  • 14

3 Answers3

3

http://de2.php.net/manual/en/function.mysql-query.php

This is expected behavior. INSERT statements return a boolean value, true on success and false on failure.

However, you really should look at mysqli or PDO.

Charles Sprayberry
  • 7,741
  • 3
  • 41
  • 50
2

Please use the function mysql_affected_rows() to get the result of an INSERT operation.

Brian
  • 15,599
  • 4
  • 46
  • 63
0

what sort of result are you expecting after inserting a row into mysql?

if you want to obtain auto-increment-id - run mysql_insert_id($con).

Kevin
  • 53,822
  • 15
  • 101
  • 132
pQd
  • 116
  • 4
  • 20