Jump to content


Photo

MySQL Data Entry Spaces?


  • Please log in to reply
5 replies to this topic

#1 Uphoreum

Uphoreum
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 July 2006 - 03:43 PM

I used to know the answer to this question, but I forgot and I can't find the information again. When I use UPDATE or INSERT to put data in to a table, if that data has a space, it cuts off the string at the space. How can I stop this from happening?

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 23 July 2006 - 03:45 PM

It shouldn't happen. Can we see your code?

#3 Uphoreum

Uphoreum
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 July 2006 - 03:57 PM

Here's the main chunk of the first page. It's several text boxes that link to...
echo "<form name='favupdate' action='update.php' method='get'>";
echo "Book: <input type='text' name='book' value=$row[book]>";
echo "<br>";
echo "Game: <input type='text' name='game' value=$row[game]>";
echo "<br>";
echo "Celeb: <input type='text' name='celeb' value=$row[celeb]>";
echo "<br>";
echo "Movie: <input type='text' name='movie' value=$row[movie]>";
echo "<br>";
echo "TV Show: <input type='text' name='tv' value=$row[tv]>";
echo "<br>";
echo "Music: <input type='text' name='music' value=$row[music]>";
echo "<br>";
echo "<input type='submit' value='Update'>";

...this page:
<html>
<?php
$con = mysql_connect("localhost","anonymous");
mysql_select_db("users",$con);
mysql_query("UPDATE favs SET book = '$_GET[book]' WHERE uid = 'testid'");
mysql_query("UPDATE favs SET game = '$_GET[game]' WHERE uid = 'testid'");
mysql_query("UPDATE favs SET celeb = '$_GET[celeb]' WHERE uid = 'testid'");
mysql_query("UPDATE favs SET movie = '$_GET[movie]' WHERE uid = 'testid'");
mysql_query("UPDATE favs SET tv = '$_GET[tv]' WHERE uid = 'testid'");
mysql_query("UPDATE favs SET music = '$_GET[music]' WHERE uid = 'testid'");
echo "Update Successful! <a href='index.php'>Click To Return</a>.";
?>
</html>


#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 23 July 2006 - 04:06 PM

The problem occurs not when you insert the data into the database, but in your form. If you had looked at the data being returned from the form, you would have see this. You need to put quotes around all values of attributes in the <input> tags. If your data includes quotes or HTML tags, pass it through the htmlentities() function first:
<?php
echo "<form name='favupdate' action='update.php' method='get'>";
echo "Book: <input type='text' name='book' value='{$row['book']}'>";
echo "<br>";
echo "Game: <input type='text' name='game' value='{$row['game']}'>";
echo "<br>";
echo "Celeb: <input type='text' name='celeb' value='{$row['celeb']}'>";
echo "<br>";
echo "Movie: <input type='text' name='movie' value='{$row['movie']}'>";
echo "<br>";
echo "TV Show: <input type='text' name='tv' value='{$row['tv']}'>";
echo "<br>";
echo "Music: <input type='text' name='music' value='{$row['music']}'>";
echo "<br>";
echo "<input type='submit' value='Update'>";
?>

Ken

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 23 July 2006 - 04:07 PM

AVO, you're solutions do not relate to the OP's problem at all, please refrain from posting non-solutions.

Ken

#6 Uphoreum

Uphoreum
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 July 2006 - 04:09 PM

Ken's Code fixed it. Thanks!

He's right, the data in the table was fine, but when I tried to read it back into the form, it got screwed up. I never used MySQL to just look at the table first.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users