Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6391785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:43:57+00:00 2026-05-25T03:43:57+00:00

<?php $dbserver=localhost; $username=root; $pass=root; $link=mysql_connect($dbserver,$username,$pass); if(!$link){die(‘DB Connection Failed’.mysql_error()); } echo(‘connected’); $Name=$_POST[namei]; $ID=$_POST[pid]; $Address=$_POST[address]; $Phone=$_POST[phone];

  • 0
<?php

$dbserver="localhost";
$username="root";
$pass="root";

$link=mysql_connect("$dbserver","$username","$pass");
if(!$link){die('DB Connection Failed'.mysql_error()); }
echo('connected');
    $Name=$_POST["namei"];
    $ID=$_POST["pid"];
    $Address=$_POST["address"];
    $Phone=$_POST["phone"];

    $query="INSERT INTO contact(Name,ID,Address,Phone) VALUES('".$Name."',".$ID.",'".$Address."',".$Phone.");";

    echo($query);



?>

The code above is used by me to connect to a mysql db, i’m posting the contents to this page from an html page. As i checked there is no problem with POST. but on click of submit it gives me an error ‘500 Internal Server Error’.

I’m using Apache 2.2 Server, and mysql 5.5.

Can any one tell what is my mistake?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:43:57+00:00Added an answer on May 25, 2026 at 3:43 am

    First please run

    <?php
    echo 'phpversion: ', phpversion(), "<br />\n";
    if ( !extension_loaded('mysql') ) {
        die('mysql module not available');
    }
    echo 'mysql_get_client_info: ', mysql_get_client_info(), "<br />\n";
    die;
    

    to check whether a) you can run any php script and b) the mysql_* functions are available.
    Then try

    <?php
    echo "start<br />\n";
    error_reporting(E_ALL);
    ini_set('display_errors', true);
    flush();
    
    $dbserver="localhost";
    $username="root";
    $pass="root";
    
    $link=mysql_connect($dbserver, $username, $pass);
    if(!$link) {
        die('DB Connection Failed '.mysql_error());
    }
    echo "connected<br />\n";
    if ( !mysql_select_db('dbname here', $link) ) {
        die('DB selection failed. '.mysql_error($link));
    }
    echo "db selected<br />\n";
    
    $Name = mysql_real_escape_string($_POST['namei'], $link);
    $ID = mysql_real_escape_string($_POST['pid'], $link);
    $Address = mysql_real_escape_string($_POST['address'], $link);
    $Phone = mysql_real_escape_string($_POST['phone'], $link);
    
    $query = "
        INSERT INTO
            contact
            (Name,ID,Address,Phone)
        VALUES
            ('$Name', '$ID','$Address','$Phone')
    ";
    echo '<pre>Debug: query=', htmlentities($query), "</pre>\n"; 
    

    It prints something in any case (echo/flush) and sets error_reporting + display_errors so that error messages are sent to the client (you don’t want that in production, don’t forget to remove those lines).
    I also added the necessary calls to mysql_select_db() and mysql_real_escape_string() (needed as soon as the script really sends the query to the mysql server).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's wrong with this class? <?php class myClass { private $dbServer = 'localhost'; private
Crazy right? Sample code: <?php session_start(); $hostname=samplehost; $username=sampleuser; $password=samplepass; $dbname=sampledb; $link = mysql_connect($hostname, $username,
I have the following php code : $db_host = localhost; $db_user = root; $db_pass
PHP has a great function called htmlspecialcharacters() where you pass it a string and
PHP's explode function returns an array of strings split on some provided substring. It
PHP, as we all know is very loosely typed. The language does not require
PHP stores its session information on the file system of the host of the
PHP treats all arrays as associative, so there aren't any built in functions. Can
PHP has a number of opcode caches, which as i understand it are scripts
PHP 4.4 and PHP 5.2.3 under Apache 2.2.4 on ubuntu. I am running Moodle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.