0

I'm trying to insert to a database but keep getting this error. I'm new to PHP and MySQL so have trawled through the forums here but have not found a solution.

Edit: Thanks for pointing out that I had mixed mysql and mysqli. I have amended that but still get the same error. Amended code below.

Here is the error I get:

Error: INSERT INTO user (vocID,username,password,firstname,lastname,street,city,postal,country,telephone,email)
       VALUES ('VOC168','testuser','testpass', 'first', 'last', 'street', 'city', 'postal', 'country', 'telephone', 'email@g.com');

Here is my code:

/* connect to the db */
$connection = mysql_connect('localhost','user','password');
mysql_select_db('database',$connection);

$result = mysql_query("select id, vocID from user order by id desc limit 1");
while ($row = mysql_fetch_assoc($result))
{
    $vocID = 'VOC'.$row['id'];

    $sql = "INSERT INTO user (vocID,username,password,firstname,lastname,street,city,postal,country,telephone,email)
            VALUES 
            ('VOC168','testuser','testpass', 'first', 'last', 'street', 'city', 'postal', 'country', 'telephone', 'email@g.com')";

    if (mysql_query($connection, $sql)) {
        echo "New record created successfully";
    }
    else {
        echo "Error: " . $sql . "<br>" . mysql_error($connection);
    }
}

mysql_close($connection);
  • Thank you! Even though this is not a solution I know have something to go on :-) – Ross Walke Jan 23 '16 at 22:56
  • Just so everyone knows, the problem was not mixing mysql and mysqli. I just needed to remove the value for vocID. I don't know why that fixed it. It worked on wamp, just not on my hosting platform. – Ross Walke Jan 25 '16 at 00:24

0 Answers0