Jump to content

please help with query


lingo5

Recommended Posts

Hi,

I have a MySQL query that inserts some values like so:

 

  $insertSQL = sprintf("INSERT INTO t_propiedades (regimen, localidad, isla, tipopropiedad, zona, amueblado, habitaciones, estado, baños, cocina, salon, terraza, aseos, metros, descripcion, precio, precio_oferta, oferta, novedad, destacada) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['regimen'], "text"),
                       GetSQLValueString($_POST['localidad'], "text"),
                       GetSQLValueString($_POST['isla'], "text"),
                       GetSQLValueString($_POST['tipopropiedad'], "text"),
                       GetSQLValueString($_POST['zona'], "text"),
                       GetSQLValueString(isset($_POST['amueblado']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['habitaciones'], "text"),
                       GetSQLValueString($_POST['estado'], "text"),
                       GetSQLValueString($_POST['baos'], "text"),
                       GetSQLValueString($_POST['cocina'], "text"),
                       GetSQLValueString($_POST['salon'], "text"),
                       GetSQLValueString($_POST['terraza'], "text"),
                       GetSQLValueString($_POST['aseos'], "text"),
                       GetSQLValueString($_POST['metros'], "text"),
                       GetSQLValueString($_POST['descripcion'], "text"),
                       GetSQLValueString($_POST['precio'], "double"),
                       GetSQLValueString($_POST['precio_oferta'], "double"),
                       GetSQLValueString(isset($_POST['oferta']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['novedad']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['destacada']) ? "true" : "", "defined","1","0"));

  mysql_select_db($database_MySQLconnect, $MySQLconnect);
  $Result1 = mysql_query($insertSQL, $MySQLconnect) or die(mysql_error());

 

what I want to do is when the $_POST['precio_oferta'] is left blank in the insert form, the value that is already on the DB remains instead of being deleted as it is at the moment.

 

My database sets the valur to 0 by default, but when a record is inserted, the 0 gets deleted and set to blank...which sucks.

 

Thanks

Link to comment
Share on other sites

thanks kays,

yes that's right, I want to do that. I need to check if the "precio_oferta" field is empty. If so, I want the column "precio_oferta" to stay as it is.

How can I do this?...any code eamples?

Thanks

Link to comment
Share on other sites

OK, here's how I did it and it works....

 

GetSQLValueString($_POST['precio_oferta'] ? "'{$_POST['precio_oferta']}'" : "precio_oferta"),

Is this a correct way of doing this?

 

Nope, that'll put the string "precio_oferta" as the value you're setting it to.  Try this:

 

strlen($_POST['precio_oferta']) ? GetSQLValueString($_POST['precio_oferta']) : "`precio_oferta`",

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.