mysqli_query() expects at least 2 parameters, 1 given

1Tsme1941

Member
Well hello, I'm just trying to update (add 1) to the "receiptno" field in "numbers"
table and display the new receiptno. At a loss
-------------------------------------------------------
the code:

<?php
//Open a new connection to the MySQL server
require_once "getprerentdb.php";
echo "<center>";echo date('m/d/y');
$id="id";
$receiptno = "receiptno +1";
$sql = "UPDATE numbers SET
receiptno='$receiptno' Where id='".$_POST['id']."'";
mysqli_query($sql) or die(mysql_error());
echo "Record for receiptno ".$_POST["receiptno"]." has been updated";
echo "receiptno ".$_POST["receiptno"]." ";
?>
-----------------------------------------------------------------------------
errors:

Notice: Undefined index: id on line 8

Warning: mysqli_query() expects at least 2 parameters, 1 given on line 9

Fatal error: Uncaught Error: Call to undefined function mysql_error() on line 9
 

1Tsme1941

Member
I really appreciate you guys and the help sometimes but what I'm hearing now is like farts in the wind. I retired from the field long ago and do this to retain grey matter. I would never defeat my purpose by asking b4 researching. Tell me to get lost but what you're telling me is a repeat of what I just read. "Investigate which parameter you're missing from the mysqli_query function since it accepts two parameters", "It tells you the line and the function call that is wrong.", my grandkids could be moderators! I looked up "php mysqli update examples" and copied, printed and spent so much time reading many different examples and why "do" and "don't" that either they don't apply or don't work. Telling me what I've told you? Thanks
 

Cromewell

Administrator
Staff member
You have the line number of the error, the function and the error. Combined with the manual entry above there is more than enough to correct the issue. Looks at your function call and look at how the doc says it should look. It is very clearly different. Which one is missing and should it be first or second?
my grandkids could be moderators
If you feel it would be more helpful, you are welcome to ask them.
I looked up "php mysqli update examples" and copied
Where ever you copied it from is wrong. As written it would have never worked. I suspect you partially converted from an object oriented call, as in previous threads you have been using the mysqli object. However, you also have mixed styles in the same code in previous threads so I cannot be certain.

In any event, you will be better served by coping examples from the php docs. In this case you are using procedural style, the object oriented style would also work. I have mentioned it before, but I will say it again: I do not suggest mixing them. You can, but it makes it awkward to read.
 
Top