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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:00:29+00:00 2026-06-04T14:00:29+00:00

I have a database test with table name table with two columns user &

  • 0

I have a database test with table name table with two columns user & email.
Whats wrong with my below code? Am not able to add the array $u to my db

<?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }

    mysql_select_db("test", $con);

    $user = "safwan";
    $email = "esafw@jdjd.com";

    $u = array ( user => $user,
                    email => $email
                   );

    $q =   "INSERT INTO table  VALUES ($u)";

    mysql_query($q) OR die(mysql_error());

    mysql_close($con);
    ?> 
  • 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-06-04T14:00:31+00:00Added an answer on June 4, 2026 at 2:00 pm

    You have a couple of issues:

    1. You’re trying to insert an array directly into your database. You need to be accessing the values individually.

    2. You should use quotes around strings, that includes when they are keys in an array

    3. You need to learn about SQL injections

    4. You should consider migrating away from mysql_* functions since they will soon be going away.

    5. table is a MySQL keyword and needs backticks if it’s actually the table name

      $user,
      ’email’ => $email
      );

      $q = “INSERT INTO table (user, email) VALUES (‘”.mysql_real_escape_string($u[‘user’]).”‘, ‘”.mysql_real_escape_string($u[’email’]).”‘)”;

      mysql_query($q) OR die(mysql_error());

      mysql_close($con);
      ?>

    Or:

    <?php
        $con = mysql_connect("localhost","root","");
        if (!$con)
          {
          die('Could not connect: ' . mysql_error());
          }
    
        mysql_select_db("test", $con);
    
        $user = "safwan";
        $email = "esafw@jdjd.com";
    
        $q =   "INSERT INTO table (user, email) VALUES ('".mysql_real_escape_string($user)."', '".mysql_real_escape_string($email)."')";
    
        mysql_query($q) OR die(mysql_error());
    
        mysql_close($con);
        ?>         
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
Let's say I have two database instances: InstanceA - Production server InstanceB - Test
I have here java code accessing mySQL database. It checks if table exists. The
I have a database with two tables, events and tickets . The events table
i have created a database called test and create a table called biodata. I
I have following databases: test table1 fields: id, password, name, lastname test2 table2 fields:
For our test fixtures we use NHibernate to generate a database schema. We have
I have the following data in my database (comma separated strings): word, test, hello
I have a simple web service that uses an oracle database. When I test
I know I have that my connection to the database works, and a test

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.