473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

small problem with spaces

Here's the snip:

<?php
// edit records directly ask for authorisation first-->later

include "../includes/db_connect.php";
$id=$_GET["rec"];
$qry="SELECT * FROM eame WHERE id=$id";
$res=mysql_query($qry);
if(!$res)die("something not right");
$data=mysql_fetch_array($res, MYSQL_ASSOC);
?>

<FORM action="edit.php" method="post">
Project Title: <INPUT TYPE="text" maxlength=100 width=40 value=<? print
$data["pros"]; ?>>

Here's the problem:

$data["pros"] contains "This is a project title"

Displayed in the input field: This

everything starting from the space is stripped.

What can I do to prevent this from happening?

thanks,

Mich

Jul 17 '05 #1
5 1714
*** michel wrote/escribió (Fri, 9 Jul 2004 13:59:32 +0200):
$data["pros"] contains "This is a project title"

Displayed in the input field: This


Oh, come on, this is simple HTML ;-)

<INPUT TYPE="text" maxlength=100 width=40 value=This is a project title>
<INPUT TYPE="text" maxlength=100 width=40 value="This is a project title">
To make it even more robust, I suggest you escape the string using
htmlentities().

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #2
michel wrote:
What can I do to prevent this from happening?


Follow HTML syntax :-)

.... and delimit strings with spaces between single or double quotes

<input value="string with spaces"/>

--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #3
Project Title: <INPUT TYPE="text" maxlength=100 width=40 value=<? print
"\"".$data["pros"]."\""; ?>>

Thanks, myself :0

"michel" <no@spam.please> wrote in message
news:cc**********@news.cistron.nl...
Here's the snip:

<?php
// edit records directly ask for authorisation first-->later

include "../includes/db_connect.php";
$id=$_GET["rec"];
$qry="SELECT * FROM eame WHERE id=$id";
$res=mysql_query($qry);
if(!$res)die("something not right");
$data=mysql_fetch_array($res, MYSQL_ASSOC);
?>

<FORM action="edit.php" method="post">
Project Title: <INPUT TYPE="text" maxlength=100 width=40 value=<? print
$data["pros"]; ?>>

Here's the problem:

$data["pros"] contains "This is a project title"

Displayed in the input field: This

everything starting from the space is stripped.

What can I do to prevent this from happening?

thanks,

Mich

Jul 17 '05 #4
On Fri, 9 Jul 2004 13:59:32 +0200, "michel" <no@spam.please> wrote:
Here's the snip:

<?php
// edit records directly ask for authorisation first-->later

include "../includes/db_connect.php";
$id=$_GET["rec"];
$qry="SELECT * FROM eame WHERE id=$id";
You may want to cast $_GET["rec"] to an int to prevent SQL injection
attacks.
$res=mysql_query($qry);
if(!$res)die("something not right");
$data=mysql_fetch_array($res, MYSQL_ASSOC);
?>

<FORM action="edit.php" method="post">
Project Title: <INPUT TYPE="text" maxlength=100 width=40 value=<? print
$data["pros"]; ?>>


The outputted HTML will say:

<INPUT TYPE="text" maxlength=100 width=40 value=This is a project
title>

The browser interprets the space after This as the end of the value
attribute.

Put quotes around your value and use htmlentities() to convert " to
&quot;

--
David ( @priz.co.uk )
Jul 17 '05 #5
On Fri, 09 Jul 2004 14:14:22 +0200, michel wrote:
Project Title: <INPUT TYPE="text" maxlength=100 width=40 value=<? print
"\"".$data["pros"]."\""; ?>>

Thanks, myself :0


Well, "yourself" just made your life more difficult. Why not just do this:

<INPUT TYPE="text" maxlength=100 width=40 value="<? print $data["pros"];?>">

In other words, put the HTML quotes in the HTML, like everything else is?
Then you (1) don't have to escape the quotes with a backslash and (2)
don't have the added ugly concatenation stuff.

I highly recommend you take the quotes out and put them in the HTML, where
they belong.

Actually, I have a third suggestion: use single quotes around the "pros"
key, like so:

$data['pros']

It doesn't matter super-too-much but single quotes around array keys ends
up making my life easier because there is no need to escape double quotes
in double quoted strings.

There you are. More information than you asked for. later...

--
Jeffrey Silverman
je*****@pantsjhu.edu
Drop "pants" to reply by email

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ruben | last post by:
Hello. I am trying to read a small text file using the readline statement. I can only read the first 2 records from the file. It stops at the blank lines or at lines with only spaces. I have a...
8
by: Mike S | last post by:
Hi all, I noticed a very slight logic error in the solution to K&R Exercise 1-22 on the the CLC-Wiki, located at http://www.clc-wiki.net/wiki/KR2_Exercise_1-22 The exercise reads as...
13
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those...
6
by: =?Utf-8?B?Q2hpV2hpdGVTb3g=?= | last post by:
hi all on our IIS6 we tried to update the asp version of a particular website from 1.1 to 2.0. Leaving other sites on the same server as ASP version 1.1 But when we go to the client and check...
2
by: shror | last post by:
I need help in a small problem, I have created a registration form and I want my users not leave the username empty or even enter any number of spaces because sometimes I found that the users...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.