Jump to content

a newbie question


hulkkk

Recommended Posts

Hello there.. im doing some random things on php to learn, but im getting this error i can't find the solution.

What happens is: when I use my php with WAMP5, I get:

http://img140.imageshack.us/img140/4029/phptest.jpg

 

But if I use it on a host (like 100webspace.com), It works just fine.

 

Here is the code:

<?

$db_host = "localhost";
$db_username = "root";
$db_password = "";
$db_name = "news";

mysql_connect($db_host,$db_username,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());

$query = "SELECT name, subject, message, date
FROM dados order by date DESC";
$result = mysql_query($query);

echo "<br><center>";

while($r=mysql_fetch_array($result))
{

echo "<tr>";
echo "<td bgcolor='#FFFFFF'><h10>// $r[subject]<HR color='#660000'></td>";
echo "</tr>";
echo "<tr>";
echo "<td bgcolor='#FFFFFF'>$r[message]<HR color='#660000'></h10></td>";
echo "</tr>";
echo "<tr>";
echo "<td bgcolor='#FFFFFF'>Posted By:
$r[name]</a>   $r[date]<br><br><br></td>";
echo "</tr>";
}
echo "</table>";

?>

 

What can it be? Thanks

Link to comment
https://forums.phpfreaks.com/topic/151255-a-newbie-question/
Share on other sites

As revraz said, the short tags could be an issue and it probably is the cause. However I find it very strange that the problem only started with the "; . If the tags thing doesn't solve the problem please paste the source outputted to the browser - because I can't see any reason why it would only start outputting the PHP at this point. Therefore I think that it could have outputted some other things that could give us a clue.

Link to comment
https://forums.phpfreaks.com/topic/151255-a-newbie-question/#findComment-794635
Share on other sites

For revraz: since u can't see the image, here it goes:

"; while($r=mysql_fetch_array($result)) { echo ""; echo "// $r[subject]"; echo ""; echo ""; echo "$r[message]"; echo ""; echo ""; echo "Posted By: $r[name] $r[date]


"; echo ""; } echo ""; ?>

Thats what appears on the browser

I tried with <?php too, and the random codes disappeared, but now it doesnt seem to work. The browser source code appear as:

 

<br><center></table>

 

And there is no error of connecting to mysql and stuff. Here is the code to add to mysql:

<?php
$db_host = "localhost";
$db_username = "root";
$db_password = "";
$db_name = "news";

if ($submit) {
mysql_connect($db_host,$db_username,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());

$date = date("D m/d/Y - g:ia");

$query = "INSERT INTO dados (name, subject, message, date)
VALUES ('$name','$subject','$message','$date')";
mysql_query($query);

mysql_close();

echo "Thanks $name your message has been added";
}

?>
<form name="news" method="post" action="index2.php">
<table align="center" cellpadding="6" cellspacing="0">
<tr>
  <td>Name :</td>
  <td><input type="text" name="name"></td>
</tr>
<tr>
  <td>Subject :</td>
  <td><input type="text" name="subject"></td>
</tr>
<tr>
  <td valign="top">Message :</td>
  <td><textarea name="message" cols="30" rows="6"></textarea></td>
</tr>
<tr>
<td> </td>
  <td><input type="submit" name="submit" value="Add" style="cursor:pointer"> <input 

type="reset" name="reset" value="Clear" style="cursor:pointer"></td>
</tr>
</table>
</form>

 

As I said, at the 100ws it works properly, but at wamp nop. Maybe something wrong with the mysql thing? lol

Link to comment
https://forums.phpfreaks.com/topic/151255-a-newbie-question/#findComment-794669
Share on other sites

As revraz said, the short tags could be an issue and it probably is the cause. However I find it very strange that the problem only started with the ";

Note so strange. View source in the browser, and I suspect you'll see the entirety of the PHP script

The browser is looking at the first character < and seeing it as an open tag for a non-HTML element, so not rendering anything until it finds the next closing  > element.... then it begins to render from the next character

Link to comment
https://forums.phpfreaks.com/topic/151255-a-newbie-question/#findComment-794694
Share on other sites

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.