• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Any PHP mysqli experts?

Yeh, didn't use foobar. Where does foobar come from? And that ipse lorum ... or something like that you always see in examples. I always use rude words in my test data, much easier. Anyway, thanks again.
 
Ah! I didn't see the relevance of your comment initially but you've sorted it for me, I just updated each item individually and it worked.

$sql = $con->query("UPDATE whlist SET date='$date' WHERE id=$id");
$sql = $con->query("UPDATE whlist SET title='$title' WHERE id=$id");
$sql = $con->query("UPDATE whlist SET speaker='$speaker' WHERE id=$id");
$sql = $con->query("UPDATE whlist SET description='$description' WHERE id=$id");

$con->error still showing same error message but I'll just comment that out.

Thanks woody1

Can't understand why I never had this problem before in my business website, got lots of far more complicated update lines. Maybe some property of the table?

That's a pretty flaky approach, inefficient and no transactional integrity, what happens if the date update works but title doesn't? Do it as a single atomic UPDATE.

Also how are the $vars sanitized? What if $id became "1; DELETE FROM whlist"?
 
Cheers TGB. I do sanitise, remove quotes etc, and check if update worked but didn't put those lines here to keep it simple. As per post I would normally do a single update line but not working here for some reason, my flaky aproach only one that worked. Not a site of any importance anyway.

PS Not quite sure what atomic is, have to have a Google.
PPS Nice cartoon. xkcd: Exploits of a Mom
 
Last edited: 11:35
That's a pretty flaky approach, inefficient and no transactional integrity, what happens if the date update works but title doesn't? Do it as a single atomic UPDATE.
Agreed, this makes any db dev want to weep
 
You said your solution is working? Are you sure it is? ie. is it actually inserting the values of variables $date, $title etc, or is it inserting the string values "$date", "$title" etc.

Here's what i think it should be (typed from memory, not tested). The {} inserts the variables into the query string.

PHP:
$sql = $con->query("UPDATE whlist SET date='{$date}', title='{$title}', speaker='{$speaker}', description='{$description}'
WHERE id={$id}");


The above assumes id is numeric key, otherwise

PHP:
$sql = $con->query("UPDATE whlist SET date='{$date}', title='{$title}', speaker='{$speaker}', description='{$description}'
WHERE id='{$id}'");


If you're still getting errors, do

PHP:
print_r($sql);


To show you what the raw SQL being executed is.
 
Last edited: 15:18
Thanks all but no need for any more solutions, it's just a little local history website, form will only be used by me and maybe 2 other people. Working ok at mo.

I do have a much more complicated small businesss website with checkout, one of the lines here, (daddress = sanitised version of address etc.) works fine:

$sql = $con->query("UPDATE shop SET name='$dname',school='$dschool',address='$daddress ',postcode='$postcode',country='$country',
tel='$tel',email='$email',comment='$dcomment' WHERE custid = '$custid'");
if ($sql === FALSE)
{
echo "Error: " . $sql . "<br>" . $con->error;
echo "Update cust 1 failed";
}

Just that that aproach with multiple items did not work in the little history thing, dunno why.
 
Last edited: 18:33

Advertisers

Back
Top