Jump to content

white space


psyqosis

Recommended Posts

Hi. I have a table with all US state names (Varchar, 50) and an auto-id that links to other data about that state. My code (which echos results) works perfectly for all states without a space (i.e. Washington, Oregon) but when it comes to a state with a space (New York, North Dakota), it only spits out the 1st word (New, North). The data in the TABLE is correct (New York, New Mexico), but the output is dying at the white space.

 

Is there a simple function I need to be sure the echo handles white space, and/or should I post my code? Thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/105434-white-space/
Share on other sites

The problem looks like it lies in the INSERT statement below . When I create a new record for "New Mexico" on the page below, it only stores "New" in the state column. BUT, I can put spaces in the other fields and it stores fine there. I can verify both of those claims by looking at the data in the table (all fields are VARCHAR 50). Then when I do a call for data with "New Mexico" on another page there's nothing there.

 

 

<?php include("config.php"); ?>

<?php include("access_control.php");?>

<head>

<link rel="stylesheet" type="text/css" href="style.css">

</head>

<br>

<body bgcolor=gray text=white link=gray alink=gray vlink=gray>

<table width=740 cellpadding=0 border=0 cellspacing=0>

<tr>

<td bgcolor=ffffff>

<table width=735 cellpadding=10 border=0 cellspacing=1>

 

<tr>

<td bgcolor=black width=100%><b>New Listing</b></td>

</tr>

<tr>

<td bgcolor=black width=100%><a href="index.php"><font face=arial size=1 color=white><b>< HOME</b></font></a></td>

</tr>

 

<tr>

 

 

<td width=100% bgcolor=black valign=top>

 

<?php

 

if($add == 1) {

 

$sql = "INSERT INTO vendors (name, address, city, state, phone, website) VALUES ('$name', '$address', '$city', '$state', '$phone', '$website');";

 

$result = mysql_query($sql, $db) or die(mysql_error());

 

?> <h3>Record added to database. Thanks.</h3> Add another record by filling in the form below or return to the main menu by <a href="index.php">clicking here</a>.<?php

}

 

?>

 

<form method=post action="<?php echo $PHP_SELF ?>" enctype="multipart/form-data">

<h3> Create New Record </h3>

 

<center>

<table width=400 cellpadding=0 cellspacing=0 border=0>

 

<tr><td align=right nowrap>Name:&nbsp</td><td><input type="text" name="name" size=50></td></tr>

<tr><td align=right nowrap>Address:&nbsp</td><td><input type="text" name="address" size=50></td></tr>

<tr><td align=right nowrap>City:&nbsp</td><td><input type="text" name="city" size=25></td></tr>

<tr><td align=right nowrap>State:&nbsp</td><td><?php

$sql = "SELECT * FROM states ORDER BY state";

$result = mysql_query($sql, $db) or die(mysql_error());

echo "<select name=\"state\">";

while ($myrow = mysql_fetch_array($result)) {

echo "<option value=".$myrow['state'].">".$myrow['state']."</option>";

}

?></td></tr>

<tr><td align=right nowrap>Phone:&nbsp</td><td><input type="text" name="phone" size=25></td></tr>

<tr><td align=right nowrap>Website:&nbsp</td><td><input type="text" name="website" size=50></td></tr>

 

    <tr><td colspan=2 align=right><input type=hidden name="add" value="1"><input type="submit" value="Submit Record"></td></tr>

</table>

</center>

 

</td>

</tr>

</table>

</td>

</tr>

</table>

</form>

</body>

Link to comment
https://forums.phpfreaks.com/topic/105434-white-space/#findComment-539981
Share on other sites

This will fix it

 

echo "<option value='".$myrow['state']."'>".$myrow['state']."</option>";

 

Your option values aren't quoted, so your HTML looks like this:

 

<option value=New Mexico>New Mexico</option>";

 

It knows what to do with New, but it just ignores Mexico. or you could double quote:

 

echo "<option value=\"".$myrow['state']."\">".$myrow['state']."</option>";

 

 

Link to comment
https://forums.phpfreaks.com/topic/105434-white-space/#findComment-539988
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.