SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ajax php mysql select menu problem

    im working on a ajax select menu list depending on what you select the details of the product is shown but it doesnt do anything this is what i have atm.

    Html code

    Code HTML4Strict:
    <script src="selectuser.js"></script>
    		<form method="post" action="">
    		<select name="plan" onChange="showUser(this.value)">
    			<?php
    			include("dbconnect.php");	//
    		   $rQuery="SELECT * FROM servers";
    			echo $rQuery;
    			$rs=mysqli_query($con,$rQuery);
    			if(!$rs)
    			{
    				echo "Error:".mysqli_error($con);
    			}
    			else
    			{
    				//
    				$count=$rs->num_rows;
    				if($count>0)
    				{
    					while($data=$rs->fetch_assoc())
    					{
    					 echo "<option value=".$data['sid'].">".$data['hpcpu']."</option>";
    					}
    				}
    			}
    			?>
    		</select>
    		</form>
    		<fieldset>
    			<legend>Product Description</legend>
    			<div id="txtHint">Data will be entered here</div>
    		</fieldset>

    for javascript/ajax code i have this

    Code JavaScript:
    var xmlHttp;
     
    function showUser(str)
    { 
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
     {
     alert ("Browser does not support HTTP Request");
     return;
     }
    var url="getuser.php";
    url=url+"?sid="+str;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    }
     
    function stateChanged() 
    { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     { 
     document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
     } 
    }
     
    function GetXmlHttpObject()
    {
    var xmlHttp=null;
    try
     {
     // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
     }
    catch (e)
     {
     //Internet Explorer
     try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
     catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
     }
    return xmlHttp;
    }

    and for my getting plan info i have this

    PHP Code:
    $sid=$_GET['sid'];
        if(
    $sid)
        {
            
    //
            
    include("dbconnect.php");    //
               
    $rQuery="SELECT * FROM servers WHERE sid='".$sid."'";
                echo 
    $rQuery;
                
    $rs=mysqli_query($con,$rQuery);
                if(!
    $rs)
                {
                    echo 
    "Error:".mysqli_error($con);
                }
                else
                {
                    
    //
                    
    $count=$rs->num_rows;
                    if(
    $count>0)
                    {
                        while(
    $data=$rs->fetch_assoc())
                        {
                            echo 
    "<table>
                            <tr>
                                <th>"
    .$data['gram']."</th>
                                <th>Guarantee Ram</th>
                            </tr>
                            <tr>
                                <th>"
    .$data['bram']."</th>
                                <th>Burstable Ram</th>
                            </tr>
                            <tr>
                                <th>"
    .$data['hpspace']."</th>
                                <th>Disk Space</th>
                            </tr>
                            <tr>
                                <th>"
    .$data['bdwidth']."</th>
                                <th>Prenium Bandwidth</th>
                            </tr>
                            <tr>
                                <th>&nbsp;</th>
                            </tr>
                            <tr>
                                <th colspan="
    2">Hypervm VPS PowerPanel</th>
                            </tr>
                            <tr>
                                <th colspan="
    2">".$data['ips']."&nbsp;IP Addresses</th>
                            </tr>
                            <tr>
                                <th colspan="
    2">Choice of     Operating System</th>
                            </tr>
                            <tr>
                                <th>"
    .$data['hpcost']."&nbsp;Per Month</th>
                            </tr>
                            <tr>
                                <th>&nbsp;</th>
                            </tr>
                            <tr>
                                <th>Monthly</th>
                                <th>"
    .$data['hpcost']."</th>
                            </tr>
                            <tr>
                                <th>Quarterly</th>
                                <th>"
    .$data['hpcost']."</th>
                            </tr>
                            <tr>
                                <th>Semi-Annually</th>
                                <th>"
    .$data['hpcost']."</th>
                            </tr>
                            <tr>
                                <th>Yearly</th>
                                <th>"
    .$data['hpcost']."</th>
                            </tr>
                        </table>"
    ;
                        }
                    }
                }
            
    //
        

    Now when i select a option from dropdown list it does not update txtHint id for some reason it just stays the same what am i do wrong?

    Can anyone help

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there an error in your JS console?

  3. #3
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope no error in the javascript console in firefox.

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You seem to be mixing procedural and OO MySQLi functions / methods, as far as I know, you cannot do this.

    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so how can i fix this?

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Can you post dbconnect.php?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #7
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is dbconnect file

    PHP Code:
    $dbhost="localhost";
        
    $dbuser="root";
        
    $dbpassword="PASS";
        
    $dbname="hostingbilling";
        
    $con=mysqli_connect($dbhost,$dbuser,$dbpassword,$dbname);
        if(!
    $con)
        {
            echo 
    "Unable to connect to Database";
            exit;
        } 

  8. #8
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <script src="selectuser.js"></script>
    <form method="post" action="">
    <select name="plan" onChange="showUser(this.value)">
    <?php
    include("dbconnect.php");   //
    $rResult mysqli_query($con'SELECT sid, hpcpu FROM servers');
    if(!
    $rResult)
    {
        echo 
    "Error:".mysqli_error($con);
    }
    else
    {
        if(
    mysqli_num_rows($rResult) > 0)
        {
            while(
    $data=mysql_fetch_assoc($rResult))
            {
                echo 
    "<option value=".$data['sid'].">".$data['hpcpu']."</option>";
            }
        }
    }
    ?>
    </select>
    </form>
    <fieldset>
    <legend>Product Description</legend>
    <div id="txtHint">Data will be entered here</div>
    </fieldset>
    PHP Code:
    <?php
    if(isset($_GET['sid']) && ! empty($_GET['sid']))
    {
        
    $iSID = (Int)$_GET['sid'];
        include(
    'dbconnect.php');
        
    $sSQL sprintf(
            
    "SELECT * FROM servers WHERE sid = %s",
            
    $iSID
        
    );
        
    $rResult mysqli_query($con$sSQL);
        if(
    is_resource($rResult) && (mysqli_num_rows($rResult) > 0))
        {
            while(
    $data mysqli_fetch_assoc($rResult))
            {
                echo 
    "<table>

                            <tr>

                                <th>"
    .$data['gram']."</th>

                                <th>Guarantee Ram</th>

                            </tr>

                            <tr>

                                <th>"
    .$data['bram']."</th>

                                <th>Burstable Ram</th>

                            </tr>

                            <tr>

                                <th>"
    .$data['hpspace']."</th>

                                <th>Disk Space</th>

                            </tr>

                            <tr>

                                <th>"
    .$data['bdwidth']."</th>

                                <th>Prenium Bandwidth</th>

                            </tr>

                            <tr>

                                <th>&nbsp;</th>

                            </tr>

                            <tr>

                                <th colspan=\"2\">Hypervm VPS PowerPanel</th>

                            </tr>

                            <tr>

                                <th colspan=\"2\">"
    .$data['ips']."&nbsp;IP Addresses</th>

                            </tr>

                            <tr>

                                <th colspan=\"2\">Choice of     Operating System</th>

                            </tr>

                            <tr>

                                <th>"
    .$data['hpcost']."&nbsp;Per Month</th>

                            </tr>

                            <tr>

                                <th>&nbsp;</th>

                            </tr>

                            <tr>

                                <th>Monthly</th>

                                <th>"
    .$data['hpcost']."</th>

                            </tr>

                            <tr>

                                <th>Quarterly</th>

                                <th>"
    .$data['hpcost']."</th>

                            </tr>

                            <tr>

                                <th>Semi-Annually</th>

                                <th>"
    .$data['hpcost']."</th>

                            </tr>

                            <tr>

                                <th>Yearly</th>

                                <th>"
    .$data['hpcost']."</th>

                            </tr>

                        </table>"
    ;
            }
        }
    }
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


Bookmarks

Posting Permissions

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