| | |
DB Column contains commas
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Nov 2007
Posts: 23
Reputation:
Solved Threads: 0
I have a mysql database with user input fields. Some of these varchar fields contain commas as part of the data. When I try to display these fields they are treated as arrays and display only the first "element". This occurs both with mysql_fetch_row() and mysql_fetch_array(). I'm chagrined I haven't run into this before, perhaps because commas have generally been limited to text fields. Any help on this would be appreciated.
Scott Holmes
use the function mysql_escape_string();
It will make sure all the characters are escaped and safe to use in a mysql query
escaping a character is adding a \ in front of a character. Eg: \'
Hope that fixes your problem.
It will make sure all the characters are escaped and safe to use in a mysql query
escaping a character is adding a \ in front of a character. Eg: \'
Hope that fixes your problem.
Last edited by FireNet; Dec 16th, 2007 at 4:56 pm.
•
•
Join Date: Nov 2007
Posts: 23
Reputation:
Solved Threads: 0
mysql_escape_string() doesn't solve my problem. The database field (bdyprt varchar(75)) contains the string "Neck, back, shoulders, dizziness and headaches" (I've quoted it here for clarity).
I fetch a row, thus: $res = mysql_fetch_row($this->res); or even as
$this->ap80rec = mysql_fetch_assoc($this->res);
echo $res[4] ; displays Neck
Either mysql or PHP is treating $res[4] as an array and is only giving me the first element.. I'm obviously missing something as phpMyAdmin fetches and displays the string correctly.
I fetch a row, thus: $res = mysql_fetch_row($this->res); or even as
$this->ap80rec = mysql_fetch_assoc($this->res);
echo $res[4] ; displays Neck
Either mysql or PHP is treating $res[4] as an array and is only giving me the first element.. I'm obviously missing something as phpMyAdmin fetches and displays the string correctly.
Scott Holmes
Try peeking inside the row result with something like this.
PHP Syntax (Toggle Plain Text)
echo "<pre>\n"; print_f($this->result); // or whatever the result set var is called. echo "</pre>\n";
•
•
Join Date: Nov 2007
Posts: 23
Reputation:
Solved Threads: 0
As I'd mentioned, it prints the first assumed element in what it thinks is an array (Neck). If I change all the commas in the field to semicolons, the data displays fine. Most of my earlier web app work was done using Postgresql and I don't recall ever having this problem so I rather suspect something on the mysql side. Also, I'm trying this with PHP5 - in case that makes any difference.
$res[4]: Neck; back; shoulders; dizziness and headaches
$res[4]: Neck; back; shoulders; dizziness and headaches
Scott Holmes
![]() |
Similar Threads
- Find Similars? (Visual Basic 4 / 5 / 6)
- Problems with my game... (Python)
- Manipluating Text file (Legacy and Other Languages)
- mysql tutorials (Database Design)
- Formating text to send to spreadsheet..... (Visual Basic 4 / 5 / 6)
- Saving information from .NET Listbox into SQL Server 2000 (ASP.NET)
- Need help fixing a Real10 "Sort By" oddity (Windows NT / 2000 / XP)
- Problem formating VB string for clipboard (Visual Basic 4 / 5 / 6)
- parsing csv file (PHP)
Other Threads in the PHP Forum
- Previous Thread: csv, convert date, mysql, php
- Next Thread: if statements help
| Thread Tools | Search this Thread |
address apache api array auto autoincrement beginner binary broken cache cakephp checkbox class cms code cron curl customizableitems database date dehasher display dynamic echo email error errorlog external file files folder form format forms forum function functions gc_maxlifetime google headmethod host href htaccess html image include incode insert ip javascript joomla limit link login mail malfunctioning masterthesis menu method mlm multiple mysql oop parsing paypal pdf php phpmysql popup problem query question radio random recursion remote script search select server sessions sms source space sql support! survey syntax system table trouble tutorial update upload url validator variable video web youtube





