Jump to content


Photo

I don't GET Forms!


  • Please log in to reply
3 replies to this topic

#1 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 11 September 2006 - 03:28 PM

???
Hi Guys I'm having a few problems with my forms. I have a text box passing a variable using GET to the next page. The address bar has:
http://fer-post/test...Search=39810370

so the PartsSearch is there with a value of 39810370.

However using the following code I just get the error shown below:

$_GET['PartsSearch']

$result = mysql_query("SELECT * FROM tbl_parts WHERE Air_Pressure_Switch=$PartsSearch", $db);        
$row = mysql_fetch_array($result);

while ($row = mysql_fetch_array($result)) {

    printf("<b class='Body2'>%s</b><br>", $row["Model"]);
	
}



Error message:

Parse error: parse error, unexpected T_VARIABLE in D:\Intranet v3\TEST\Spares\test.php on line 7

(line 7 is the $result line) Can anyone see where I'm going wrong?
"Whats wrong with the cat?" - Mrs Schrödinger

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 11 September 2006 - 03:35 PM

Use this:
$PartsSearch = $_GET['PartsSearch'];

$result = mysql_query("SELECT * FROM tbl_parts WHERE Air_Pressure_Switch='$PartsSearch'", $db);
$row = mysql_fetch_array($result);

while ($row = mysql_fetch_array($result)) {

    printf("<b class='Body2'>%s</b><br>", $row["Model"]);

}

From looking at your code, you didnt the define the $PartsSearch variable. However thats not the problem. The problem is where you have $_GET['PartsSearch'] on its own. You didnt add a semi-colon after $_GET['PartsSearch'].  Thats why your got the parse error.

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 11 September 2006 - 03:36 PM

you're not doing anything at all with this line:
<?php
$_GET['PartsSearch'];
?>

you need to assign the value of that $_GET to the variable you're trying to use in the query or else just use $_GET itself in your query:
<?php
// either
$PartsSearch = $_GET['PartsSearch'];
$result = mysql_query("SELECT * FROM tbl_parts WHERE Air_Pressure_Switch=$PartsSearch", $db);

// or
$result = mysql_query("SELECT * FROM tbl_parts WHERE Air_Pressure_Switch=$_GET[PartsSearch]", $db);

?>

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 11 September 2006 - 03:58 PM

Corr you two are quick and teaching me loads!  ;D

I have to be more careful with my code.
Thank you both.

Tom
"Whats wrong with the cat?" - Mrs Schrödinger




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users