Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem in retrieving data from mysql into specified fields on webpage

    Hi,

    Here's wat im trying to do. I have a list box populated by mysql database. On select of a particular element i want all the details of that in their specified text fields or text areas on the web page so that the user can modify or update the details and submit.

    The code till now is as follows:
    modify species page:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    var xmlhttp;
    
    function showMod(str)
    {
    xmlhttp=GetXmlHttpObject();
    
    if (xmlhttp==null)
      {
      alert ("Browser does not support HTTP Request");
      return;
      }
    
    var url="getdspe.php";
    url=url+"?q="+str;
    url=url+"&sid="+Math.random();
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    
    }
    
    function stateChanged()
    {
     if (xmlhttp.readyState==4)
    {
       document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
     }
    
    }
    
    function GetXmlHttpObject()
     {
        if (window.XMLHttpRequest)
        {
           // code for IE7+, Firefox, Chrome, Opera, Safari
           return new XMLHttpRequest();
       }
    
    if (window.ActiveXObject)
      {
        // code for IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
    return null;
    }
    </script>
    <title>Add Species information</title>
    </head>
    <frameset rows="40%,60%">
    
      <frame src="frame_a.htm">
    
    
    <form method="post" action="http://...">
    
    <font size=3><b><i>Species : &nbsp;&nbsp;</i></b></font><select name="sname" onchange="showMod(this.value)">
    <option>-- Select One --</option>
    <?php
    
    $con = mysql_connect("localhost","user", "pwd") or die(mysql_error());
    
    mysql_select_db("dbname") or die ( "Couldn't open : ".mysql_error() );
    
    $query = "SELECT * FROM species"; 
    
    $result = mysql_query($query) or die(mysql_error());
    
    for($i=0;$i<mysql_num_rows($result);$i++)
    
    {
    
    $row=mysql_fetch_assoc($result);
    
    echo '<option >'.$row[sname].'</option>';
    
    }
    
    ?>
    
    </select>
    <br />
    
    <br><div id="txtHint"><b>Species info will be displayed here.</b></div>
    
    <center><input type="reset" name="submit" value="Reset">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="Submit"></center>
    <center></center>
    </form>
    </frameset>
    </html>
    And the getdspe.php file is as follows

    Code:
    <html>
    
    <head>
    
    <title>asdf</title>
    
    <script type="text/javascript">
    
    
    
    </script>
    
    </head>
    
    <body>
    
    <form method="post" action="http://......">
    
    <?php
    
    
    
    $q=$_POST["q"];
    
    
    
    $con = mysql_connect('localhost','user','pwd');
    
    
    
    if (!$con)
    
      {
    
      die('Could not connect: ' . mysql_error());
    
      }
    
    
    
    mysql_select_db("dbname", $con);
    
    $sql = "SELECT * FROM species WHERE sname = '".$q."'";
    
    
    
    $result = mysql_query($sql);
    
    
    
    while ($row=mysql_fetch_array($result))
    
    	{
    		$sname=$row["sname"];
    
                    $synonyms=$row["synonyms"];
    
    		$distribution=$row["distribution"]; 
    
    		$author=$row["author"];
    
    		$Extralimital=$row["Extralimital"];
    
    		$variety=$row["variety"];
    
    		$vauthor=$row["vauthor"];
    
    		$form=$row["form"];
    
    		$fauthor=$row["fauthor"];
    
    
    	
    	}	
    	
    
      echo "<table border=\"0\" cellpadding=\"6\" cellspacing=\"6\">";
    
      echo "<tr>";
    
      echo "<td><font size=3><b><i>Species :</i></b></font></td>";
    
      echo "<td><input type=\"text\" name=\"sname\" value=\"$row[sname]\" /></td>";
    
    
    
      echo "<td><font size=3><b><i>Author :</i></b></font></td>";
    
      echo "<td><input type=\"text\" name=\"author\" value=\"$author\" value=\"$row[author]\" /></td>";
    
      echo "</tr>";
    
     
    
      echo "<tr>";
    
      echo "<td><font size=3><b><i>Variety :</i></b></font></td>";
    
      echo "<td><input type=\"text\" name=\"variety\" value=\"$row[variety]\" /></td>";
    
    
    
      echo "<td><font size=3><b><i>Variety Author :</i></b></font></td>";
    
      echo "<td><input type=\"text\" name=\"vauthor\" value=\"$row[vauthor]\" /></td>";
    
      echo "</tr>";
    
    
    
      echo "<tr>";
    
      echo "<td><font size=3><b><i>Form :</i></b></font></td>";
    
      echo "<td><input type=\"text\" name=\"form\" value=\"$row[form]\" /></td>";
    
    
    
      echo "<td><font size=3><b><i>Form Author :</i></b></font></td>";
    
      echo "<td><input type=\"text\" name=\"fauthor\" value=\"$row[fauthor]\" /></td>";
    
      echo "</tr>";
    
    
    
      echo "<tr>";
    
      echo "<td><font size=3><b><i>Synonyms :</i></b></font></td>";
    
      echo "<td><input type=\"text\" name=\"synonyms\" value=\"$row[synonyms]\" /></td>";
    
    
    
      echo "<td><font size=3><b><i>Extralimital :</i></b></font></td>";
    
      echo "<td><input type=\"text\" name=\"Extralimital\" value=\"$row[Extralimital]\" /></td>";
    
      echo "</tr>";
    
    
    
      echo "<tr>";
    
      echo "<td><font size=3><b><i>Distribution :</i></b></font></td>";
    
      echo "<td><textarea name=\"distribution\" rows=\"5\" cols=\"25\" value=\"$row[distribution]\" > </textarea><br /> </td>";
    
      echo "</tr>";
    
    
    
    echo "</table>";
    
    	
    
    
    mysql_close($con);
    
    ?> 
    
    </form>
    
    </body>
    
    </html>

    Pls help me out..... I know my mistake is in the retrieval part.
    Help any one...

    Thanks

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    To begin with, I'd recommend to use a basic form with a submit button(without any ajax) in the first page, and submit run the query from the target page based on the value from the drop down.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,955
    Thanks
    9
    Thanked 726 Times in 720 Posts
    Isn't this the problem:

    PHP Code:
    $q=$_POST["q"]; 
    Aren't you using GET instead of POST from Ajax - so this should be:

    PHP Code:
    $q=$_GET["q"]; 

  • #4
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    Code:
    xmlhttp.open("GET",url,true);
    looks like it
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •