hulkkk Posted March 26, 2009 Share Posted March 26, 2009 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 More sharing options...
revraz Posted March 26, 2009 Share Posted March 26, 2009 Paste the actual error or problem and not a link to it if you want a more broad range of help (my work blocks imageshack). Link to comment https://forums.phpfreaks.com/topic/151255-a-newbie-question/#findComment-794554 Share on other sites More sharing options...
Derleek Posted March 26, 2009 Share Posted March 26, 2009 I can't even tell if thats an error it just looks like jumbled output to me... Link to comment https://forums.phpfreaks.com/topic/151255-a-newbie-question/#findComment-794556 Share on other sites More sharing options...
Mark Baker Posted March 26, 2009 Share Posted March 26, 2009 Looks more like the webserver isn't configured to execute PHP scripts Link to comment https://forums.phpfreaks.com/topic/151255-a-newbie-question/#findComment-794595 Share on other sites More sharing options...
revraz Posted March 26, 2009 Share Posted March 26, 2009 Try using <?php instead of the <? short tags Link to comment https://forums.phpfreaks.com/topic/151255-a-newbie-question/#findComment-794607 Share on other sites More sharing options...
KPH71 Posted March 26, 2009 Share Posted March 26, 2009 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 More sharing options...
hulkkk Posted March 26, 2009 Author Share Posted March 26, 2009 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 More sharing options...
revraz Posted March 26, 2009 Share Posted March 26, 2009 Looks like for one host you have register globals enabled (the one that works) and the other has it off. Re code to not use register globals and it will probably work. Link to comment https://forums.phpfreaks.com/topic/151255-a-newbie-question/#findComment-794674 Share on other sites More sharing options...
Mark Baker Posted March 26, 2009 Share Posted March 26, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.