Page 1 of 1

[SOLVED]Getting wierd results with mysql_fetch_array

Posted: Mon Jul 18, 2011 11:03 am
by angelicodin
Hey ya guys and gals. I've been working on this CMS for this site and I have hit a wall. It all seems to work well but all of a sudden on this one page the results are coming back wierd.

What I'm doing on this said page is making it so there is an easy to edit box (or other input types) for the user to edit the information on an item in the system, but it's coming back with not the whole field.

Here is what I'm using, as an example, (edited out info of course)

Code: Select all

<? include 'functions.php';
mysql(1); //custom fucntion just to connect to mysql data base
$result = mysql_query("SELECT * FROM `items` WHERE `id` = ".$_POST['id']."");
while($row = mysql_fetch_array($result, MYSQL_BOTH)){	
	echo "<table border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"1\">
	<tr>
	<td><form name=\"form1\" method=\"post\" action=\"items_edit_ac.php\">
	<table width=\"100%\" border=\"1\" cellspacing=\"1\" cellpadding=\"0\">
	<tr>
	<td colspan=\"3\"><strong><div align=\"center\">Edit An Item</div></strong></td>
	</tr>";
	
	echo "<tr>
	<td width=\"71\">Edit Item</td>
	<td width=\"6\">:</td>
	<td width=\"301\"><input name=\"item\" type=\"text\" value=\"".$row['itemname']."\" ></td>
	</tr>";		
	
	echo "<input type=\"hidden\" name=\"id\" id=\"id\" value=\"".$row['id']."\">

	<tr>
	<td colspan=\"3\" align=\"center\"><input type=\"submit\" name=\"Submit\" value=\"Submit\"><input type=\"reset\"><br />Make sure everything is correct before hitting submit</td>
	</tr>

	</table>
	</form>
	</td>
	</tr>
	</table>";
} //end while
?>
Result:

Code: Select all

Apple: 
The example Item I'm using in the database is ' Apple: "Green" ' (minus the single quote marks), but the output is only giving me ' Apple: ' (again with out the single quotes). I have tried to do addslashes(), but that just adds a "/" to the field giving me ' Apple: / '

Really I have no idea what I'm doing wrong. Thoughts?

EDIT: forgot the part in the code that would show the pulling of info into the input field. >_< needs more coffee.

EDIT2: The database table for this field is a varchar(200) and latin1_swedish_ci for the collation.

EDIT3: Playing around with the code some more, is giving me the same result if I set a variable outside the table to something like $item. But if I call the variable outside the table it seems to work fine with the full result but not in the input field. :banghead:

Re: Getting wierd results with mysql_fetch_array

Posted: Mon Jul 18, 2011 12:35 pm
by angelicodin
Just changed my collation for the fields to utf8_unicode_ci and didn't make a difference.

Re: Getting wierd results with mysql_fetch_array

Posted: Mon Jul 18, 2011 12:43 pm
by angelicodin
Ok I figured it out. because the data in the database contains quotes I had to have php make sure the quotes where not being truncated by doing htmlspecialchars($row['itemname'], ENT_QUOTES)

Perhaps this will help someone else out.