PHP MySql insert gives server error 500

Szabó Tamás

Can anyone tell me why the following code is giving me an error page 500. And also how, can I correct it.

mysql_connect("xxx", "xxx", "xxx") or die(mysql_error());
mysql_select_db("xxx") or die(mysql_error());

$sql = "INSERT INTO oc2_ads (id_user, id_category)
VALUES ('$id_user', '$id_category')";
mysql_query($sql);

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

Thank you

Jay Blanchard

You cannot mix database API's. You start with older mysql_* functions and then move to some OOP version API (either MySQLi or PDO). If you want to use the older API all the way through you would do this:

mysql_connect("xxx", "xxx", "xxx") or die(mysql_error());
mysql_select_db("xxx") or die(mysql_error());
$sql = "INSERT INTO oc2_ads (id_user, id_category)
VALUES ('$id_user', '$id_category')";
$result = mysql_query($sql);

if ($result === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . mysql_error();
}

Your script is at risk for SQL Injection Attacks.

Please stop using mysql_* functions. These extensions have been removed in PHP 7. Learn about prepared statements for PDO and MySQLi and consider using PDO, it's really pretty easy.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Insert Into MYSQL DB using jquery/ajax 500 internal server error

From Dev

CURL gives 500 Internal server error

From Dev

Creating symlink gives 500 Internal Server Error

From Dev

.htaccess file gives 500 internal server error

From Dev

Creating symlink gives 500 Internal Server Error

From Dev

Error 500 Using Mysql In Php

From Dev

After hosting to server symfony gives 500 internal server error

From Dev

Jupyer lab gives Error 500: Internal Server Error

From Dev

Ajax call to webmethod gives ERROR 500 Internal server error

From Dev

Unexplained PHP error (Internal Server Error 500)

From Dev

Using CURL and PHPSimpleHTMLDOMParser gives me - 500 Internal Server error

From Dev

Htaccess rewrite url gives 500 Internal server error

From Dev

ExpressJS API Deployed on Heroku Gives 500 Internal Server Error

From Dev

Htaccess rewrite url gives 500 Internal server error

From Dev

Django, nginx, gunicorn: why on some page gives Server Error (500)?

From Dev

simple AJAX JQuery example gives me 500 internal server error

From Dev

Server gives 500 code error but still serves content

From Dev

MySQL in PHP gives error, MySQL in phpmyadmin does not

From Dev

MySQL in PHP gives error, MySQL in phpmyadmin does not

From Dev

sql data to json array using PHP gives HTTP ERROR 500

From Dev

php-login.net MVC login script gives a 500 error

From Dev

sql data to json array using PHP gives HTTP ERROR 500

From Dev

Internal Server Error 500 on .PHP pages only

From Dev

PHP code giving 500 internal server error

From Dev

Slim PHP 500 Internal Server Error

From Dev

500 internal server error php, how to solve?

From Dev

PHP use keyword is causing 500 server error

From Dev

POST 500 Internal Server Error -- PHP

From Dev

PHP Sql Server Output Parameter gives error

Related Related

  1. 1

    Insert Into MYSQL DB using jquery/ajax 500 internal server error

  2. 2

    CURL gives 500 Internal server error

  3. 3

    Creating symlink gives 500 Internal Server Error

  4. 4

    .htaccess file gives 500 internal server error

  5. 5

    Creating symlink gives 500 Internal Server Error

  6. 6

    Error 500 Using Mysql In Php

  7. 7

    After hosting to server symfony gives 500 internal server error

  8. 8

    Jupyer lab gives Error 500: Internal Server Error

  9. 9

    Ajax call to webmethod gives ERROR 500 Internal server error

  10. 10

    Unexplained PHP error (Internal Server Error 500)

  11. 11

    Using CURL and PHPSimpleHTMLDOMParser gives me - 500 Internal Server error

  12. 12

    Htaccess rewrite url gives 500 Internal server error

  13. 13

    ExpressJS API Deployed on Heroku Gives 500 Internal Server Error

  14. 14

    Htaccess rewrite url gives 500 Internal server error

  15. 15

    Django, nginx, gunicorn: why on some page gives Server Error (500)?

  16. 16

    simple AJAX JQuery example gives me 500 internal server error

  17. 17

    Server gives 500 code error but still serves content

  18. 18

    MySQL in PHP gives error, MySQL in phpmyadmin does not

  19. 19

    MySQL in PHP gives error, MySQL in phpmyadmin does not

  20. 20

    sql data to json array using PHP gives HTTP ERROR 500

  21. 21

    php-login.net MVC login script gives a 500 error

  22. 22

    sql data to json array using PHP gives HTTP ERROR 500

  23. 23

    Internal Server Error 500 on .PHP pages only

  24. 24

    PHP code giving 500 internal server error

  25. 25

    Slim PHP 500 Internal Server Error

  26. 26

    500 internal server error php, how to solve?

  27. 27

    PHP use keyword is causing 500 server error

  28. 28

    POST 500 Internal Server Error -- PHP

  29. 29

    PHP Sql Server Output Parameter gives error

HotTag

Archive