Page 2 of 2

Re: edit profile php

Posted: Wed Jul 01, 2015 10:12 am
by Celauran
No. You're going to need four separate queries; one to update users and one for each row of renewal that needs updating. The where clause is going to be different for each.

Re: edit profile php

Posted: Wed Jul 01, 2015 10:39 am
by Celauran
No joins required. One update on users table, three on renewals table (one for each item)

Re: edit profile php

Posted: Wed Jul 01, 2015 11:51 am
by Celauran

Code: Select all

$query = "Update users SET name='$name', email='$email', address1='$address1', address2='$address2', town='$town', county='$county', postcode='$postcode', telnumber='$telnumber', mobnumber='$mobnumber', model='$model', numplate='$numplate' WHERE id='$id';";

$sql = "UPDATE renewal SET id='$id', renewal_date='$insurance' WHERE item_id=1 LIMIT 1;";

$sql = "UPDATE renewal SET id='$id', renewal_date='$mot' WHERE item_id=2 LIMIT 1;";
These three queries never get executed.

Re: edit profile php

Posted: Wed Jul 01, 2015 11:52 am
by Celauran

Code: Select all

$sql = "UPDATE renewal SET id='$id', renewal_date='$insurance' WHERE item_id=1 LIMIT 1;";

$sql = "UPDATE renewal SET id='$id', renewal_date='$mot' WHERE item_id=2 LIMIT 1;";

$sql = "UPDATE renewal SET id='$id', renewal_date='$tax' WHERE item_id=3 LIMIT 1;";
The ID for these is already set, so you probably don't want to change that. What you'd want to do is add the ID to your where clause so you can ensure you're updating the record belonging to the correct user.

Re: edit profile php

Posted: Wed Jul 01, 2015 11:53 am
by Celauran
it leaves the tax date empty
Have you checked the value of $tax before executing the query? Does it contain a value? Is it formatted correctly?

Re: edit profile php

Posted: Wed Jul 01, 2015 1:50 pm
by Celauran

Code: Select all

$sql2 = "UPDATE renewal SET renewal_date='$insurance' WHERE item_id=1 LIMIT 1;";

$query2 = mysqli_query($db, $sql2) or die (mysqli_error($db));

$sql3 = "UPDATE renewal SET renewal_date='$mot' WHERE item_id=2 LIMIT 1;";

$query3 = mysqli_query($db, $sql3) or die (mysqli_error($db));

$sql4 = "UPDATE renewal SET renewal_date='$tax' WHERE item_id=3 LIMIT 1;";

$query4 = mysqli_query($db, $sql4) or die (mysqli_error($db));
This will come back to bite you when you have more than one user.