Jump to content

$_Post isset but returns no value from form?


webdogjcn

Recommended Posts

I could just be over looking something incredibly simple here but im processing this form from one page:

<form action="search_classes_process.php" method="post">
<input name="desc" type="hidden" value="number">
Unique KU Class Number: <input type="text" name="classid"><br>
<input type="Submit" value="Search">
</form>

 

NOTE: the purpose of the hidden input value is because there are several forms on this page all being processed through the same "search_classes_process.php" file. And the hidden value is to identify which form we are processing.

 

Now on our "search_classes_process.php" file we have:

mysql_select_db($database, $con);
if ($_Post["desc"] == "number")
{
	$query="Select KUclassID from classes where KUclassID='$_Post[number]'";
	if ($query){
		echo" Exists";
	}
	else{
		echo"DNE";
	}
}
else
{
	echo "error";
                echo $_Post["desc"];
}

 

Now Im not getting any PHP errors or anything. I have tried eliminating all the db checking and gone with simple isset($_Post["desc"]) checks and it isset but if i try echo $_Post["desc"]; I still get nothing.

 

NOTE: I have tried changing the type of field out of hidden as well

 

Link to comment
Share on other sites

alright thanks i feel really dumb.

 

One more question...This code is being used to search a database for specific entries so Im using this right now

elseif ($_POST["desc"] == 'info')
{
	$query=mysql_query("SELECT * from classes WHERE Category=$_POST[subject] && Number=$_POST[course]");
	if (mysql_num_rows($query) > 0){
		echo" Entry Found Redirecting to Class Page...";
	}
	else{
		header('Location: http://somesite.com/search_classes.php?error=dne');
	}

 

I search for values I know exist in the database and it still redirects me. If I eliminate the $_POST[subject] search however, it can find it. I think it has to do with the type of variables in the table. the $_POST[course] is an integer value in the table and I converted it early using

if (isset($_POST["course"])) {$_POST["course"] = intval ($_POST["course"]);}  //converts form value to integer

 

however the Category field is classified as a VARCHAR string in the table. Could this be the reason why it cannot locate the entry? if so how do I convert a $_POST string to VARCHAR? or am I making another simple error

Link to comment
Share on other sites

No, strings in PHP are fine as VARCHARs in MySQL. What you should do is enclose the value in quotes since it is a string and check if you're getting an error with the query. You also never trust user input.

<?php
$q = "SELECT * from classes WHERE Category='" . mysql_real_escape_string($_POST['subject']) . "' && Number=$_POST[course]";
$query = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
?>

 

Since Number is an integer, it doesn't need to be in quotes.

 

Ken

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.