[PHP]Weird **** with an <input> box :S [solved

Joined
Jul 26, 2006
Messages
3,626
Reaction score
1,006
So, I got this:
PHP:
                        	<?php
								if($row['shop_name'] == "N/A")
								{
									$the_shop_name = unc($row['ign'] ."'s Shop");
								}
								else
								{
									$the_shop_name = unc($row['shop_name']);
								}
							?>
                            <form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
                        	<input type="text" value="<?=$shop_name;?>" name="shop_name" class="bigbox text" maxlength="40" /> //no worky
Yes, I've tried <?php echo $shop_name; ?> instead of the quick tags.

unc() (the reverse of mysql_real_escape_string)
PHP:
	function unc($string)
	{
		$cms = array("\\\"", "\\'");
		$rms = array("\"", "'");
		$tstring = $string;
		for($i = 0; $i < count($cms); $i++)
		{
			if(strstr($tstring, $cms[$i]))
			{
				$tstring = str_replace($cms[$i], $rms[$i], $tstring);
			}
		}
		
		return $tstring;
	}

I know some stuff can be done more efficient but that's not my question here.
The weird thing is, that if I just echo the $shop_name, it prints it out neatly, without any backslashes still in it, etc.
Now, when I put the $shop_name in the value="" of my input tag, it only prints out this:
Code:
X 00 X's //note the extra space!
//of what has to say:
X 00 X's "Donator & Others" Shop

I have tried several things but I can't get my head around it.
Thanks,

~Elite.

EDIT:
Even making it a type="hidden" works. Something fishy is going on :S
I've now changed it to a <textarea> that matches the size of just one text line. This is my desperate solution lol.
 
Last edited:
Re: [PHP]Weird **** with an <input> box :S

Ohhh wait, are you trying to put quotes in the value of a textfield?


You need to use htmlspecialchars() on it. The quote is closing the value attribute. I think..

Also, why not use stripslashes instead of unc()?
 
Last edited:
Re: [PHP]Weird **** with an <input> box :S

Or you can just use Textarea, yeah.. this works with the form! just place it before </form>

PHP:
<textarea name="shop_name" rows="2" cols="20" maxlength="40"><?=$shop_name;?></textarea>

;)
 
Last edited:
Re: [PHP]Weird **** with an <input> box :S

Ohhh wait, are you trying to put quotes in the value of a textfield?


You need to use htmlspecialchars() on it. The quote is closing the value attribute. I think..

Also, why not use stripslashes instead of unc()?

I should have deleted this thread yesterday, I fixed it like 20mins after posting.
I took a look at the source in FF and indeed, the double quotes were messing with the tags. Fixed now.
Also using stripslashes already.
 
Re: [PHP]Weird **** with an <input> box :S

then my Textarea didnt help anything? :(

and anyways, if your going to use textarea later..

this code should be added if you need maxlenght:

PHP:
<script language="javascript" type="text/javascript">
<!--
function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}
-->
</script>

<textarea name="shop_name" rows="2" cols="20"  onkeypress="return imposeMaxLength(this, 40);"><?=$shop_name;?></textarea>
 
Last edited:
Re: [PHP]Weird **** with an <input> box :S

then my Textarea didnt help anything? :(

and anyways, if your going to use textarea later..

this code should be added if you need maxlenght:

PHP:
<script language="javascript" type="text/javascript">
<!--
function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}
-->
</script>


<textarea name="shop_name" rows="2" cols="20"  onkeypress="return imposeMaxLength(this, 40);"><?=$shop_name;?></textarea>

Or you could use the maxlength attribute directly in the textarea,
Code:
<textarea maxlength="40"></textarea>

Come on man, think simpler :thumbup1:

The Web Development state of mind should be to create the simplest solution to any and every problem. You're a great problem solver, just use your problem solving a little more constructively and you'll be a full package ;)

Well there's always a little learning curve involved, but I can see it now..

Emineem, The Web Developer...

Keep working on it :8:
 
Back