Jump to content

variable help


witham

Recommended Posts

I am really at my wits end with this problem and I really hope someone can please help. The problem is that I have a page called searchweld.php which is a form that has a text box called "Searchman" that stores the variable for the processing page weldsearch.php to search the database:

searchweld looks like this:

[code]<!-- open the form and send the reults to weldsearch.php for processing -->

<form action="weldsearch.php" method="get">
<hr>
<tr><td colspan = 3><h2 align = "center"><b>SEARCH DATABASE</b></h2></td><tr>
<br>
<br>
<br>
<br
<tr><td colspan = 2><h3 align=center>This screen allows users to search for equivalents within the database by name of part name</h3></td></tr>
<tr><td><b>Product Name:</b></td>
<td><input type text name="Searchman"></td></tr>

<!-- put in a submit button to send the data to weldsearch.php -->

<tr><td colspan = 2 align = center><button type="submit">SEARCH THE EQUIVALENTS DATABASE BY PRODUCT NAME</button></td></tr>[/code]

now when I press submit it goes to weldsearch.php that looks like this:

[code]$sqlCOMPARE = "SELECT MANNAME, prodtype, proddesc, prodnar, prodequiv FROM man, produse, prodname
      where proddesc like '%$Searchman%'
      and prodid = useid
      and manno = MANID
      order by MANNAME";

// mysql_connect connects to the database server and returns a link to the the resource
$dblink = @mysql_connect("$dbhost","$dbpass")
or die("<p><b>Could not connect to database server: ($dbhost)</b></p>\n");

// mysql_select_db selects a database to use on the database server pointers to by $dblink
// the @ sign before the command supresses any error messages
@mysql_select_db ($dbname , $dblink)
or die ("<p><b>Could not connect to database ($dbname)</b></p>\n");



// now execute the next query to return the table data to display

$result  = mysql_query($sqlCOMPARE, $dblink)
or die("<p>Error Processing Query</p><hr /><p>".mysql_error()."</p>\n");


if (  mysql_num_rows($result) < 1  ){ 
header("Location: noprod.php"); 
die ("opps"); 

}
[/code]

and then:

[code]echo '<table align = "center" border="1">' . "\n";
echo "<tr bgcolor = #000000><td>MANUFACTURER</td><td>PRODUCT TYPE</td><td>PRODUCT NAME</td><td>PRODUCT DESCRIPTION</td><td>PRODUCT EQUIVALENT</td></tr>\n";


// mysql_fetch_array fetches the results from the query a row at a time each time it's called
// the result is returned as an array that can be referenced either by field name or by it's index

while ($row = mysql_fetch_array ($result))
// loop through the rows outputing them as html table rows
  {



// $row["fieldname"] returns the content for the field in the current row

  echo "<tr><td align = center>" . $row["MANNAME"]. "</td>";

  echo "<td>"  .$row["prodtype"].  "</td>";

  echo "<td>"  .$row["proddesc"].  "</td>";

echo "<td>"  .$row["prodnar"]. "</td>";

  echo "<td>"  .$row["prodequiv"].  "</td></tr>";


  }
// close html table tag
echo "</table>\n";
[/code]

The problem is that when I run the code everything in the database in displayed even though "$Searchman" in weldsearch.php contains only the text typed into "Searchman" from searchweld.php I have been tinkering for a week now and cannot figure it!!!
Link to comment
Share on other sites

Hi,

'%$Searchman%'

could you try concatenating the whole thing?

$sqlCOMPARE = "SELECT MANNAME, prodtype, proddesc, prodnar, prodequiv FROM man, produse, prodname
      where proddesc like[b] ".$Searchman." [/b]
      and prodid = useid
      and manno = MANID
      order by MANNAME";

Maybe this could solve it.
Link to comment
Share on other sites

If you're using phpMyAdmin you can use that, it's a file that you can run to add data into a database, it would allow me to create the tables and insert the data that you have in order for me to be able to test your code.

A dump looks like this:

[code]
-- phpMyAdmin SQL Dump
-- version 2.6.1
-- http://www.phpmyadmin.net
--
-- Host: ***.***.***.***
-- Generation Time: Oct 19, 2006 at 07:55 PM
-- Server version: 4.1.19
-- PHP Version: 4.3.2
--
-- Database: `osCom`
--

-- --------------------------------------------------------

--
-- Table structure for table `banners`
--

CREATE TABLE `banners` (
  `banners_id` int(11) NOT NULL auto_increment,
  `banners_title` varchar(64) NOT NULL default '',
  `banners_url` varchar(255) NOT NULL default '',
  `banners_image` varchar(64) NOT NULL default '',
  `banners_group` varchar(10) NOT NULL default '',
  `banners_html_text` text,
  `expires_impressions` int(7) default '0',
  `expires_date` datetime default NULL,
  `date_scheduled` datetime default NULL,
  `date_added` datetime NOT NULL default '0000-00-00 00:00:00',
  `date_status_change` datetime default NULL,
  `status` int(1) NOT NULL default '1',
  PRIMARY KEY  (`banners_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Dumping data for table `banners`
--

INSERT INTO `banners` VALUES (1, 'osCommerce', 'http://www.oscommerce.com', 'banners/oscommerce.gif', '468x50', '', 0, NULL, NULL, '2006-08-29 20:23:40', NULL, 1);

-- --------------------------------------------------------

--
-- Table structure for table `banners_history`
--

CREATE TABLE `banners_history` (
  `banners_history_id` int(11) NOT NULL auto_increment,
  `banners_id` int(11) NOT NULL default '0',
  `banners_shown` int(5) NOT NULL default '0',
  `banners_clicked` int(5) NOT NULL default '0',
  `banners_history_date` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`banners_history_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;

--
-- Dumping data for table `banners_history`
--

INSERT INTO `banners_history` VALUES (1, 1, 146, 0, '2006-08-29 20:24:09');
INSERT INTO `banners_history` VALUES (2, 1, 18, 0, '2006-09-06 11:51:41');
INSERT INTO `banners_history` VALUES (3, 1, 12, 0, '2006-09-12 00:47:56');
INSERT INTO `banners_history` VALUES (4, 1, 1, 0, '2006-09-15 23:52:14');
INSERT INTO `banners_history` VALUES (5, 1, 5, 0, '2006-09-16 00:00:55');
INSERT INTO `banners_history` VALUES (6, 1, 13, 0, '2006-09-28 16:32:29');
INSERT INTO `banners_history` VALUES (7, 1, 18, 0, '2006-10-01 11:30:47');
[/code]

Regards
Huggie
Link to comment
Share on other sites

No trouble...

1. Open phpMyAdmin
2. Click on your database name on the left hand side (above all the table names).
3. On the right hand side, click 'Export'
4. Select the tables to export in the list by using 'Ctrl' + clicking the ones you want
5. Put a dot in the box called SQL under the table list
6. Tick 'Structure', 'Add AUTO_INCREMENT value', 'Enclose table and field names with backquotes' and 'Data'.
7. Select 'INSERTS' in the drop down box.
8. Click 'Go'

Then paste the output in the forum here.  Don't forget to delete any sensitive data from it, if there is any.

Regards
Huggie
Link to comment
Share on other sites

problem is $Searchman won't work unless you have globals turned on which are off by default. you first have to assign the get value or use it right in the query

[code]<?php
$sqlCOMPARE = "SELECT MANNAME, prodtype, proddesc, prodnar, prodequiv FROM man, produse, prodname
      where proddesc like '%".$_GET['Searchman']."%'
      and prodid = useid
      and manno = MANID
      order by MANNAME";?>
[/code]

or

[code]<?php
$Searchman = $_GET['Searchman'];
$sqlCOMPARE = "SELECT MANNAME, prodtype, proddesc, prodnar, prodequiv FROM man, produse, prodname
      where proddesc like '%$Searchman%'
      and prodid = useid
      and manno = MANID
      order by MANNAME";
?>[/code]

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