MySqlTalk.com  

Go Back   MySqlTalk.com > MySQL > SQL syntax
User Name
Password
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
Thread Tools Search this Thread
Old 11-29-2004, 01:35 AM   #1
Azkaban
Senior Member
 
Join Date: Jul 2004
Posts: 167 Azkaban is on a distinguished road
How do you validate data that is in comma delimeted format?

I have data that's coming in like zo:

"123,32,41,234,124,253,342,34,0"

and I want to validate that it is numbers and commas only. Any idea hot to achieve?
Azkaban is offline   Fork this post Reply With Quote
Old 11-29-2004, 02:39 AM   #2
codenode
Member
 
Join Date: Nov 2004
Posts: 31 codenode is on a distinguished road
Re: How do you validate data that is in comma delimeted format?

Validate it in MySQL or in some programming language?
codenode is offline   Fork this post Reply With Quote
Old 11-29-2004, 03:01 AM   #3
Azkaban
Senior Member
 
Join Date: Jul 2004
Posts: 167 Azkaban is on a distinguished road
Re: How do you validate data that is in comma delimeted format?

PHP. But the data will be used in a mysql query. Is it enough to use htmlspecialchars?
Azkaban is offline   Fork this post Reply With Quote
Old 11-29-2004, 03:43 PM   #4
codenode
Member
 
Join Date: Nov 2004
Posts: 31 codenode is on a distinguished road
Re: How do you validate data that is in comma delimeted format?

if(preg_match('/[^\d,]/', $string)) invalid
else valid
codenode is offline   Fork this post Reply With Quote
Old 01-18-2005, 04:49 AM   #5
AllenGarner
Junior Member
 
Join Date: Jan 2005
Posts: 8 AllenGarner is on a distinguished road
Re: How do you validate data that is in comma delimeted format?

if you do something like this you can manipulate the data as you wish

$row = 1;
$handle = fopen($uploadFile, "r");

while ( ($data = fgetcsv($handle, filesize($uploadFile)+1, ",")) != FALSE ) {
$num = count($data);
if($row == 1){
$fields = " `id` , ";
for($i=0; $i<$num; $i++){
$fields .= "`" . addslashes(trim($data[$i])) . "` , ";
}
$fields .= "`group` , `user` , ";
$f = substr($fields, 0, -1);
$f = substr($f, 0, -1);
$row++;
}else{
$values = " '' , ";
for($i=0; $i<$num; $i++){
$values .= "'" . addslashes(trim($data[$i])) . "' , ";
}
$values .= "'personal' , '" . $_SESSION['user'] . "' , ";

$v = substr($values, 0, -1);
$v = substr($v, 0, -1);
$sql = "INSERT INTO $table ( $f ) VALUES ( $v )";
mysql_query($sql) or die(print "<center><font size='2' face='verdana' color='#5E6B79'><b>Upload complete some entries may not have been loaded successfully!</b><br><br><a href='addressbook.php' class='light'>Back to Address Book</a></font></center></td></tr></table>");
$values = '';
$row++;
}
}
fclose ($handle);
AllenGarner is offline   Fork this post Reply With Quote
Old 01-18-2005, 06:00 AM   #6
AllenGarner
Junior Member
 
Join Date: Jan 2005
Posts: 8 AllenGarner is on a distinguished road
Re: How do you validate data that is in comma delimeted format?

just do something like

if (is_numeric($var)){
do something;
}else{
not valid;
}
AllenGarner is offline   Fork this post Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Corruption using navicat webie Navicat Support 1 08-19-2005 02:12 PM
Limiting Data to specific format kfschaefer Database Design 2 12-01-2004 05:05 AM
Import Access, Excel and data of other formats to MySQL by Navicat NavicatGuy Articles 0 08-17-2004 01:08 AM
2 Installing MySQL Administrator Documentation 103 06-09-2004 02:53 AM



All times are GMT -4. The time now is 01:22 PM.



Powered by: vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Google
  Web http://www.mysqltalk.com
DISCLAIMERS:
1. We have no commercial interest in this site.
Banner Ads and Subscriptions will only be used to help pay for hosting and maintenance costs.
2. MySQLTalk.com is NOT affiliated with MySQL AB in any way.
3. MySQLTalk.com is NOT endorsed by MySQL AB in any way.
4. Please do not post any content that is harmful to MySQL or MySQL AB, meaning no misleading or obsolete information will be tolerated.
Well-founded constructive criticism meant to help the community is permitted.
5. This website is founded with the goal of improving the MySQL community.
We not only tolerate newbies, we encourage them.
Please do not ask newbies to "read the manual".