Reputation: 13
So basically it goes in and finds a word in the database that matches with the word i type in and spits a reply out which works but it does all this other crap.
https://i.sstatic.net/rDA4R.png
This is my PHP Code
<?php
// Connect to database
mysql_connect("*****", "***", "****");
mysql_select_db("***");
// If something is received
if($_POST)
{
if($_POST['action'] == "ask")
{
// Filter it to prevent SQL injections
$text = mysql_real_escape_string($_POST['stringdata']);
// Search it on the database
$q = mysql_query("SELECT `reply` FROM `poka` WHERE `word` = '$text' ORDER BY RAND()");
// Show result
if($r = mysql_fetch_assoc($q))
echo $r['reply'];
else
echo "Cannot find a reply";
}
elseif($_POST['action'] == "teach")
{
// Filter it to prevent SQL injections
$word = mysql_real_escape_string($_POST['word']);
$answer = mysql_real_escape_string($_POST['answer']);
// Insert it to the database
if( mysql_query("INSERT INTO `poka` VALUES(NULL, '$word', '$answer')") )
echo "ok";
else
echo "fail";
}
}
?>
Upvotes: 1
Views: 95
Reputation: 1554
Could you try the following change, just to make sure you're not breaking any strings.
echo $r['reply'];
to
echo "{$r['reply']}";
Does it behave the same way anyway?
Although, the answer above probably is the reason.
Here is an example from the PHP documentation on how to use arrays in echos:
// You can also use arrays
$baz = array("value" => "foo");
echo "this is {$baz['value']} !"; // this is foo !
Upvotes: 0
Reputation: 2353
If you want to know definitively, head over to http://www.apachefriends.org/en/index.html and pick yourself up a copy of XAMPP.
With it you can quickly setup a local copy of a MYSQL database. Migrate your database data over from your current host to duplicate the setup you already have.
Then in your PHP, change it to point to your new local database (on 'localhost') and see if you get the same result.
My suspicions are as everyone elses :)
Upvotes: 0
Reputation: 399
Your hosting company is automatically adding Google(?) Analytics code to every page sent. Talk to them.
Upvotes: 4