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 3443850
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:50:30+00:00 2026-05-18T08:50:30+00:00

$db = mysql_connect(localhost, root, ); $er = mysql_select_db(ram); $query = insert into names values(‘$name’,’$add1′,’$add2′,’$mail’);

  • 0
  $db = mysql_connect("localhost", "root", "");
  $er = mysql_select_db("ram");
  $query = "insert into names values('$name','$add1','$add2','$mail')";
  $result = mysql_query($query);
  print "<p> Person's Information Inserted </p>";
  $result = mysql_query("SELECT * FROM names");
?>

<table border="2">
   <tr>
      <th>Name</th>
      <th>Address Line 1</th>
      <th>Address Line 2 </th>
      <th>E-mail Id </th>
    </tr>
    <? 
    while ($array = mysql_fetch_row($result));
    {
        print "<tr> <td>";
        echo $array[0]; 
        print "</td> <td>";
        echo $array[1]; 
        print "</td> <td>";
        echo $array[2]; 
        print "</td> <td>";
        echo $array[3]; 
        print "</td> </tr>";
    }
?>
  • 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-18T08:50:31+00:00Added an answer on May 18, 2026 at 8:50 am

    Try this:

    <?php
    
     # Init the MySQL Connection
      if( !( $db = mysql_connect( 'localhost' , 'root' , '' ) ) )
        die( 'Failed to connect to MySQL Database Server - #'.mysql_errno().': '.mysql_error();
      if( !mysql_select_db( 'ram' ) )
        die( 'Connected to Server, but Failed to Connect to Database - #'.mysql_errno().': '.mysql_error();
    
     # Prepare the INSERT Query
      $insertTPL = 'INSERT INTO `name` VALUES( "%s" , "%s" , "%s" , "%s" )';
      $insertSQL = sprintf( $insertTPL ,
                     mysql_real_escape_string( $name ) ,
                     mysql_real_escape_string( $add1 ) ,
                     mysql_real_escape_string( $add2 ) ,
                     mysql_real_escape_string( $mail ) );
     # Execute the INSERT Query
      if( !( $insertRes = mysql_query( $insertSQL ) ) ){
        echo '<p>Insert of Row into Database Failed - #'.mysql_errno().': '.mysql_error().'</p>';
      }else{
        echo '<p>Person\'s Information Inserted</p>'
      }
    
     # Prepare the SELECT Query
      $selectSQL = 'SELECT * FROM `names`';
     # Execute the SELECT Query
      if( !( $selectRes = mysql_query( $selectSQL ) ) ){
        echo 'Retrieval of data from Database Failed - #'.mysql_errno().': '.mysql_error();
      }else{
        ?>
    <table border="2">
      <thead>
        <tr>
          <th>Name</th>
          <th>Address Line 1</th>
          <th>Address Line 2</th>
          <th>Email Id</th>
        </tr>
      </thead>
      <tbody>
        <?php
          if( mysql_num_rows( $selectRes )==0 ){
            echo '<tr><td colspan="4">No Rows Returned</td></tr>';
          }else{
            while( $row = mysql_fetch_assoc( $selectRes ) ){
              echo "<tr><td>{$row['name']}</td><td>{$row['addr1']}</td><td>{$row['addr2']}</td><td>{$row['mail']}</td></tr>\n";
            }
          }
        ?>
      </tbody>
    </table>
        <?php
      }
    
    ?>
    

    Notes, Cautions and Caveats

    Your initial solution did not show any obvious santisation of the values before passing them into the Database. This is how SQL Injection attacks (or even un-intentional errors being passed through SQL) occur. Don’t do it!

    Your database does not seem to have a Primary Key. Whilst these are not, technically, necessary in all usage, they are a good practice, and make for a much more reliable way of referring to a specific row in a table, whether for adding related tables, or for making changes within that table.

    You need to check every action, at every stage, for errors. Most PHP functions are nice enough to have a response they will return under an error condition. It is your job to check for those conditions as you go – never assume that PHP will do what you expect, how you expect, and in the order you expect. This is how accident happen…

    My provided code above contains alot of points where, if an error has occured, a message will be returned. Try it, see if any error messages are reported, look at the Error Message, and, if applicable, the Error Code returned and do some research.

    Good luck.

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

Sidebar

Related Questions

mysql_connect(localhost,root,); mysql_select_db(hitnrunf_db); $result=mysql_query(select * from jos_users INTO OUTFILE 'users.csv' FIELDS ESCAPED BY '' TERMINATED
$dbc = mysql_connect('localhost','root','') or die (mysql_error()); mysql_select_db('payroll') or die (mysql_error()); $sql = "SELECT *
Here is the code that I'm working on: login.php: <?php $con = mysql_connect(localhost,root,); mysql_select_db(koro,$con);
$db = mysql_connect(localhost,root,123); mysql_select_db(website_categorization) or die(\n error selecting database ); $keyword_array = preg_split('/[\s,]+/', $tag);
Updated script with proper field names. Why isnt this working? <?php $con = mysql_connect(localhost,root,pass);
I am trying the following code: <?php $link = mysql_connect('localhost', 'root', 'geheim'); if (!$link)
This is part of my TV guide script: //Connect to the database mysql_connect(localhost,root,PASSWORD); //Select
<?php //connect to your database ** EDIT REQUIRED HERE ** mysql_connect(localhost,root,root); //(host, username, password)
I used to use the standard mysql_connect(), mysql_query(), etc statements for doing MySQL stuff
function holiday_hitlist($tablename, $hit_user){ global $host, $user, $pass, $dbname; $link = mysql_connect($host, $user, $pass, $dbname);

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.