Now Place:2uzhan.com » SQL Update. Help needed.

SQL Update. Help needed.

PHP @ January 3, 2003   Views:0

Hi again, the maths bit is now working, but i have another problem.

When people submit the form it calculates the values i need, but when i check my table, it has updated every row. (prolly cos i said WHERE email='$email', so that makes them all the same.

Any ideas how i can make it simply update the current row pls?
Heres my code;

PHP Code:



mysql_connect (localhost,elliott,password);
mysql_select_db ("quote");
mysql_query ("insert inTO main (applicant_id, firstname, surname, situation, title, dob, address, postcode, time_at_address,
 previous_address, phone, work_phone, email, contact_time, employment, occupation, contract_length, service_length, accounts,
income_2001, income_2000, income_1999, income1, income2, total_income, ccj, ccj_details, bankruptcy, arrears, details,
lender, mortgage_outstanding, property_sold, loans_outstanding, monthly_payment, loan_expires, cards, cards_outstanding,
property_price, mortgage_req, mortgage_reason, urgency, other_info)

VALUES ('$_GET[applicant_id]', '$_GET[firstname]', '$_GET[surname]', '$_GET[situation]', '$_GET[title]', '$_GET[dob]',
'$_GET[address]', '$_GET[postcode]', '$_GET[time_at_address]', '$_GET[previous_address]', '$_GET[phone]', '$_GET[work_phone]',
'$_GET[email]', '$_GET[contact_time]', '$_GET[employment]', '$_GET[occupation]', '$_GET[contract_length]',
'$_GET[service_length]', '$_GET[accounts]', '$_GET[income_2001]', '$_GET[income_2000]', '$_GET[income_1999]',
'$_GET[income1]', '$_GET[income2]', '$_GET[total_income]', '$_GET[ccj]', '$_GET[ccj_details]', '$_GET[bankruptcy]',
'$_GET[arrears]', '$_GET[details]', '$_GET[lender]', '$_GET[mortgage_outstanding]', '$_GET[property_sold]', '$_GET[loans_outstanding]',
'$_GET[monthly_payment]', '$_GET[loan_expires]', '$_GET[cards]', '$_GET[cards_outstanding]', '$_GET[property_price]', '$_GET[mortgage_req]',
'$_GET[mortgage_reason]', '$_GET[urgency]', '$_GET[other_info]')

mysql_connect (localhost, elliott, password);
mysql_select_db ("quote");
mysql_query ("UPDATE main SET mortgage_quote='$total_income'*3/0.95 WHERE applicant_id='$applicant_id'");



Thanks if you can help


i think you forgot to close "" at the end of the first paragraph

ah yeah, all the code has been changed since then, so it all works.

The problem is still there that i dont know how to make it update THIS row. At the moment its updating every row in the table, but i dont know what to put after the WHERE to make it update the current record.

i dont understand what youre trying to say.
also you should set $total_income and $applicant_id without '' beacaus its a number, strings on the other hand need ''

ok im my table i have the above fields, and a final field called 'mortgage_quote'.

When a user fills in the form on the website the php file then sticks all the form variables into the SQL table.

For the final field to be completed a calculation needs to be done.

The calculation needs to be total_income*3/0.95

This then needs to be stored in the mortgage_quote field on the same row as the other details.

If i make it an INSERT, it puts a new row in, so i used UPDATE, and this works, but i need to make it work only on the one row.

At the moment it seems to be updating the final field in every row on the table.

This sux, cos once ive done this i need to call it back and make it display on the next screen to show the user the result of the quote.

if i correctly understand your question try doing this:

$variable = $total_income*3/0.95;

and then
echo $variable;
mysql_connect (localhost, elliott, password);
mysql_select_db ("quote");
mysql_query ("UPDATE main SET mortgage_quote='$total_income'*3/0.95 WHERE applicant_id='$applicant_id'");


Thanks that sorta worked, but its still not putting a value into my mortgage_quote field.

The echo thing works, but do u know how it is possible for me to go to a specific link after i submit the form?

right at the end of all that
put either this

header ("Location: linkpage.php");

or this:

echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<title>Adding entry. Please wait.</title>
<meta http-equiv='refresh' content='0;URL='linkpage.php'>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<body>Message here<br>If this page doesn't refresh click <a href='index.php'>HERE</a>

hmmmm well its further than i got towards opening another page...but i got this

Warning: Cannot add header information - headers already sent by (output started at /usr/local/psa/home/vhosts/aptfinance.co.uk/httpdocs/apt/quote.php:4) in /usr/local/psa/home/vhosts/aptfinance.co.uk/httpdocs/apt/quote.php on line 46

i have a page called results.htm with a basic table in it to output the Firstname, Surname Email Address and the mortgage quote.

is it possible to go to this html file?

i dont remeber what that header error means, try the second option. echo this at then end of the script, right before ?>

echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<title>Updating. Please wait.</title>
<meta http-equiv='refresh' content='0;URL='results.php'>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<body>Message here<br>If this page doesn't refresh click <a href='results.php'>HERE</a>

ok i tried that one, and it seems to be in a loop, constantly refreshing the page. ( i bet ive got hundreds of rows in the table now )

its not opening the results.htm unless i click the cl;ick here link.

sorry about that, the tag is supposed to go like this:

<meta http-equiv='refresh' content='0;URL=results.php'>

'0;URL=results.php' must be all in the same pair of '

nice one hermzz thanks, it now goes to the results.htm page.

Now another question

Now i have this page up, how can i display their firstname, surname, email and then the quote?

I have a page layed out like


Here is your Quote:

And want it to display the values from the table that they just submitted.

hmm.. im not sure, try at the results page to echo the variables you got before, like

PHP Code:

echo "Firstname: ";
echo $_GET[firstname]; 

ah been waiting for you

and once again uve sorted my problem

Thanks for all your help m8, over past few days

© 2018 2uzhan.com Contact