Jump to content

Problem With php-mysql-xml DB


jimmyb29

Recommended Posts

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());
}
?>
Link to comment
https://forums.phpfreaks.com/topic/287569-problem-with-php-mysql-xml-db/
Share on other sites

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.)

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? :confused:

Jimmyb29

  • 8 months later...

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! :confused:

 

Jimmy

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.