psyqosis Posted May 13, 2008 Share Posted May 13, 2008 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 More sharing options...
BlueSkyIS Posted May 13, 2008 Share Posted May 13, 2008 post code. Link to comment https://forums.phpfreaks.com/topic/105434-white-space/#findComment-539972 Share on other sites More sharing options...
psyqosis Posted May 13, 2008 Author Share Posted May 13, 2008 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: </td><td><input type="text" name="name" size=50></td></tr> <tr><td align=right nowrap>Address: </td><td><input type="text" name="address" size=50></td></tr> <tr><td align=right nowrap>City: </td><td><input type="text" name="city" size=25></td></tr> <tr><td align=right nowrap>State: </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: </td><td><input type="text" name="phone" size=25></td></tr> <tr><td align=right nowrap>Website: </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 More sharing options...
benphp Posted May 13, 2008 Share Posted May 13, 2008 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 More sharing options...
soycharliente Posted May 13, 2008 Share Posted May 13, 2008 ALWAYS use quotes around HTML tag attributes. That's the purpose of them. So things like that don't happen. Link to comment https://forums.phpfreaks.com/topic/105434-white-space/#findComment-539989 Share on other sites More sharing options...
psyqosis Posted May 13, 2008 Author Share Posted May 13, 2008 thanks benphp & charlieholder. I knew it was something dumb I missed. Thanks. Link to comment https://forums.phpfreaks.com/topic/105434-white-space/#findComment-540170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.