tallberg Posted November 21, 2006 Share Posted November 21, 2006 I have a recurring problem i hope some kind sol can help with.Below is a query that inserts a $condition variable into a db.$dbList = mysql_query("INSERT INTO query VALUES ('','$condition')", $dbLocalhost) or die("Problems writing to the datbase table drawer" . mysql_error());The problem is: The condition variable is typically a string containing commas such as: The_Group='Aplines'php reads the first comma surrounding Alpines and thinks it is the end of the feild. The other example of where this is problem:<input type='hidden' name='condition' value='$conditiion'>The $condition can not be pass to the $_POST array because it understand the comma is the $condition string variable as the end of the value. Link to comment https://forums.phpfreaks.com/topic/28005-problem-passing-variable-with-commas-in-the-string/ Share on other sites More sharing options...
kenrbnsn Posted November 21, 2006 Share Posted November 21, 2006 Those are not commas, they are single quotes. You need to use the function [url=http://www.php.net/mysql_real_escape_string]mysql_real_escape_string()[/url] on the values before they are inserted to escape these characters.[code]<?php$dbList = mysql_query("INSERT INTO query VALUES ('','" . mysql_real_escape_string($condition) . "')", $dbLocalhost) or die("Problems writing to the datbase table drawer" . mysql_error());?>[/code]The solution to your other problem is easier. Use double quotes to enclose the value:[code]<?phpecho '<input type="hidden" name="condition" value="' . $conditiion . '">';?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/28005-problem-passing-variable-with-commas-in-the-string/#findComment-128109 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.