Jump to content

[SOLVED] PHP + Ajak Error


june_c21

Recommended Posts

hi, i try to run this code but when i code on the select menu, there is no information display. can someone tell me what's the mistake?

 

html page

 

<html>

 

<head>

 

<script src="selectuser.js"></script>

 

</head>

 

<body><form>

 

  <table width="497" border="0">

 

    <tr>

 

      <td width="284">Staff No </td>

 

      <td width="203"><input type="text" name="textfield"></td>

 

    </tr>

 

 

 

    <tr>

 

      <td>GF</td>

 

      <td><input type="text" name="textfield2"></td>

 

    </tr>

 

    <tr>

 

      <td>Designation</td>

 

      <td><input type="text" name="textfield3"></td>

 

    </tr>

 

    <tr>

 

      <td>Date Of Borrow </td>

 

      <td><input type="text" name="textfield4"></td>

 

    </tr>

 

    <tr>

 

      <td>Tools</td>

 

      <td><select name="tool_list" onChange="showUser(this.value)">

 

        <option value="1">Allen Keys (2MM)</option>

 

        <option value="2">Allen Keys (2.5MM)</option>

 

        <option value="3">Glenn Quagmire</option>

 

        <option value="4">Joseph Swanson</option>

 

      </select></td>

 

    </tr>

 

    <tr>

 

      <td colspan="2"><p>

 

<div id="txtHint"><b>Info will be listed here.</b></div>

 

</p> </td>

 

    </tr>

 

    <tr>

 

      <td>Quantity</td>

 

      <td><input type="text" name="textfield5"></td>

 

    </tr>

 

    <tr>

 

      <td>Status</td>

 

      <td><select name="select">

 

        <option>Borrow</option>

 

      </select>      </td>

 

    </tr>

 

  </table>

 

  <p> </p>

 

  <p>

 

    <input type="submit" name="Submit" value="Submit">

 

  </p>

 

</form></body>

 

</html>

 

javascript

 

var xmlHttpfunction showUser(str)

 

{

 

xmlHttp=GetXmlHttpObject()

 

if (xmlHttp==null)

 

{

 

alert ("Browser does not support HTTP Request")

 

return

 

}

 

var url="getuser.php"

 

url=url+"?id="+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;

 

}

 

php code

 

<?php

 

$id=$_GET["id"];

 

 

 

$host = 'localhost';

 

$user = 'root';

 

$password = 'admin';

 

$dbase = 'tool';

 

 

 

$dblink = mysql_connect($host,$user,$password);

 

mysql_select_db($dbase,$dblink);

 

 

 

$sql="SELECT * FROM tool_list WHERE id = '".$id."'";

 

 

 

$result = mysql_query($sql);

 

 

 

echo "<table border='1'>

 

<tr>

 

<th>ID</th>

 

<th>Title</th>

 

<th>Model</th>

 

<th>Capacity</th>

 

<th>Quantity</th>

 

</tr>";

 

 

 

while($row = mysql_fetch_array($result))

 

{

 

echo "<tr>";

 

echo "<td>" . $row[0] . "</td>";

 

echo "<td>" . $row[1] . "</td>";

 

echo "<td>" . $row[2] . "</td>";

 

echo "<td>" . $row[3] . "</td>";

 

echo "<td>" . $row[4] . "</td>";

 

echo "</tr>";

 

}

 

echo "</table>";

 

 

 

?>

 

 

Link to comment
Share on other sites

Mind using


tags?

 

var xmlHttpfunction showUser(str)

 

Should be:

var xmlHttp; function showUser(str)

 

xmlHttp=GetXmlHttpObject()

 

Should be: (just testing up to IE 7.0)

xmlHttp = (window.ActiveXObject)? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();

 

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

 

Uh, what's the point of checking both of those?

if (xmlHttp.readyState==4)

Link to comment
Share on other sites

hi, sorry... i just update my code. can anyone help with the the listing the option value from database?

html page

<html>

<head>

<script src="selectuser.js"></script>

</head>

<body><form> 

 <table width="497" border="0">

   <tr>

     <td width="284">Staff No </td>

     <td width="203"><input type="text" name="textfield"></td>

   </tr>



   <tr>

     <td>GF</td>

     <td><input type="text" name="textfield2"></td>

   </tr>

   <tr>

     <td>Designation</td>

     <td><input type="text" name="textfield3"></td>

   </tr>

   <tr>

     <td>Date Of Borrow </td>

     <td><input type="text" name="textfield4"></td>

   </tr>

   <tr>

     <td>Tools</td>

     <td><select name="tool_list" onChange="showUser(this.value)">

       <option value="1">Allen Keys (2MM)</option>

       <option value="2">Allen Keys (2.5MM)</option>

       <option value="3">Glenn Quagmire</option>

       <option value="4">Joseph Swanson</option>

     </select></td>

   </tr>

   <tr>

     <td colspan="2"><p>

<div id="txtHint">Info will be listed here.</div>

</p> </td>

   </tr>

   <tr>

     <td>Quantity</td>

     <td><input type="text" name="textfield5"></td>

   </tr>

   <tr>

     <td>Status</td>

     <td><select name="select">

       <option>Borrow</option>

     </select>      </td>

   </tr>

 </table>

 <p> </p>

 <p>

   <input type="submit" name="Submit" value="Submit">

 </p>

</form></body>

</html>

 

javascipt

var xmlHttp; function showUser(str)
{ 
xmlHttp = (window.ActiveXObject)? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getuser.php"
url=url+"?id="+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;
}

 

php

<?php
$id=$_GET["id"];

$host = 'localhost';
$user = 'root';
$password = 'admin';
$dbase = 'tool';

$dblink = mysql_connect($host,$user,$password);
mysql_select_db($dbase,$dblink);

$sql="SELECT * FROM tool_list WHERE id = '".$id."'";

$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>ID</th>
<th>Title</th>
<th>Model</th>
<th>Capacity</th>
<th>Quantity</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row[0] . "</td>";
echo "<td>" . $row[1] . "</td>";
echo "<td>" . $row[2] . "</td>";
echo "<td>" . $row[3] . "</td>";
echo "<td>" . $row[4] . "</td>";
echo "</tr>";
}
echo "</table>";

?>

Link to comment
Share on other sites

Remove the html :

        <option value="1">Allen Keys (2MM)</option>

        <option value="2">Allen Keys (2.5MM)</option>

        <option value="3">Glenn Quagmire</option>

        <option value="4">Joseph Swanson</option>

and add the php code :

 

<?php
      $host = 'localhost';
$user = 'username';
$password = 'password';
$dbase = 'db_name';
$dblink = mysql_connect($host,$user,$password);
mysql_select_db($dbase,$dblink);
$sql="SELECT * FROM tablename ";
$result = mysql_query($sql);
while($arr=mysql_fetch_assoc($result)){
	echo "<option value='".$arr['id']."'>".$arr['name']."</option>";
}      
?>

 

and change the sql according to your need.

 

rgds

Sharad

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.