0

I have this update statement:

mysql_query ("UPDATE loan SET  loan_reff_id='$_POST[loan_reff_id]',
commit_date='$_POST[commit_date]',app_loan_type='Tertiary Loan',
app_ln_amnt='$_POST[app_ln_amnt]', institution_name='$_POST[institution_name]',
app_course='$_POST[app_course]',course_length='$_POST[course_length]',
course_cost='$_POST[course_cost]', app_trm_pymnt='$_POST[app_trm_pymnt]',
app_intrst_rate=3
WHERE app_file_id='$_POST[app_file_id]'");

However wen I run the query it says query empty, what do you think might be the problem Im using mysql and php

7
  • @MarcusAdams give a small example please? so you are saying: (example) commit_date='$_POST[commit_date]'..should be? Commented Mar 20, 2012 at 13:05
  • @user1027167 mysql send an error saying:Error: Query was empty Commented Mar 20, 2012 at 13:07
  • send an error to whom? how? which way? this very code you posted here doesn't have to send any errors. Commented Mar 20, 2012 at 13:11
  • @YourCommonSense Im am updating using a php form and when i fill out the textareas and submit the data the error is returned Commented Mar 20, 2012 at 13:19
  • Could it be there's a space between mysql_query and the brackets? Commented Mar 20, 2012 at 13:24

2 Answers 2

1

This one is not empty.
You are getting such an error from some other query.

According this one, to make it sane at the very least,

foreach($_POST as $key => $value) {
  $_POST[$key] = mysql_real_escape_string($value);
}
$sql = "UPDATE loan SET loan_reff_id='$_POST[loan_reff_id]',
commit_date='$_POST[commit_date]',app_loan_type='Tertiary Loan',
app_ln_amnt='$_POST[app_ln_amnt]', institution_name='$_POST[institution_name]',
app_course='$_POST[app_course]',course_length='$_POST[course_length]',
course_cost='$_POST[course_cost]', app_trm_pymnt='$_POST[app_trm_pymnt]',
app_intrst_rate=3
WHERE app_file_id='$_POST[app_file_id]'";

mysql_query($sql) or trigger_error(mysql_error()." in ".$sql);
Sign up to request clarification or add additional context in comments.

Comments

0

You should not use directly $_POST values in your queries, you risk SQL injections, try using PDO. Regarding the empty query, you must have a problem with simple/double quotes and concatenation. Finally, are you sure you do not violate any constraint in your table ? NOT NULL, etc...

2 Comments

could you give a small example on PDO please or recommend a link, what exactly do you mean by simple/double quotes. and now i havnt violated any of the table constraints
<?php $req = $bdd->prepare('UPDATE load SET loan_reff_id = :reff_id, commit_date = :commit_date WHERE app_file_id = :app_file_id'); $req->execute(array( 'reff_id' => $$reffId, 'commit_date' => $commitDate, 'app_file_id' => $appFileId )); ?> PDO will escape strings for you. You need to activate it in you php.ini.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.