Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6650933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:57:02+00:00 2026-05-26T00:57:02+00:00

When Im trying to validate my PHP output data my echo string puts a

  • 0

When Im trying to validate my PHP output data my echo string puts a <br /> after the tag, how can I prevent this ?

as you see in the first row after background-color: an
shows up from no where and it’s screwing up my validatation.

Im trying to validate in Transitional

This is my entire script

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>Visitkort</title> 

<style type="text/css">
body {
    background-color:#efefef;
}

#kort{
position:absolute;
margin-top:30px;
padding-left:5px;
padding-right:25px;
margin-left:450px;
background-color:<?php echo($_POST['color']);?>;
color:<?php echo($_REQUEST['fontcolor']);?>;
font-family: <?php echo($_REQUEST['typsnitt']);?>;
}
</style>

</head>

<body>


<form id="form" method="post" action="visitkort.php">
<table width="300">
<tr>
<td>Företag: </td>
<td>    
<input type="text" name="enterprise" id="enterprise" value="<?php echo isset($_POST['enterprise']) ? $_POST['enterprise'] : '' ?>" />
</td>
</tr>
<tr>
<td>
Efternamn: </td>
<td>
<input type="text" name="lastname" id="lastname" value="<?php echo isset($_POST['lastname']) ? $_POST['lastname'] : '' ?>"/>
</td>
</tr>
<tr>
<td>namn: </td>
<td>
<input type="text" name="namn" id="namn" value="<?php echo isset($_POST['namn']) ? $_POST['namn'] : '' ?>"/>
</td>
</tr>
<tr>
<td>
Title:</td>
<td> 
<input type="text" name="title" id="title" value="<?php echo isset($_POST['title']) ? $_POST['title'] : '' ?>"/>
</td>
</tr><tr>
<td>
Phone:
</td>
<td> 
<input type="text" name="phone" id="phone" value="<?php echo isset($_POST['phone']) ? $_POST['phone'] : '' ?>"/>
</td>
</tr><tr>
<td>
E-mail:
</td>
<td>
<input type="text" name="mail" id="mail" value="<?php echo isset($_POST['mail']) ? $_POST['mail'] : '' ?>"/>
</td>
</tr><tr>
<td>
Typsnitt:
</td>
<td>
<select id="typsnitt" name="typsnitt">
<option value="Verdana">Verdana</option>
<option value="Arial">Arial</option>
<option value="Tahoma">Tahoma</option>
<option value="Impact">Impact</option>
</select>
</td>
</tr><tr>
<td>
Bakgrundsfärg: 
</td>
<td>
<select name="color" id="color">
<option value="#799ef1" 
<?php if(isset($_POST['color']) && $_POST['color'] == '#799ef1') 
echo ' selected="selected"';
?>
>Ljus blå</option>

<option value="#f0f179" 
<?php if(isset($_POST['color']) && $_POST['color'] == '#f0f179') 
echo ' selected="selected"';
?>
>Ljus gult</option>
<option value="#fff" 
<?php if(isset($_POST['color']) && $_POST['color'] == '#fff') 
echo ' selected="selected"';
?>
>Vit</option>

<option value="#64b6c1" 
<?php if(isset($_POST['color']) && $_POST['color'] == '#64b6c1') 
echo ' selected="selected"';
?>
>Turkos</option>
<option value="red" 
<?php if(isset($_POST['color']) && $_POST['color'] == 'red') 
echo ' selected="selected"';
?>
>röd</option>
</select>
</td>
</tr><tr>

<td>
Textfärg: 
</td>
<td>
<select name="fontcolor" id="fontcolor">
<option value="#000" 
<?php if(isset($_POST['fontcolor']) && $_POST['fontcolor'] == '#799ef1') 
echo ' selected="selected"';
?>
>Välj Färg</option>

<option value="#799ef1" 
<?php if(isset($_POST['fontcolor']) && $_POST['fontcolor'] == '#799ef1') 
echo ' selected="selected"';
?>
>Ljus blå</option>

<option value="#f0f179" 
<?php if(isset($_POST['fontcolor']) && $_POST['fontcolor'] == '#f0f179') 
echo ' selected="selected"';
?>
>Ljus gult</option>
<option value="#fff" 
<?php if(isset($_POST['fontcolor']) && $_POST['fontcolor'] == '#fff') 
echo ' selected="selected"';
?>
>Vit</option>

<option value="#64b6c1" 
<?php if(isset($_POST['fontcolor']) && $_POST['fontcolor'] == '#64b6c1') 
echo ' selected="selected"';
?>
>Turkos</option>
<option value="red" 
<?php if(isset($_POST['fontcolor']) && $_POST['fontcolor'] == 'red') 
echo ' selected="selected"';
?>
>röd</option>
</select>
</td>
</tr><tr>

<td colspan="2">
<input type="submit" name="go" id="go" value="Skapa visitkort" />
<input type="button" value="Rensa" onclick="window.location.reload();return false" />
</td>
</tr>

</form>

<div id="kort">
<?php

if(isset($_REQUEST["go"])){ 
echo($_REQUEST["enterprise"] . "<br/>");    
echo($_REQUEST["lastname"] . " "); 
echo($_REQUEST["namn"] . "<br/>");
echo($_REQUEST["title"] . "<br/>"."<br/>");     
echo($_REQUEST["phone"] . "<br/>"); 
echo($_REQUEST["mail"] . "<br/>");  

}
else{ 
?>

<?php

}
?>
</div>


</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:57:03+00:00Added an answer on May 26, 2026 at 12:57 am

    This output is from xdebug, because there is an error. $_POST['color'] is not defined.

    Notice: Undefined index: color in C:\wamp\www\Labb3.1\visitkort.php on line 10

    You should always validate user input before using it for anything. Verify it’s a value that you can use, and is safe to use, before printing to the output. If it’s an array like $_POST, make sure the index exists before attempting to read it.

    Be very careful to validate and filter any user input you use in your output, and be mindful of XSS attacks. This is not merely a suggestion, but something you should be dedicated to.

    Learn more: https://www.owasp.org/index.php/Cross-site_Scripting_%28XSS%29

    To simply prevent the error you have to do something like this:

    background-color:<?php echo isset($_POST['color']) ? $_POST['color'] : 'someDefaultColor'; ?>;
    

    However:

    You really should validate the values, at the very least htmlspecialchars($_POST['color']), but even then – you can get broken CSS which will affect the entire page. Consider writing one or more validation/filtering functions to ensure the value is appropriate to use in CSS output (which is beyond the scope of this question). Make sure it’s a 3 or 6 digit hex, or within a predetermined array of named color values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to validate my output data from a php site that Im calling
I'm trying to validate a pair of data columns on mysql from my php
I am trying to validate a directory with C++. http://php.net/manual/en/function.is-readable.php bool is_readable ( string
I am trying to validate form input data using PHP's preg_match function. I am
I'm trying to validate date using PHP. I'd like following formats to be valid:
I am new to programming PHP and am trying to validate a field in
Ok, I'm trying to validate a form in codeigniter as a first step I
I am trying to validate form data from server-side. my interest is that the
I'm trying to validate a date format in PHP 01/02 Day and Month. Anyway,
I have a CSV string that I am trying to validate via regex to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.