Jump to content

Error in PHP Code


jimmyb29

Recommended Posts

I'm getting an error with this code:

 

<?php
// CONNECT TO THE SERVER AND SELECT DATABASE
$server = "/home/users/web/b2713/ipg.jimmybryantnet";
$user = "jimmyb29";
$password = "alfiep69";
$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());
}
?>
 
The error message says, "error in line 10, character 17".
 
I don't understand
 
Thanks!
Jimmy
Link to comment
Share on other sites

Hi,

 

I sent a post yesterday, but included the wrong code! :-\  Here's the problem:

 

<?xml version="1.0" encoding="utf-8" ?> 
<configuration>
<phpURL>/home/users/web/b2713/ipg.jimmybryantnet?>
<alert_color>#FF0000</alert_color>
<name_color>#8d2405</name_color>
<message_color>#532b2b</message_color>
<datePosted_color>#307a03</datePosted_color>
<insert_ok><![CDATA[<font color='#0f5711'>Thanks for the message.</font>]]></insert_ok>
<insert_error><![CDATA[<font color='#ff0000'>Error adding Message</font>]]></insert_error>
</configuration>
 
The error message says: mismatch error line 11, Col 17. Please help.  :stoopid:
 
Jimmy
Link to comment
Share on other sites

  • 2 months later...
This seems to be the culprit now; It's the Guestbook code:

 

I get an error message that says there's an unexpected T_String error in line 5.

 

<?php

// CONNECT TO THE SERVER AND SELECT DATABASE

$server = ' <

$link = mysqli_connect( <?php 

$link = mysqli_connect('jimmybryantnet.ipagemysqli.com', 'jimmyb29', '*******'); 

if (!$link) { 

    die('Could not connect: ' . mysqli_error()); 


echo 'Connected successfully'; 

mysqli_select_db(guestbook); 

?> ); 

if (!$link) {  die('Could not connect: ' . mysqli_error()); 

echo 'Connected successfully'; 

mysqli_select_db(guestbook); 

?> ';

$user = 'jimmyb29';

$password = 'alfiep69';

$dataBase = 'guestbook';

 

$conx = mysqli_connect($server,$user,$password);

$db_selected = mysqli_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=mysqli_escape_string(trim($_POST['name']));

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

$message=mysqil_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 = mysqil_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 = 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'])){

// GET LIST OF MESSAGES AND PUT THEM AS XML FILE

$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;

}

 

Thanks!

Link to comment
Share on other sites

The code seems a bit jumbled.

<?php
// CONNECT TO THE SERVER AND SELECT DATABASE
// not needed $server = ' <
// not needed $link = mysqli_connect( <?php ' 
// mysqli_connect($host, $user, $password, $database);
// change    $link = mysqli_connect('jimmybryantnet.ipagemysqli.com', 'jimmyb29', '*******'); 
if (!$link) { 
    die('Could not connect: ' . mysqli_error()); 
} 
echo 'Connected successfully'; 
// not needed mysqli_select_db(guestbook); 
// not needed ?> ); 
// not needed if (!$link) {  die('Could not connect: ' . mysqli_error()); 
// not needed echo 'Connected successfully'; 
// not needed mysqli_select_db(guestbook); 
// not needed ?> ';
// appears to be making a redundant connection to the same database, so
// not needed here - should be defined at top of page $user = 'jimmyb29';
// not needed here - should be defined at top of page $password = 'alfiep69';
// not needed here - should be defined at top of page$dataBase = 'guestbook';
 
// not needed $conx = mysqli_connect($server,$user,$password);
// not needed $db_selected = mysqli_select_db($dataBase,$conx);
Link to comment
Share on other sites

Guest
This topic is now 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.