Jump to content

I don't GET Forms!


Fearpig

Recommended Posts

???
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/Spares/Test.php?PartsSearch=39810370

so the PartsSearch is there with a value of 39810370.

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

[code]$_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"]);

}[/code]



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?
Link to comment
https://forums.phpfreaks.com/topic/20400-i-dont-get-forms/
Share on other sites

Use this:
[code=php:0]$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"]);

}[/code]

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.
Link to comment
https://forums.phpfreaks.com/topic/20400-i-dont-get-forms/#findComment-89857
Share on other sites

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

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:
[code]
<?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);

?>
[/code]

hope this helps
Link to comment
https://forums.phpfreaks.com/topic/20400-i-dont-get-forms/#findComment-89858
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.