candice Posted February 6, 2009 Share Posted February 6, 2009 Hi all, I am about to do a live search, and in the midst of testing out my script that generates the xml, i found this error: XML Parsing Error: junk after document element Location: http://localhost/equipdb/genUserSearch.php Line Number 2, Column 1:<b>Notice</b>: Undefined index: search in <b>C:\wamp\www\equipdb\genUserSearch.php</b> on line <b>41</b><br /> ^ Does any of you know where the error lies? Thanks. Attached is my code: <?php header ('Content-type:text/xml') ?> <?php echo ('<?xml version="1.0" encoding="iso-8859-1"?>') ?> <?php require_once('connection.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } function highlightkeyword($text) { $keyword = $_GET['search']; $highlighttext = str_ireplace($keyword, "<span class='highlight'>".$keyword."</span>", $text); return $highlighttext; } mysql_select_db($db_name); $search = $_GET['search']; $query_rsAccount = "SELECT * FROM student WHERE studentID LIKE '%".$search."%' OR studentname LIKE '%".$search."%'"; $rsAccount = mysql_query($query_rsAccount, $db_name) or die(mysql_error()); $row_rsAccount = mysql_fetch_assoc($rsAccount); $totalRows_rsAccount = mysql_num_rows($rsAccount); ?> <Account> <?php do { ?> <result total ="<?php echo $totalRows_rsAccount ?>"> <id><![CDATA[<?php echo $row_rsAccount['id']; ?>]]></id> <studentID><![CDATA[<?php echo highlightkeyword($row_rsAccount['studentID']); ?>]]></studentID> <studentname><![CDATA[<?php echo highlightkeyword($row_rsAccount['studentname']); ?>]]></studentname> <?php } while ($row_rsAccount = mysql_fetch_assoc($rsAccount)); ?> </Account> <?php mysql_free_result($rsAccount); ?> Link to comment https://forums.phpfreaks.com/topic/144046-xml-parsing-error-junk-after-document-element/ Share on other sites More sharing options...
only one Posted February 6, 2009 Share Posted February 6, 2009 You forgot to add a quotation mark <?php echo ('<?xml version="1.0" encoding="iso-8859-1"?>') ?> Link to comment https://forums.phpfreaks.com/topic/144046-xml-parsing-error-junk-after-document-element/#findComment-755819 Share on other sites More sharing options...
candice Posted February 6, 2009 Author Share Posted February 6, 2009 Thanks for the reply. I tried replacing the code, but im still getting the same error. XML Parsing Error: junk after document element Location: http://localhost/equipdb/genUserSearch.php Line Number 2, Column 1:<b>Notice</b>: Undefined index: search in <b>C:\wamp\www\equipdb\genUserSearch.php</b> on line <b>41</b><br /> ^ could be something to search variable? Link to comment https://forums.phpfreaks.com/topic/144046-xml-parsing-error-junk-after-document-element/#findComment-755826 Share on other sites More sharing options...
RichardRotterdam Posted February 6, 2009 Share Posted February 6, 2009 it's because your get parameter is empty $_GET['search'] Link to comment https://forums.phpfreaks.com/topic/144046-xml-parsing-error-junk-after-document-element/#findComment-755829 Share on other sites More sharing options...
candice Posted February 6, 2009 Author Share Posted February 6, 2009 Sorry im not very sure what you mean. How should i code it? Link to comment https://forums.phpfreaks.com/topic/144046-xml-parsing-error-junk-after-document-element/#findComment-755835 Share on other sites More sharing options...
RichardRotterdam Posted February 6, 2009 Share Posted February 6, 2009 put this in your function highlightkeyword $keyword=""; if(isset($_GET['search'])){ $keyword = $_GET['search']; } Link to comment https://forums.phpfreaks.com/topic/144046-xml-parsing-error-junk-after-document-element/#findComment-755870 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.