Jump to content


Photo

variable help


  • Please log in to reply
8 replies to this topic

#1 witham

witham
  • Members
  • PipPipPip
  • Advanced Member
  • 86 posts

Posted 18 October 2006 - 08:54 PM

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:

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

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

$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");  

}

and then:

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";

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

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 19 October 2006 - 10:56 AM

The code all looks ok to me, with the exception of the html...

Can you provide a sample dump of your database and the full code and I'll give it a try for you?

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 mrparanoid

mrparanoid
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 19 October 2006 - 11:15 AM

Hi,

'%$Searchman%'

could you try concatenating the whole thing?

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

Maybe this could solve it.

#4 witham

witham
  • Members
  • PipPipPip
  • Advanced Member
  • 86 posts

Posted 19 October 2006 - 05:49 PM

Concatenation didn't work I am afraid sorry for my igorance Huggiebar but how do I "dump" this sample?

thanks

#5 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 19 October 2006 - 06:58 PM

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:

-- 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');

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#6 witham

witham
  • Members
  • PipPipPip
  • Advanced Member
  • 86 posts

Posted 19 October 2006 - 07:22 PM

Huggie I am using phpadmin but I can't see how you dump, could you please go back a step or two and start from scratch to tell me how to get the information?
I am really sorry to put you to this trouble 

#7 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 19 October 2006 - 07:30 PM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#8 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 19 October 2006 - 07:37 PM

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

<?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";?>

or

<?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";
?>

Ray

#9 witham

witham
  • Members
  • PipPipPip
  • Advanced Member
  • 86 posts

Posted 19 October 2006 - 07:53 PM

Huggie thank you so much for your help, and Craygo getting the variable first worked and th script worked fine. I hope if I keep learning I will be able to help others as you have both helped me.

thanks again




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users