/    Sign up×
Community /Pin to ProfileBookmark

MySQL blank records problem

Hello,

I have a problem with the records inserted in my database.I have a form where i upload text and print this text through echo on the screen.Yesterday,i had no problem and every record was apperead normally.But after the insertion of about 100 records i have problem and it appears blank record on every text i submit.I can’t understand what’s wrong.Here the code:

index.php

[code=php]<form action=”insert.php” method=”POST” name=”Wordform”><input type=hidden name=”color” value=”<?php echo sprintf(“#&#37;x%x%x”, rand(0,255), rand(0,255), rand(0,255)); ?>”><input name=”message” style=”width:40%; padding:3px;” type=”text” name=”text”><input style=”cursor:pointer; cursor:hand;” type=”submit” style=”font-size:14px;” value=”Upload Text”>
<?php
$color = sprintf(“#%x%x%x”, rand(0,255), rand(0,255), rand(0,255));

$con = mysql_connect(“localhost”,”root”,””);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}

mysql_select_db(“data”, $con); $result = mysql_query(“SELECT * FROM text ORDER BY num DESC LIMIT 100″);
while($row = mysql_fetch_array($result))
{

echo ‘<font color=”‘.$row[‘color’].'”>’ . $row[‘text’] . ‘</font>’;
echo “&nbsp;”;

}

mysql_close($con);
?>
[/code]

insert.php

[code=php]<?php
// Connects to your Database
mysql_connect(“localhost”, “root”, “”) or die(mysql_error());
mysql_select_db(“data”) or die(mysql_error());

// now we insert it into the database
mysql_query(“INSERT INTO text (text, color)
VALUES (‘”.$_POST[‘text’].”‘ , ‘” .$_POST[‘color’]. “‘)”) or die(mysql_error());

{ header(“Location:index.php”);
}
?>[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@jojo13authorSep 18.2011 — I found the problem.I had double names on form input for text.But now i have another problem with apostrophes.When i enter an apostrophe at the form the mysql returns an error.What's the problem?
×

Success!

Help @jojo13 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...