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

The Archive Base Latest Questions

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

In a php script, I’ve attempted an insert statement several different ways: $query =

  • 0

In a php script, I’ve attempted an insert statement several different ways:

$query = "INSERT INTO table (charfield,charfield,intfield,decimalfield) VALUES ('$stringvar','$stringvar',$intvar,$decimalvar)";
$query = "INSERT INTO table (charfield,charfield,intfield,decimalfield) VALUES ('".$stringvar."','".$stringvar."',".$intvar.",".$decimalvar.")";
$query = 'INSERT INTO table (charfield,charfield,intfield,decimalfield) VALUES ("'.$stringvar.'","'.$stringvar.'",'.$intvar.','.$decimalvar.')';
$query = 'INSERT INTO table (charfield,charfield,intfield,decimalfield) VALUES ("'.$stringvar.'","'.$stringvar.'","'.$intvar.'","'.$decimalvar.'")';

I’ve executed it several different ways too using combinations of these:

mysql_real_escape_string($query);
mysql_query($query);
$result = @mysql_query($query);

I’ve echo’d out the statement that is being concatenated and it looks fine. Even if I copy and paste that into phpmyadmin sql editor, it executes fine. The database is MySQL and the user has the correct permissions.

What am I doing wrong?


EDIT:

Error message using or die:

Access denied for user 'schaffins'@'localhost' (using password: NO)

I’ve added a user with the rights to select, insert, and update and I’m connecting using that user in the php before executing anything.

Also, I was able to insert into another table I made in the same script.

  • 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-04T02:04:46+00:00Added an answer on June 4, 2026 at 2:04 am

    Sometimes the database connection happens only after certain actions &| validations take place. Make sure you have an open connection before attempting to execute any sql. If the connection is nested within an if/else code block, the conditions may not be satisfied and the db connection will not be established.

    Try finding the db connection and moving (or copying) to a more ‘globalized’ location within the php – aka somewhere in the php that ensures the db connection is made before any if statements that might exclude the connection from being established based on conditionals that aren’t allowing

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

Sidebar

Related Questions

My php script won't work if i try to insert into database something in
My PHP script generates a table with rows which can optionaly be edited or
I have a php script that backup my table in .sql format and I
I have a PHP script that runs a SELECT query then immediately deletes the
My php script should validiate address of websites, that user type into the form.
I have small PHP script which has $query = SELECT MAX(id) FROM `dbs`; //query
In PHP-script i need to update title, content fields. If I put @ into
The php script is calling four functions that scrape different websites for data. $returnData[0]=getWebsite1Data($description);
A PHP script is generating the following table panel based on the data from
I have a php script which is editing records in mysql table. I have

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.