-1

I am able to fully update my SQL using PHP. No connection issues and no errors, so I'm not posting that info.

I simply need help on specifying my update query to not change the column if the new info is NULL.

 $sql4 = "update `Tickets` SET `newowner` ='".$_POST["ownernew"]."' where 
 `referencenumber` ='".$_POST["newref"]."'"; 

I will give some context

  • newowner = the owner of a ticket in my ticketing system ( the column)
  • ownernew = is the field in which my update query pulls from
  • referencenumber = is the column for the unique ticket number, so it knows which row to update , by pulling it from the newref textbox

I currently have a select box , with the ID of ownernew.

However, it has a default selection set, which has no value - so its currently sending nothing to the server and wiping out the current owner.

I want it, so if nothing is selected it doesn't update that one column.

I'm sure that I have to put if null query in there, but I don't know where and how it should go in?

zx485
  • 28,498
  • 28
  • 50
  • 59
  • [Little Bobby](http://bobby-tables.com/) says [**your script is at risk for SQL Injection Attacks**](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). – rollstuhlfahrer Apr 05 '18 at 16:58
  • we need to know what the schema and values are. – Funk Forty Niner Apr 05 '18 at 17:00

1 Answers1

-1

Dont do the Query if you Data not correct

if($_POST["ownernew"] != null) {
    //do sql query
}
beari7
  • 105
  • 2
  • 15