Dear All,

I am currently working on a web assignment.
But I do not know what is wrong with this ^piece of code.
Can anyone of you find the bug in it please

	if(!$con){die("could not connect".mysql_error());}
	echo("dbconnect is working");

	$fname=a;//$_GET('search_fname');echo $fname;
//	include("dbConnect.php");
	echo "blaljfkdjfjdfk";	
	echo $fname;
	$sql="SELECT fname,lname,email FROM user WHERE fname=$fname AND lname=$lname";
		echo "No result found";
	 header('Content-Type: text/xml');
 $xml_name = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" ;
 $xml_name = $xml_name."<Nom>" ;

	while($rows=mysql_fetch_array($result) ){
	echo $xml_name;
<? echo $fname; echo $lname; >

Recommended Answers

All 6 Replies

Looks like there's a few bugs in there...

1. You have commented out the filename so you're pointing to just 'a'. Not sure what you're trying to do here... This makes no sense! Also, you're trying to write three lines of code on one line... You should concatenate these lines

$fname=a;//$_GET('search_fname');echo $fname;

2. Your query variables should have single quotes around them like this:

$sql="SELECT fname,lname,email FROM user WHERE fname='$fname' AND lname='$lname'";

3. You have used incorrect quotes here:

$xml_name = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" ;

Change it to:

$xml_name = '<? xml version=\"1.0\" encoding=\"ISO-8859-1\";' ?>

4. You've missed the last closing php tag:

<? echo $fname; echo $lname; ?>

Those are the ones I saw straight away... there's probably more in there though

Thanks man.
I've corrected these mistakes but now I am left with this last error.
Can you please work it out.

XML Parsing Error: XML declaration not well-formed
Location: http://localhost/idareyou/searchUser.php
Line Number 1, Column 15:<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><Nom><Name><fname>a</fname><lname>a</lname><email>a@a.c</email></Name></Nom>

note the arrow is just underneath the escape charater just after version=\

k, either try removing the double quotes completely from the version/encoding or if that still fails, try removing the escape chars, I'm not sure how necessary they are.

I've removed the escape characters.

thanks a lot .

The php code is working...thanks to you. I am using this php file with some basic ajaxing. But I do not why, it is not working, though it is accessing each method in it. Can you please figure out what is wrong in it. Thanks in advance.

var xmlhttp;

function showUserName(){

    var fname= document.getElementById("search_fname");//alert("fname is " + fname);
    var lname= document.getElementById('search_lname');//alert("lname is "+ lname);
        //code for ie7+,firefox,chrome,opera,safari
        xmlhttp=new XMLHttpRequest();
        //code for ie6,5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        alert("cannot create XMLHTTP instance");
        return false;

    var url="searchUser.php";


function theResponse(){

            var tableName="<table><tr><th>First Name</th><th>Last Name</th><th>Email</th></tr>"; 
            var xmlDoc=xmlhttp.responseXML.documentElement;//refers to root position of the xml <Nom>

            var NomNo=xmlDoc.childNodes.length;
                for(var i=0;i<NomNo;i++){
                var namenode=xmlDoc.childNodes[i];//refers to Nom/Name

                var nameNo=namenode.childNodes.length;//refers to no of element under Name

                for(var j=0;j<nameNo;j++){
                    var Nam=namenode.childNodes[j];//1st object
                    var sibl=Nam.childNodes[0];//its value
            alert("there was a problem with the request");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.