Page 1 of 1

PHP Problem

Posted: Mon Dec 22, 2014 3:22 pm
by jimmyb29
Hi, I'm back with a similar problem. This is the php code to query and add names to the guestbook. It ALMOST works, but-?

<img_back>imgback</img_back>

Code: Select all

<?php 
$link = mysql_connect('jimmybryantnet.ipagemysql.com', '*****', '*****'); 
if (!$link) { 
    die('Could not connect: ' . mysql_error());
 
} 
echo 'Connected successfully';


 mysqli_select_db(guestbook); 
?> 
} 
echo 'Connected successfully';
 
(mysqli_select_db(guestbook); 
?>";
$server = mysql_connect('jimmybryantnet.ipagemysql.com', '****', '****'); 
if (!$link) { 
    die('Could not connect: ' . mysql_error());
 
} 
echo 'Connected successfully';$user = "*****";
$password = *****";

$dataBase = "guestbook";


$conx = mysqli_connect(<?php 
$link = mysql_connect('jimmybryantnet.ipagemysql.com', '*****', '****'); 
if (!$link) { 
    die('Could not connect: ' . mysql_error());
 
} 
echo 'Connected successfully';
 
 
mysql_select_db(guestbook);
 
?>$server,$user,
$password);

$db_selected = mysqli_select_db($dataBase,$conx);


if($conx && $db_selected){
	$xml = "<xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
	$xml .= "<data>\n";
	
	if(isset($_POST['name'])){
		$result = 0;

		$name=mysqli_escape_string(trim($_POST['name']));

		$email=mysqli_escape_string(trim($_POST['email']));

		$message=mysqli_escape_string(trim($_POST['message']));

		
		$sqli="INSERT INTO guestbook(name,email,message,dateAdded)values('$name','$email','$message',now())";


		$query = mysqli_query($sql,$conx);

		if ($query){
			$result= 1;

			$sql2 = "SELECT * FROM guestbook ORDER BY id DESC";

			$query2 = mysqli_query($sql2,$conx);

			//WHEN query == true , GET LIST OF MESSAGES  AND PUT THEM AS XML FILE
			while($data = mysqli_fetch_array($query2)){
				$xml .= "<guest>\n";

				$xml .= "<name>".$data['name']."</name>\n";


				$xml .= "<msg><![CDATA[".$data['message']."]]></msg>\n";

				$xml .= "</guest>\n";
				}
			}
		else{
			$result=0;

			}
		$xml .= "<inserted>".$result."</inserted>\n";

		
	}	
	if(isset($_POST['getMessage'])){
			$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{
	die (mysqli_error());
}
?>

Re: PHP Problem

Posted: Mon Dec 22, 2014 3:28 pm
by requinix
That code is all sorts of messed up. Is that really what you have?

Re: PHP Problem

Posted: Mon Dec 22, 2014 7:43 pm
by jimmyb29
Unfortunately, yes! I believe part of it is right, but the rest -? Is there any way I could pay you to straighten it out so that it works properly? I would DESPERATELY like to get this guestbook finished!

Thanks,

Jimmyb29

Re: PHP Problem

Posted: Mon Dec 22, 2014 8:41 pm
by requinix
I can't straighten it up for you because I don't know what it's supposed to look like. That is what you mean, right? Because what you've posted, literally, won't work. Certainly won't do what you're saying it does. So I'm asking whether the code you posted, what you have right there in your post, is exactly the code you're working with.

Re: PHP Problem

Posted: Tue Dec 23, 2014 1:33 am
by jimmyb29
requinix wrote:I can't straighten it up for you because I don't know what it's supposed to look like. That is what you mean, right? Because what you've posted, literally, won't work. Certainly won't do what you're saying it does. So I'm asking whether the code you posted, what you have right there in your post, is exactly the code you're working with.
I have another version of this that might be better. Let me see if I can find it.

Jimmyb

Re: PHP Problem

Posted: Tue Dec 23, 2014 1:41 am
by jimmyb29
jimmyb29 wrote:
requinix wrote:I can't straighten it up for you because I don't know what it's supposed to look like. That is what you mean, right? Because what you've posted, literally, won't work. Certainly won't do what you're saying it does. So I'm asking whether the code you posted, what you have right there in your post, is exactly the code you're working with.
I have another version of this that might be better. Let me see if I can find it.

Jimmyb
Here it is - but it didn't work!

Code: Select all

<?php
<?xml version="1.0" encoding="UTF-8"?>
$server = " <?php 
$link = mysqli_connect('jimmybryantnet.ipagemysql.com', '*****', '*****'); 
if (!$link) { 
    die('Could not connect: ' . mysql_error()); 
} 
echo 'Connected successfully'; 
mysqli_select_db(guestbook); 
?> ";
$user = "*****";
$password = "*****";
$dataBase = "guestbook";

$conx = mysqli_connect($server,$user,$password);
$db_selected = mysqli_select_db($dataBase,$conx);

if($conx && $db_selected){
	$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
	$xml .= "<data>\n";
	
	if(isset($_POST['name'])){
		$result = 0;
		$name=mysqli_escape_string(trim($_POST['name']));
		$email=mysqli_escape_string(trim($_POST['email']));
		$message=mysqli_escape_string(trim($_POST['message']));
		
		$sql="INSERT INTO guestbook(name,email,message,dateAdded)values('$name','$email','$message',now())";
		$query = mysqli_query($sql,$conx);
		if ($query){
			$result= 1;
			$sql2 = "SELECT * FROM guestbook ORDER BY id DESC";
			$query2 = mysqli_query($sql2,$conx);
			//WHEN query == true , GET LIST OF MESSAGES  AND PUT THEM AS XML FILE
			while($data = mysqli_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'])){
			$sql = "SELECT * FROM guestbook ORDER BY id DESC";
			$query = mysqli_query($sql,$conx);
			while($data = mysqli_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{
	die (mysqli_error());
}
?>
See if you can make sense of it.

Thanks, Jimmyb

Re: PHP Problem

Posted: Tue Dec 23, 2014 2:23 am
by requinix
That's not your code either.

To make sure we both understand what the problem is: it's nothing to do with the "It ALMOST works, but-" you said in your first post. The code you have running right now, that works partially but not quite, is somewhere on your computer. Or on a server somewhere, I don't know. But what you've been posting is not that code: the first one was valid, coincidentally, but does not even come close to working, while this latest code is not even valid PHP code in the first place.

In an effort to get the right code posted here, I have some questions:
1. Where is the code you're reading from right now? A file on your computer? Somewhere else?
2. How are you getting that code into your posts in this thread?
3. Can you try using just an attachment instead?

One more thing. If you do put the code directly into your post, please copy/paste, then select all the code and hit the "PHP Code" button above the text box. That will wrap the code in

Code: Select all

 tags that make it much easier to read than if it was just straight text.