Jump to content

[SOLVED] Please Help Me!!!!


smd8061

Recommended Posts

I am trying to search my database and show the results, but I don't really know what I am doing. There are not any error messages showing up in PUTTY but it will not search and bring back my information. WHAT AM I DOING WRONG!?!?!?!?!?

 

Please Help Me!

 

Here is my code:

 

<html>

 

<body>

 

<form id="form1" name="form1" method="post" action="">

  <label>

  <select name="$select" size="1">

    <option value="PO Number" selected="selected">PO Number</option>

    <option value="Invoice ID">Invoice ID</option>

    <option value="Vendor ID">Vendor ID</option>

    <option value="Material ID">Material ID</option>

    <option value="Date">Date</option>

    <option value="Quantity">Quantity</option>

    <option value="Estimated Total">Estimated Total</option>

    <option value="Total Price">Total Price</option>

    <option value="Due Date">Due Date</option>

  </select>

  <br />

  <br />

  <input type="text" name="textfield" />

  </label>

  <label>

  <input type="submit" name="Submit" value="Submit" />

  </label>

  <label>

  <input type="reset" name="Submit2" value="Reset" />

  </label>

</form>

 

 

<?php

 

 

// Connecting, selecting database

$link = mysql_connect('HOST', 'USERNAME', 'PASSWORD')

    or die('Could not connect: ' . mysql_error());

mysql_select_db('software') or die('Could not select database');

 

// Performing SQL query

$select = '$GET[$select]';

$query = "SELECT * FROM Master WHERE 'HEADING' = '$select'";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

 

// Printing Results

echo "<table border=1 padding=10>\n";

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {

    echo "\t<tr>\n";

    foreach ($line as $col_value) {

        echo "\t\t<td>$col_value</td>\n";

    }

    echo "\t</tr>\n";

}

echo "</table>\n";

 

// Free resultset

mysql_free_result($result);

 

// Closing connection

mysql_close($link);

 

?>

 

</body>

</html>

Link to comment
Share on other sites

<html>

<body>

<form id="form1" name="form1" method="post" action="">
  <label>
  <select name="$select" size="1">
    <option value="PO Number" selected="selected">PO Number</option>
    <option value="Invoice ID">Invoice ID</option>
    <option value="Vendor ID">Vendor ID</option>
    <option value="Material ID">Material ID</option>
    <option value="Date">Date</option>
    <option value="Quantity">Quantity</option>
    <option value="Estimated Total">Estimated Total</option>
    <option value="Total Price">Total Price</option>
    <option value="Due Date">Due Date</option>
  </select>




  <input type="text" name="textfield" />
  </label>
  <label>
   <input type="submit" name="Submit" value="Submit" />
  </label>
  <label>
   <input type="reset" name="Submit2" value="Reset" />
  </label>
</form>


<?php


// Connecting, selecting database
$link = mysql_connect('HOST', 'USERNAME', 'PASSWORD')
    or die('Could not connect: ' . mysql_error());
mysql_select_db('software') or die('Could not select database');

// Performing SQL query
$select = $GET[$select];
$query = "SELECT * FROM Master WHERE HEADING = '$select'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing Results
echo "<table border=1 padding=10>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
        echo "\t\t<td>$col_value</td>\n";
    }
    echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);

?>

</body>
</html>

Link to comment
Share on other sites

$select = '$GET[$select]';

 

If i'm not mistaken, you are making $select a string here, not the actual $_GET value you are trying for.

 

Also, the syntax is $_GET not $GET

Nice pick up there.

 

I fixed the quotes around it, but failed to notice it was missing a _

 

D'oh. :P

Link to comment
Share on other sites

I thought that there might be a syntax that lets you search by the headings of the databases. that is why i tried HEADING.

The correct term for that, is 'column'.

 

A database is consisted of tables, each of which is made up by rows (your data) and columns (what your data is sorted into).

Link to comment
Share on other sites

OK, i guess i wasn't clear on what i was trying to get it to do. I have a drop down box and i want to be able to select a columns name and then in the text box input a number, and when you hit search it will search that number in one of the columns IE: the one you selected in the drop down box. That is where the $select comes from it is the drop down box.

Link to comment
Share on other sites

ok so if i change HEADING for COLUMN it should work?

Say my table is called CATS.

My CATS table consists of these columns:

- Name

- Color

- Breed

- DoB

 

If I wanted to select all the names, I would use:

SELECT Name FROM CATS

 

However, if I wanted to selet the Color and Breed, I would use:

SELECT Color, Breed FROM CATS

 

Finally, if I wanted to select all the data I could either do:

SELECT Name, Color, Breed, DoB FROM CATS

or

SELECT * FROM CATS

 

Hope that helps in some way. Its all dependant on your column names. ;)

Link to comment
Share on other sites

Say my table is called CATS.

My CATS table consists of these columns:

- Name

- Color

- Breed

- DoB

 

If I wanted to select all the names, I would use:

SELECT Name FROM CATS

 

However, if I wanted to selet the Color and Breed, I would use:

SELECT Color, Breed FROM CATS

 

Finally, if I wanted to select all the data I could either do:

SELECT Name, Color, Breed, DoB FROM CATS

or

SELECT * FROM CATS

 

I get that, I just don't know how I would pull the info using forms to select my column name.

 

my columns are:

 

- PO Number

- Invoice ID

- Vendor ID

- Material ID

- Date

- Quantity

- Estimated Total

- Total Price

- Due Date

Link to comment
Share on other sites

Say my table is called CATS.

My CATS table consists of these columns:

- Name

- Color

- Breed

- DoB

 

If I wanted to select all the names, I would use:

SELECT Name FROM CATS

 

However, if I wanted to selet the Color and Breed, I would use:

SELECT Color, Breed FROM CATS

 

Finally, if I wanted to select all the data I could either do:

SELECT Name, Color, Breed, DoB FROM CATS

or

SELECT * FROM CATS

 

I get that, I just don't know how I would pull the info using forms to select my column name.

 

my columns are:

 

- PO Number

- Invoice ID

- Vendor ID

- Material ID

- Date

- Quantity

- Estimated Total

- Total Price

- Due Date

Okay. If I understand you correctly, something like this?..

<html>
<body>

<form id="form1" name="form1" method="post" action="">
  <label>
  <select name="select" size="1">
    <option value="PO Number" selected="selected">PO Number</option>
    <option value="Invoice ID">Invoice ID</option>
    <option value="Vendor ID">Vendor ID</option>
    <option value="Material ID">Material ID</option>
    <option value="Date">Date</option>
    <option value="Quantity">Quantity</option>
    <option value="Estimated Total">Estimated Total</option>
    <option value="Total Price">Total Price</option>
    <option value="Due Date">Due Date</option>
  </select>


  <input type="text" name="textfield" />
  </label>
  <label>
   <input type="submit" name="Submit" value="Submit" />
  </label>
  <label>
   <input type="reset" name="Submit2" value="Reset" />
  </label>
</form>


<?php

// Connecting, selecting database
$link = mysql_connect('HOST', 'USERNAME', 'PASSWORD')
    or die('Could not connect: ' . mysql_error());
mysql_select_db('software') or die('Could not select database');

// Performing SQL query
$table_name = "invoices"; #Change
$select = $_POST["select"];
$textfield = $_POST["textfield"];
$query = "SELECT * FROM $table_name WHERE $select = '$textfield'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing Results
echo "<table border=1 padding=10>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
        echo "\t\t<td>$col_value</td>\n";
    }
    echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);

?>

</body>
</html>

 

A little unclear about your "WHERE" though.

 

Change $table_name to the table name, if its different.

 

Its not very wise naming an element like a PHP variable. Its not going to work at any time. :P

Also, $_GET is for retrieving things in the URL (ie: index.php?select=BLAH) as opposed to straight through the form ($_POST).

 

Edit: added some follow-up info.

Link to comment
Share on other sites

You need to give people more than 5 minutes to reply.  We're not all just sitting here waiting for you to ask a question.

 

Quote from: smd8061 on Today at 10:03:23 AM

Hello Any Body?HuhHuh??

 

Sorry I just am tired of trying to get this to work.

 

and thank you very much twostars I will try this.

Link to comment
Share on other sites

echo out $query and copy in the result so we can see the sql command

 

I did that and this is what it says:

 

Query failed: Query was empty

 

[quote author=smd8061 link=topic=176679.msg784231#msg784231 date=1200063536]
[quote]Say my table is called CATS.
My CATS table consists of these columns:
- Name
- Color
- Breed
- DoB

If I wanted to select all the names, I would use:
SELECT Name FROM CATS

However, if I wanted to selet the Color and Breed, I would use:
SELECT Color, Breed FROM CATS

Finally, if I wanted to select all the data I could either do:
SELECT Name, Color, Breed, DoB FROM CATS
or
SELECT * FROM CATS[/quote]

I get that, I just don't know how I would pull the info using forms to select my column name.

my columns are:

- PO Number
- Invoice ID
- Vendor ID
- Material ID
- Date
- Quantity
- Estimated Total
- Total Price
- Due Date
[/quote]
Okay. If I understand you correctly, something like this?..
[code]
<html>
<body>

<form id="form1" name="form1" method="post" action="">
  <label>
  <select name="select" size="1">
    <option value="PO Number" selected="selected">PO Number</option>
    <option value="Invoice ID">Invoice ID</option>
    <option value="Vendor ID">Vendor ID</option>
    <option value="Material ID">Material ID</option>
    <option value="Date">Date</option>
    <option value="Quantity">Quantity</option>
    <option value="Estimated Total">Estimated Total</option>
    <option value="Total Price">Total Price</option>
    <option value="Due Date">Due Date</option>
  </select>


  <input type="text" name="textfield" />
  </label>
  <label>
   <input type="submit" name="Submit" value="Submit" />
  </label>
  <label>
   <input type="reset" name="Submit2" value="Reset" />
  </label>
</form>


<?php

// Connecting, selecting database
$link = mysql_connect('HOST', 'USERNAME', 'PASSWORD')
    or die('Could not connect: ' . mysql_error());
mysql_select_db('software') or die('Could not select database');

// Performing SQL query
$table_name = "invoices"; #Change
$select = $_POST["select"];
$textfield = $_POST["textfield"];
$query = "SELECT * FROM $table_name";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing Results
echo "<table border=1 padding=10>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
        echo "\t\t<td>$col_value</td>\n";
    }
    echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);

?>

</body>
</html>

 

I took off the WHERE bit.

Told you I was unsure if you wanted that. lol[/code]

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.