Jump to content

Recommended Posts

I am having an issue where the sql query returns undefined as I believe I am not passing a variable through correctly.  I want to have the quantity be shown by selecting the order number... code below.

 

addparts.php

<script type="text/javascript">
<!-- 
// BROWSER SUPPORT CODE
var xmlhttp;
var republicordernumber;
function loadAjax(url, cfunc){
try{
	// Opera 8.0+, Firefox, Safari
	xmlhttp = new XMLHttpRequest();
} catch (e){
	// Internet Explorer Browsers
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){
			// Something went wrong
			alert("Your browser broke!");
			return false;
		}
	}
}

// var emp_id = document.getElementById('emp_id').value;
// var queryString = "?emp_id=" + emp_id;
// ajaxRequest.open("GET", "ajax-example.php" + queryString, true);

// xmlhttp.open("GET","ajax-example.php", true);
// xmlhttp.send(); 

// ADD IN QUERY STRING TO PASS ORDER NO TO PHP PAGE
//var queryString = "?republicordernumber=" + republicordernumber;
xmlhttp.onreadystatechange=cfunc;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}

// GETS ORDER NUMBERS
function getOrderNos()
{
loadAjax("ajax-example.php", function(){
	if(xmlhttp.readyState == 4 ){
		var orders_dd = document.getElementById('order_no');
		orders_dd.innerHTML = xmlhttp.responseText;
		var quant_it = document.getElementById('quant_no');
		quant_it.innerHTML = xmlhttp.responseText;
	}
}
)
}

// SHOWS ORDER NUMBERS
function showParts(order_nb,quant_nb)
{
var orders_lbl = document.getElementById('orders_msg');
orders_lbl.innerHTML = "You have selected order #: " + order_nb;
var quant_lbl = document.getElementById('quant_msg');
quant_lbl.innerHTML = "You have ordered this amount: " + quant_nb;
}

//-->
</script>
</head>

<body onload="getOrderNos()">

<form name="partsubmission" id="partsubmission" method="post" action="">
<table width="100%" border="0">
  <tr>
    <th scope="col" width="100%"><div align="center"><strong>PARTS INFORMATION:</strong></div></th>
  </tr>
</table>
<table width="100%" border="0">
  <tr>
    <th scope="col" width="50%"><div align="left"><strong>Order Number:</strong> <div id="order_no"></div> <div id="orders_msg"></div><div id="qaunt_no"></div> <div id="quant_msg"></div></div> </th>
    <th scope="col" width="50%"><div align="right"><strong>Add: <input type="button" title="Add Row" value="Add Row" onclick="AddRow(this)"></strong></div></th>
  </tr>
</table>
</body>
</html>

 

ajax-example.php

<?php
$dbhost = "10.0.0.21";
$dbuser = "web-republic";
$dbpass = "1038stor";
$dbname = "web-orderlog";
//CONNECT TO MYSQL
mysql_connect($dbhost, $dbuser, $dbpass);
// SELECT DATABASE
mysql_select_db($dbname) or die(mysql_error());
// RETRIEVE DATA FROM QUERY STRING
$republicordernumber = $_GET['republicordernumber'];
//$quantity1 = $_GET['quantity1'];
//$emp_id = $_GET['emp_id'];

// ESCAPE USER INPUT TO HELP PREVENT SQL INJECTION
//$emp_id = mysql_real_escape_string($emp_id);

// QUERY SECTION
//$query = "SELECT republicordernumber FROM orderstest WHERE emp_id = '$emp_id'";
$query = "SELECT republicordernumber FROM orderstest ORDER BY republicordernumber asc";
//$query = "SELECT republicordernumber FROM orderstest";
//$query = "SELECT republicordernumber,quantity1 FROM orderstest WHERE republicordernumber = '$republicordernumber'";

// EXECUTE QUERY
$qry_result = mysql_query($query) or die(mysql_error());

//Build Result String
/*
$display_string = "<table>";
$display_string .= "<tr>";
$display_string .= "<th>Name</th>";
$display_string .= "<th>Age</th>";
$display_string .= "<th>Sex</th>";
$display_string .= "<th>WPM</th>";
$display_string .= "</tr>";
*/

// INSERT A NEW ROW IN THE TABLE FOR EACH PERSON RETURNED
//$display_string = "Items fetched are: ";
$display_string = "<select name='orders_dd' onchange='showParts(this.value)'>";

while($row = mysql_fetch_array($qry_result)){
//	$display_string .= " 
$display_string .= "<option value='$row[republicordernumber]'>$row[republicordernumber]</option>";
}
$display_string .= "</select>";
//$display_string .= "<br />";
//$display_string .= "<input name='quant_it' value='$row[qauntity1]' onchange='showQuant(this.value)' />";

// ESCAPE USER INPUT TO PREVENT SQL INJECTION
//$emp_id = mysql_real_escape_string($emp_id);
//$query2 = "SELECT quantity1 FROM orderstest WHERE republicordernumber = '$republicordernumber'";

//Execute query
//$qry_result2 = mysql_query($query2) or die(mysql_error());

// Insert a new row in the table for each person returned
//$display_string = "Items fetched are: ";
//$display_string2 = "<input name='qauntity1' onchange='showQuant(this.value)'>";

//while($row2 = mysql_fetch_array($qry_result2)){
//$display_string2 = "<input name='quant_inp' value='$row2[qauntity1]' onchange='showParts(this.value)' />";
//	$display_string2 .= " 
//	$display_string2 .= "<option value='$row[republicordernumber]'>$row[republicordernumber]</option>";
//}
//$display_string2 .= "</select>";

//echo $query2
echo $display_string;

?>

Link to comment
https://forums.phpfreaks.com/topic/248905-issue-passing-a-variable-php/
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.