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
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
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
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.