user4399269 user4399269 - 9 months ago 48
MySQL Question

The following php code returns a http error 500 using mysql?

This is the sample code which I got error, It works well in localhost when try to run the code in remote server is returns errors, Suggest me is there is any other way to achieve the same function in code.

if (!$con = mysql_connect('localhost', 'root', 'password')) {
die('An error occurred while connecting to the MySQL server!<br><br>' . mysql_error());
if (!mysql_select_db(sample)) {
die('An error occurred while connecting to the database!<br><br>' . mysql_error());
$sql = array(
'CREATE TABLE content SELECT * FROM sample2.content'
if (sizeof($sql) > 0) {
foreach ($sql as $query) {
if (!mysql_query($query)) {
die('A MySQL error has occurred!<br><br>' . mysql_error());




For starters, do not use any mysql_* functions if you are able to as they have been deprecated as of PHP 5.5.x and have been entirely removed in PHP 7.

There isn't anything wrong with your code other than bad practice and 500 is a generic error code. This could be due to a numerous of things such as:

  1. PHP not set up correctly.
  2. Apache/Nginx/etc not set up correctly.
  3. ...

When you have found your specific error you are receiving, then ask a new question.