Jump to content

MySQL Data Entry Spaces?


Uphoreum

Recommended Posts

Here's the main chunk of the first page. It's several text boxes that link to...
[code]
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'>";[/code]

...this page:
[code]
<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>[/code]
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:
[code]<?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'>";
?>[/code]

Ken

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.