Forum Moderators: phranque

Message Too Old, No Replies

XML Errors (Having Trouble Replicating)

Email form returning XML error for certain users

         

Andertoons

2:29 pm on Feb 21, 2006 (gmt 0)

10+ Year Member



I'm having a lot of users reports an XML error when trying to use the "Use This Cartoon" feature of my site.
<snip>

And the form you fill in :

<snip>

My web guys are having trouble replicating it and diagnosing it. Can anyone help?

[edited by: physics at 4:34 pm (utc) on Feb. 21, 2006]
[edit reason] No URL drops please. [webmasterworld.com...] [/edit]

physics

4:37 pm on Feb 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Andertoons, welcome to WebmasterWorld.com!
Can you provide the error and the relevant snippets of code (with any specific domains changed to example.com)?

Andertoons

2:36 pm on Feb 22, 2006 (gmt 0)

10+ Year Member



OK, sorry about that. I'm still kinda new here.

Here's the error I'm getting:

The XML page cannot be displayed

Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.

Only one top level element is allowed in an XML document. Error processing resource 'http://www.example.com/usethiscarto...

<b>Warning</b>: Missing argument 2 for checkname() in <b>/home/.magpie/example/example.com/validate...

And here's the code for the page:

<?
require('config.inc');
include('form.inc');
require('validate.inc');

$errs = array();
if ( $submit ) {
$tmp = checkname($name);
if (strlen($tmp)){ array_push($errs, $tmp); }

$tmp = checkphone($telephone);
if (strlen($tmp)){ array_push($errs, $tmp); }

$tmp = checkemail($email);
if (strlen($tmp)){ array_push($errs, $tmp); }

$tmp = checkmessage($message);
if (strlen($tmp)){ array_push($errs, $tmp); }
}

$result=mysql_query("SELECT * FROM toon WHERE id='$id'");
$row=mysql_fetch_array($result);
$thumbnail = sprintf("%04d", $row['id']).'t.jpg';

include('inc_header.php');
if ( count($errs) < 1 && $submit ) {
$stripphone=ereg_replace("[^0-9]","",$telephone);
$stripname=stripslashes($name);
$stripmessage=stripslashes($message);

$result=mysql_query("SELECT * FROM toon WHERE id=$id and lower(status) = 'active'");
$row=mysql_fetch_array($result);

$msg="Use This Cartoon\n\n";
$msg.="Cartoon Number: ".$row[id]."\n\n";
$msg.="Name: $stripname\n";
$msg.="Telephone: $stripphone\n";
$msg.="E-mail: $email\n";
$msg.="Referrer: $referer\n";
$msg.="Usage: $usage\n";
$msg.="Message: $stripmessage\n";

$msg.="

Server Information
----------------------------------------------------------------------
";
foreach ($_SERVER as $key => $value) {
$msg .= "$key: $value\n";
}

$mailheaders="From: $stripname <$email>\n";
$mailheaders.="Reply-To: $stripname <$email>\n\n";
mail("mark@example.com","example - Use This Cartoon",$msg,$mailheaders);
mail("nicholas@example.com","example - Use This Cartoon",$msg,$mailheaders);
?>
<p>
<img src="/images/process_illustration.gif" width="90" height="120" alt="" class="right" />
<p class="center">
Thanks for your request! I&#146;ll get back to you right away!
<br/><br/>
<a href="/">Click here</a> to return to the main page.
</p>
</p>
<?
$result2=mysql_query("select tt.topicid from toon t, toon_topic tt ".
"where t.id = $id and lower(t.status) = 'active' and t.id = tt.toonid group by tt.topicid");
$ids = array();
while ($row2 = mysql_fetch_array($result2)) {
array_push($ids, $row2[0]);
}

$query = "select t.id, t.row from toon t, toon_topic tt ".
"where t.id!= $id and lower(t.status) = 'active' and t.id = tt.toonid ".
"and tt.topicid in (".implode(",", $ids).") ".
"group by t.id, t.row order by t.row desc";
//echo $query;

$result2 = mysql_query($query);

if (mysql_num_rows($result2)>=2){
echo"<p>If you like this cartoon, you may also like these:</p>";

$counter=0;

while ($row2=mysql_fetch_array($result2)) {
if ($row2[id]!=$id) {
if ($counter<3) {
$thumbnail=sprintf("%04d", $row2[id]).'t.jpg';
echo '<a href="toon.php?id='.$row2[id].'"><img src="/cartoons/'.$thumbnail.'" /></a>&nbsp;';
$counter=($counter+1);
}
}
}
}
?>
<?
} else {
?>
<p>
I offer my cartoons for usage in your projects for very reasonable fees! Just fill in the
form below and click Submit and I&#146;ll get back to you with a quote the same day!
(Please note - I cannot offer cartoons for unpaid usage.)
</p>

<form action="/usethiscartoon.php" method="post">
<input type="hidden" name="id" value="<? echo $id;?>" />
<div class="form">
<img src="/cartoons/<?echo $thumbnail;?>" alt="" class="right" />
<ul class="left">
<? if (count($errs) > 0) { echo '<li class="error">'.implode('<br/>', $errs).'<br/><br/></li>'; }?>
<li><label>Name</label><input type="text" name="name" size="35" maxlength="40" value="<? echo $name;?>" class="left" /></li>
<li><label>Telephone</label><input type="text" name="telephone" maxlength="14" value="<? echo $telephone;?>" size="35" class="left" /></li>
<li><label>E-mail</label><input type="text" name="email" value="<? echo $email;?>" size="35" maxlength="60" class="left" /></li>
<li><label>Referrer</label>
<select name="referer">
<?
$result = mysql_query("select id, name from referer order by id");
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row[1] . '"'.($referer == $row[1]? ' selected' : '').'>' . $row[1] . '</option>';
}
?>
</select>
</li>
<li><label>Usage</label>
<select name="usage" class="left">
<option value="Magazine">Magazine</option>
<option value="Newspaper">Newspaper</option>
<option value="Book">Book</option>
<option value="Presentation">Presentation</option>
<option value="Newsletter">Newsletter</option>
<option value="Advertising">Advertising</option>
<option value="Web site">Web site</option>
<option value="Merchandise">Merchandise</option>
<option value="Other">Other</option>
</select>
</li>
<li><label>Message</label><textarea name="message" cols="30" rows="5" maxlength="255" class="left"><? echo $message;?></textarea></li>
<li>&nbsp;</li>
<li><label>&nbsp;</label><input type="submit" name="submit" value="Click here to submit!" class="left" /></li>
</ul>
</div>
</form>
<?
}
include('inc_footer.php');
?>

Any ideas?

physics

2:32 pm on Feb 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is the checkname() function? One of the errors seems to refer to that needing a second argument.

Iguana

2:41 pm on Feb 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Agree with physics.

Even stranger is why would you be getting an XML error on a page that is designed to put out HTML. Why do the users browsers think they are looking at XML?

Andertoons

7:44 pm on Feb 23, 2006 (gmt 0)

10+ Year Member



OK, here's the checkname stuff:

function checkname($str, $identifier)
{
$err = "";
$identifier = $identifier? $identifier : "name";
if ($str == ""){
$err = "Please supply a $identifier.";
} else if ( strlen($str) > 40 ) {
$err = "The $identifier must be less than 40 characters long.";
} else if (!preg_match("/^[a-z A-Z]+$/", $str)) {
$err = "The $identifier you entered contains illegal characters.";
}
return $err;
}

And the XML is baffling me too... Any ideas?

Iguana

12:55 pm on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The checkname function does require 2 parameters to be passed - has it been changed because it is used elsewhere in the system? It might have been changed so that it deals with more than just identifiers called "name"

just call it like this:

checkname($name, "name");

On the XML question, it sounds like your server is telling browsers that .php page type is xml - check your server configuration

Andertoons

12:48 pm on Feb 25, 2006 (gmt 0)

10+ Year Member



I checked with my host about that server php/xml thing and they're saying they don't haveanything like that set up.

The mystery deepens... Any other thoughts?

Iguana

2:45 pm on Feb 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have any lines like the following in your .htaccess file (either in the root or a lower directory?

AddType application/xml .?

Andertoons

3:12 pm on Feb 25, 2006 (gmt 0)

10+ Year Member



Hmmm... Lemme check... I'm not much of a tech guy, but I'll throw it to my web guys...

Thanks!