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

The Archive Base Latest Questions

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

when I try to insert data to my database using PHP, echoing out the

  • 0

when I try to insert data to my database using PHP, echoing out the query, it echoes a query that can be inserted(I inserted the data directly using PHPMyadmin no problems). But still it gave me some errors using php, so i deleted the relation on the DB and tried again, and then i saw what was the issue, but i don’t understand what is causing it.

The Problem

My code:

echo "<b>mysql_query(\"INSERT INTO EncomendaCab(utilizador_id,data_encomenda,data_vencimento, envio_id, pagamento_id, total,obs) VALUES('$cliente_id','$data_e','$data_v', '$envio_id', '$pagamento_id','$total','$obs')\");</b>";

    mysql_query("INSERT INTO EncomendaCab(utilizador_id,data_encomenda,data_vencimento, envio_id, pagamento_id, total,obs) VALUES('$cliente_id','$data_e','$data_v', '$envio_id', 'pagamento_id','$total','$obs')") or die(mysql_error());

My echo:

“mysql_query(“INSERT INTO EncomendaCab(utilizador_id,data_encomenda,data_vencimento, envio_id, pagamento_id, total,obs) VALUES(‘1′,’2012-12-03 11:13:08′,’2013-01-03 11:13:08’, ‘1’, ‘1’,’2400′,’Observações’)”);”

what i get inserted:

+++++++++++++++
+EncomendaCab +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|utilizador_id |   data_encomenda  |  data_vencimento  | envio_id | pagamento_id | total | obs |
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|      1       |2012-12-03 11:13:08|2013-01-03 11:13:08|    1     |       1      |  2400 |Observações|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

So this is for an e commerce site, that is going to receive the orders and get the payment or via Paypal, or postal service or directly in the physical store, the fields you are in Portuguese, so I am translating and explaining them below(some may be straight forward others may not be that easy):

utilizador_id:(int)this is the user id it is the key of the users table.

data_encomenda (order_date)(datetime): this is the date time of the moment when the client(user) submits the form confirming an order.

data_vencimento(datetime): this is equivalent to due date it is a request from “my client”

envio_id(int): this is the kind of shipment that the client of the store can choose(he can ask to send to his house or pick the things in the physical store);

pagamento_id(int): this is the table that stores the king of payments the client can choose(paypal, check, postal service, etc), and is where the problem is, on the echoed query it echoes a 1 or other number of the select element in the form(witch is getting the values from the database), but when is submitting to the database it is replaced with a 0, and caused a “foreign key constraint fails” error. and i don’t understand why…

total(float): this stores the total of the order to display in the back-end,

obs(varchar(500)): this is the observations field where people can ask for things(like: “draw a unicorn on the box”).

thank you for your time…

EDIT:

i forgot the data types, but already added them…

the error message was a foreign key constraint fails but i deleted the relation on the table pagamento now it inserts a zero this means(AFAIK) that the data inserted is invalid, but if it is echoing an integer why isn’t it accepting it, somewhere when the mysql_query() is executed that variable is “corrupted” and i don’t understand where or why…

it is given by a $_POST from the form it maybe important…

  • 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-15T14:04:39+00:00Added an answer on June 15, 2026 at 2:04 pm
    mysql_query("INSERT INTO EncomendaCab(utilizador_id,data_encomenda,data_vencimento, envio_id, pagamento_id, total,obs) VALUES('$cliente_id','$data_e','$data_v', '$envio_id', 'pagamento_id','$total','$obs')") or die(mysql_error());
    

    pagamento_id is the problem because it is not a php variable.

    mysql_query("INSERT INTO EncomendaCab(utilizador_id,data_encomenda,data_vencimento, envio_id, pagamento_id, total,obs) VALUES('$cliente_id','$data_e','$data_v', '$envio_id', '$pagamento_id','$total','$obs')") or die(mysql_error());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to write tests using php for database. I have a table that
I am using SQL to insert data to SQL Database file using C# as
actually I try to insert Chinese data to sqlite3 from ActionScript3 using CGI webservice
I can get data from MySql with use of php using android successfully. But
I want to insert data in MYSQL database using python here my code import
I am trying to INSERT some data in ms access database using jsp but
I've got a PHP script that deletes old data from a database, reads data
I am using PHP to query an Access database on an IIS server using
I have a php file that inserts data to a mysql db using pdo.
When i try to insert the value from the textbox into the database, the

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.