Home > Archive > PHP Language > June 2006 > newbie: Need help with my bug
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
newbie: Need help with my bug
|
|
|
| Hey
php4
I have this code on my web page:
echo "<tr><td colspan='2' style='padding-left:15px;'>";
echo "<form action='test.php?type=post' method='post'>";
echo "<label>Your name:</label><br>";
echo "<input name='name' type='text' size='30' /><br>";
echo "<label>Title:</label><br>";
echo "<input name='title' type='text' size='30' /><br>";
echo "<input name='unique_id' type='hidden' value=" . $id . "/>";
echo "<input name='postid' type='hidden' value=" . $_GET["art"] . "/>";
echo "<label>Comments:</label><br>";
echo "<textarea name='comment' cols='57' rows='10'
wrap='physical'></textarea><br>";
echo "<input name='post' type='submit' value='Post
Message'/><label>(test)</label>";
echo "</form>";
echo "</td></tr>";
My problem is that my code above adds an extra character ("/") to the postid
field. If $_GET["art"] has the value 4, then postid field gets the value
4/. Of course I don't want that last char ("/"). But I'm not sure what
causing it...
Any suggestion to solving this bug will be greatly appreaciated!
Jeff
| |
| David Haynes 2006-06-17, 8:04 am |
| Jeff wrote:
> Hey
>
> php4
>
> I have this code on my web page:
> echo "<tr><td colspan='2' style='padding-left:15px;'>";
> echo "<form action='test.php?type=post' method='post'>";
> echo "<label>Your name:</label><br>";
> echo "<input name='name' type='text' size='30' /><br>";
> echo "<label>Title:</label><br>";
> echo "<input name='title' type='text' size='30' /><br>";
> echo "<input name='unique_id' type='hidden' value=" . $id . "/>";
> echo "<input name='postid' type='hidden' value=" . $_GET["art"] . "/>";
> echo "<label>Comments:</label><br>";
> echo "<textarea name='comment' cols='57' rows='10'
> wrap='physical'></textarea><br>";
> echo "<input name='post' type='submit' value='Post
> Message'/><label>(test)</label>";
> echo "</form>";
> echo "</td></tr>";
>
> My problem is that my code above adds an extra character ("/") to the postid
> field. If $_GET["art"] has the value 4, then postid field gets the value
> 4/. Of course I don't want that last char ("/"). But I'm not sure what
> causing it...
>
> Any suggestion to solving this bug will be greatly appreaciated!
>
> Jeff
>
Jeff:
If you ran this thing from the command line (e.g. php this.php), it
would become pretty obvious what the issue is.
If you can't run it from the command line, try adding 'echo <pre>' to
the beginning and 'echo </pre>' to the end.
The bug is in this bit:
value=" . $_GET["art"] . "/>
Notice that value does not have its assigned value in quotes. So, this
runs through the php interpreter as:
value=4/>
which is what you are getting.
Simply wrapping the assigned value will solve this. e.g.
value='".$_GET['art']."'/>";
I have to ask you about all those echos. Why not reverse this bit and do
things like:
<input name="unique_id" type="hidden" value="<?php echo $id;?>">
<input name="postid" type="hidden" value="<?php echo $_GET['art'];?>">
<label>Comments:</label><br>
It saves a lot of typing and reduces all the quote work.
-david-
| |
|
| Thanks, it works great now
"David Haynes" <david.haynes2@sympatico.ca> wrote in message
news:V9jkg.21207$Ab3.2658@fe80.usenetserver.com...
> Jeff wrote:
>
> Jeff:
> If you ran this thing from the command line (e.g. php this.php), it would
> become pretty obvious what the issue is.
>
> If you can't run it from the command line, try adding 'echo <pre>' to the
> beginning and 'echo </pre>' to the end.
>
> The bug is in this bit:
> value=" . $_GET["art"] . "/>
>
> Notice that value does not have its assigned value in quotes. So, this
> runs through the php interpreter as:
>
> value=4/>
>
> which is what you are getting.
>
> Simply wrapping the assigned value will solve this. e.g.
> value='".$_GET['art']."'/>";
>
> I have to ask you about all those echos. Why not reverse this bit and do
> things like:
>
> <input name="unique_id" type="hidden" value="<?php echo $id;?>">
> <input name="postid" type="hidden" value="<?php echo $_GET['art'];?>">
> <label>Comments:</label><br>
>
> It saves a lot of typing and reduces all the quote work.
>
> -david-
>
|
|
|
|
|