jimmyb29 Posted April 6, 2014 Share Posted April 6, 2014 Hi! I'm an 85 year old newbie, trying to implement a "store bought" Guestbook. I seem to be having a problem with the module that connects the DB to the .flv (I think!) I've checked it with several online checkers and they don't report any errors/ Would someone be so kind as to look at the code and see id you can find the errors? THANKS! <?php // CONNECT TO THE SERVER AND SELECT DATABASE $server = "ftp.ipage.com"; $user = "jimmybryantnet"; $password = "********"; $dataBase = "guestbook"; $conx = mysql_connect($server,$user,$password); $db_selected = mysql_select_db($dataBase,$conx); if($conx && $db_selected){ // IF CONNECTION IS ESTABLISHED $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; $xml .= "<data>\n"; if(isset($_POST['name'])){ $result = 0; $name=mysql_escape_string(trim($_POST['name'])); $email=mysql_escape_string(trim($_POST['email'])); $message=mysql_escape_string(trim($_POST['message'])); // ADD DATA TO THE TABLE guestbook WHEN THE USER PRESS THE send_btn in FLASH $sql="INSERT INTO guestbook(name,email,message,dateAdded)values('$name','$email','$message',now())"; $query = mysql_query($sql,$conx); if ($query){ $result= 1; $sql2 = "SELECT * FROM guestbook ORDER BY id DESC"; $query2 = mysql_query($sql2,$conx); //WHEN query == true , GET LIST OF MESSAGES AND PUT THEM AS XML FILE while($data = mysql_fetch_array($query2)){ $xml .= "<guest>\n"; $xml .= "<name>".$data['name']."</name>\n"; $xml .= "<msg><![CDATA[".$data['message']."]]></msg>\n"; $xml .= "<sdate>".$data['dateAdded']."</sdate>\n"; $xml .= "</guest>\n"; } } else{ $result=0; } $xml .= "<inserted>".$result."</inserted>\n"; } if(isset($_POST['getMessage'])){ // GET LIST OF MESSAGES AND PUT THEM AS XML FILE $sql = "SELECT * FROM guestbook ORDER BY id DESC"; $query = mysql_query($sql,$conx); while($data = mysql_fetch_array($query)){ $xml .= "<guest>\n"; $xml .= "<name>".$data['name']."</name>\n"; $xml .= "<msg><![CDATA[".$data['message']."]]></msg>\n"; $xml .= "<sdate>".$data['dateAdded']."</sdate>\n"; $xml .= "</guest>\n"; } } $xml .= "</data>\n"; echo $xml; } else{ // IF CONNECTION == false OR DATABASE DOESN'T EXISTE die (mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 6, 2014 Share Posted April 6, 2014 the ftp address is used for transferring files via FTP (File Transfer Portocol.) this has nothing to do with a database server. the database server's host(name) would be something like mysql.your_web_host.com or just the ip address of the mysql server. your web host should have a faq that specifies this or it is usually displayed in the tool/page where you are creating database user, passwords, and managing your databases and tables (i.e phpmyadmin or a similar tool.) Quote Link to comment Share on other sites More sharing options...
jimmyb29 Posted April 7, 2014 Author Share Posted April 7, 2014 the ftp address is used for transferring files via FTP (File Transfer Portocol.) this has nothing to do with a database server. the database server's host(name) would be something like mysql.your_web_host.com or just the ip address of the mysql server. your web host should have a faq that specifies this or it is usually displayed in the tool/page where you are creating database user, passwords, and managing your databases and tables (i.e phpmyadmin or a similar tool.) Hi, Thanks for the reply! I'm using the MYsql - PHP Admin server on ipage to create the database,.I assumed that was why the ftp address was there (this was given in the code I bought.) I actually have a server on my computer - should I build the DB with that? I'm over my head with this - I assumed the code was correct when I bought the program - was I wrong? Jimmyb29 Quote Link to comment Share on other sites More sharing options...
jimmyb29 Posted December 14, 2014 Author Share Posted December 14, 2014 Hi! I found a T_string error in the XML declaration - I noted it in RED. Any ideas about that? <?php // CONNECT TO THE SERVER AND SELECT DATABASE $server = "ftp.ipage.com"; $user = "jimmybryantnet"; $password = "********"; $dataBase = "guestbook"; $conx = mysql_connect($server,$user,$password); $db_selected = mysql_select_db($dataBase,$conx); if($conx && $db_selected){ // IF CONNECTION IS ESTABLISHED $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";THIS LINE OF CODE THROWS AN ERROR! $xml .= "<data>\n"; if(isset($_POST['name'])){ $result = 0; $name=mysql_escape_string(trim($_POST['name'])); $email=mysql_escape_string(trim($_POST['email'])); $message=mysql_escape_string(trim($_POST['message'])); // ADD DATA TO THE TABLE guestbook WHEN THE USER PRESS THE send_btn in FLASH $sql="INSERT INTO guestbook(name,email,message,dateAdded)values('$name','$email','$message',now())"; $query = mysql_query($sql,$conx); if ($query){ $result= 1; $sql2 = "SELECT * FROM guestbook ORDER BY id DESC"; $query2 = mysql_query($sql2,$conx); //WHEN query == true , GET LIST OF MESSAGES AND PUT THEM AS XML FILE while($data = mysql_fetch_array($query2)){ $xml .= "<guest>\n"; $xml .= "<name>".$data['name']."</name>\n"; $xml .= "<msg><![CDATA[".$data['message']."]]></msg>\n"; $xml .= "<sdate>".$data['dateAdded']."</sdate>\n"; $xml .= "</guest>\n"; } } else{ $result=0; } $xml .= "<inserted>".$result."</inserted>\n"; } if(isset($_POST['getMessage'])){ // GET LIST OF MESSAGES AND PUT THEM AS XML FILE $sql = "SELECT * FROM guestbook ORDER BY id DESC"; $query = mysql_query($sql,$conx); while($data = mysql_fetch_array($query)){ $xml .= "<guest>\n"; $xml .= "<name>".$data['name']."</name>\n"; $xml .= "<msg><![CDATA[".$data['message']."]]></msg>\n"; $xml .= "<sdate>".$data['dateAdded']."</sdate>\n"; $xml .= "</guest>\n"; } } $xml .= "</data>\n"; echo $xml; } else{ // IF CONNECTION == false OR DATABASE DOESN'T EXISTE die (mysql_error()); } ?> Thanks again for your help. Sorry if I've made mistakes - but I AM 85 1/2 years old, and don't know all your rules! Jimmy Quote Link to comment Share on other sites More sharing options...
Barand Posted December 14, 2014 Share Posted December 14, 2014 With the exception of some expected "deprecated mysql" warnings, your code ran fine when I tried it. Of course I had to change the database connection credentials. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.