Solved

if $new_input is empty do not update

Posted on 2013-01-18
4
230 Views
Last Modified: 2013-01-20
using php to update $new_input to varchar column

if $new_input is empty do not update


this has to be writen in mysql not php
0
Comment
Question by:rgb192
  • 2
4 Comments
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 200 total points
ID: 38794136
This would require a conditional statement and this function,
http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_length

Wouldn't that be easier if you'd check the variable from php ?
0
 

Author Comment

by:rgb192
ID: 38794334
I understand length
SELECT LENGTH('text');
http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_length


but do not understand how to do conditional statement


the if in php would be too complex
I would rather do in mysql so I can test in query editor
0
 
LVL 2

Accepted Solution

by:
EndreCz earned 300 total points
ID: 38796374
You need something like this:

UPDATE table SET column='$new_input' WHERE LENGTH('$new_input')>0
0
 

Author Closing Comment

by:rgb192
ID: 38799841
the former introduced length and the latter applied length and a conditional statement to a sample query. Thank you.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question