Jump to content

form problem in php


unistake

Recommended Posts

Hi all,

 

I have a select box that works fine in normal html if i list the mysql values by hand, however when I try to get the values from a mysql database using the code below, the script DOES NOT work in IE and some other browsers, however it DOES work in Mozilla.

Do you know where I have gone wrong?

Thanks

 

 

<?php
echo "
   <select name='users' style='margin-left:-10px; padding:7px; width:270px; height:40px; background-color:#C0DB5A; border:2px solid #888888; font-size:16px;'>
    <option>1. select...</option>";

while ($row = mysql_fetch_assoc($result))
{
extract($row);
    echo "<option value='$bookmaker' onClick=\"showUser(this.value)\">$bookmaker</option>";
}
echo "</select>";
?>

 

p.s - when testing any website script, what browser is best to use? I use mozilla, however I am not sure if this is right because of problems like above!

Link to comment
https://forums.phpfreaks.com/topic/171962-form-problem-in-php/
Share on other sites

This is the full PHP code that is included in another PHP page that contains <script type="text/javascript" src="selectuser.js"></script>

the above javascript works as it should when using it with just a HTML version of the select box below.

 

The full PHP code is here

// included PHP code ////
<?php 
$con = mysql_connect('localhost', 'user', 'password');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("db", $con);

$sql="SELECT * FROM bookmakers";

$result = mysql_query($sql);

    
echo "
   <select name='users' style='margin-left:-10px; padding:7px; width:270px; height:40px; background-color:#C0DB5A; border:2px solid #888888; font-size:16px;'>
    <option>1. select...</option>";

while ($row = mysql_fetch_assoc($result))
{
extract($row);
    echo "<option value='$bookmaker' onClick=\"showUser(this.value)\">$bookmaker</option>";
}
echo "</select>";

?>

 

/// main.php //
<?php include("selectoption.php"); ?>
	<div id="txtHint"><p>select an option from above</div>   

 

// JavaScript Document

var xmlhttp;

function showUser(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="getuser.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;
}

 

Link to comment
https://forums.phpfreaks.com/topic/171962-form-problem-in-php/#findComment-906756
Share on other sites

also the getuser.php script is

 

<?php

$q=$_GET["q"];

include("login.inc");

 

 

mysql_select_db("$database", $con);

 

$sql="SELECT * FROM bookmakers WHERE bookmaker = '".$q."'";

 

$result = mysql_query($sql);

 

 

while($row = mysql_fetch_array($result))

{

    echo $row['bookmaker'];

    echo $row['bonus'];

}

 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/171962-form-problem-in-php/#findComment-906776
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.