Get and Post Headache
Moderator: General Moderators
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Get and Post Headache
Just do it and I'm pretty sure it will work.
-
crazitrain02
- Forum Newbie
- Posts: 22
- Joined: Wed Dec 08, 2010 5:20 pm
Re: Get and Post Headache
I commented out the <div id='txtHint'> tag from the modify_inventory.php page, and now the form is not showing up on the page after I select an item from the combo box. The alert box still comes back with the proper URL.
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Get and Post Headache
No, don't remove it, move it. Here, like this:
Code: Select all
<html>
<head>
<title>Modify Current Inventory</title>
<link rel="stylesheet" href="CSS\standard.css">
</head>
<body align="center">
<h2>Modify Current Inventory</h2>
Select the part number from the drop-down list to modify.
<?php
include 'admin\db_inventory.php';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to database');
mysql_select_db($dbname);
$query = "SELECT DISTINCT partnum FROM parts;";
if($result = mysql_query($query))
{
if($success = mysql_num_rows($result) > 0)
{
echo "<form method='post' name='partnum' action='get_inventory.php'>";
echo "<select name='partnum' onchange='getInventory(this.value);'>\n";
echo "<option>-- Part Number --</option>\n";
while ($row = mysql_fetch_array($result))
echo "<option value='$row[partnum]'>$row[partnum]</option>\n";
echo "</select>\n<p />";
}
else { echo "No results found."; }
}
else { echo "Failed to connect to database."; }
mysql_close();
?>
</form>
<div align="center" id="txtHint"></div>
<script type="text/javascript">
function getInventory(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","get_inventory.php?q="+str,true);
xmlhttp.send();
}
</script>
<br />
<FORM>
<INPUT TYPE="button" VALUE="Home" onclick="window.location.href='index.php';" />
<INPUT TYPE="button" VALUE="View Inventory" onclick="window.location.href='current_inventory.php';" />
</FORM>
</body>
</html>-
crazitrain02
- Forum Newbie
- Posts: 22
- Joined: Wed Dec 08, 2010 5:20 pm
Re: Get and Post Headache
I tried that code change, but now it will not POST the data to the modify.php page.
I also noticed that in my original code that I never closed out the first form with the combo box, but even closing out that form with the second form inside of it doesn't work.
I also noticed that in my original code that I never closed out the first form with the combo box, but even closing out that form with the second form inside of it doesn't work.
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Get and Post Headache
You need to change it so that the form loaded with Ajax is not placed inside of the first form.
-
crazitrain02
- Forum Newbie
- Posts: 22
- Joined: Wed Dec 08, 2010 5:20 pm
Re: Get and Post Headache
Here is my code now for the modify_inventory.php page:
This should not be loading the Ajax in the first form correct?
Code: Select all
<html>
<head>
<title>Modify Current Inventory</title>
<link rel="stylesheet" href="CSS\standard.css">
</head>
<body align="center">
<h2>Modify Current Inventory</h2>
Select the part number from the drop-down list to modify.
<?php
include 'admin\db_inventory.php';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to database');
mysql_select_db($dbname);
$query = "SELECT DISTINCT partnum FROM parts;";
if($result = mysql_query($query))
{
if($success = mysql_num_rows($result) > 0)
{
echo "<form method='post' name='partnum' action='get_inventory.php'>";
echo "<select name='partnum' onchange='getInventory(this.value);'>\n";
echo "<option>-- Part Number --</option>\n";
while ($row = mysql_fetch_array($result))
echo "<option value='$row[partnum]'>$row[partnum]</option>\n";
echo "</select>\n
<p />
</form>";
}
else { echo "No results found."; }
}
else { echo "Failed to connect to database."; }
mysql_close();
?>
<script type="text/javascript">
function getInventory(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","get_inventory.php?q="+str,true);
xmlhttp.send();
}
</script>
<div align="center" id="txtHint" />
<br />
<FORM>
<INPUT TYPE="button" VALUE="Home" onclick="window.location.href='index.php';" />
<INPUT TYPE="button" VALUE="View Inventory" onclick="window.location.href='current_inventory.php';" />
</FORM>
</body>
</html>- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Get and Post Headache
Yes, I think that'll work. Try it.
-
crazitrain02
- Forum Newbie
- Posts: 22
- Joined: Wed Dec 08, 2010 5:20 pm
Re: Get and Post Headache
In Chrome and IE when I hit the submit button none of the variables are being POSTed to the modify.php page.
In Firefox when I hit the submit button I get the same Undefined index: q error as before.
In Firefox when I hit the submit button I get the same Undefined index: q error as before.
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Get and Post Headache
Sounds like it's mostly working. You probably just need to clear your Firefox cache.
-
crazitrain02
- Forum Newbie
- Posts: 22
- Joined: Wed Dec 08, 2010 5:20 pm
Re: Get and Post Headache
I can always work on compatibility later, but now it's not POSTing the variables from the form. Any ideas?
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Get and Post Headache
That's because the form in get_inventory.php uses the POST method.
-
crazitrain02
- Forum Newbie
- Posts: 22
- Joined: Wed Dec 08, 2010 5:20 pm
Re: Get and Post Headache
Is there another way that I can "post" the data from the form and update it in the MySQL database, or should I try and figure out another way of doing this?
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Get and Post Headache
Er, do you want to POST or GET? Just change the method attribute of the form in get_inventory to whichever one you want.
-
crazitrain02
- Forum Newbie
- Posts: 22
- Joined: Wed Dec 08, 2010 5:20 pm
Re: Get and Post Headache
I'm an idiot... It is POSTing the data, but just not the one variable that I'm looking for.
Thanks for all of your help
I've been looking for days trying to figure this out, but haven't found anything.
Thanks for all of your help