witham Posted October 18, 2006 Share Posted October 18, 2006 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 indexwhile ($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 tagecho "</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!!! Quote Link to comment https://forums.phpfreaks.com/topic/24374-variable-help/ Share on other sites More sharing options...
HuggieBear Posted October 19, 2006 Share Posted October 19, 2006 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?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24374-variable-help/#findComment-111150 Share on other sites More sharing options...
mrparanoid Posted October 19, 2006 Share Posted October 19, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/24374-variable-help/#findComment-111158 Share on other sites More sharing options...
witham Posted October 19, 2006 Author Share Posted October 19, 2006 Concatenation didn't work I am afraid sorry for my igorance Huggiebar but how do I "dump" this sample?thanks Quote Link to comment https://forums.phpfreaks.com/topic/24374-variable-help/#findComment-111432 Share on other sites More sharing options...
HuggieBear Posted October 19, 2006 Share Posted October 19, 2006 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]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24374-variable-help/#findComment-111465 Share on other sites More sharing options...
witham Posted October 19, 2006 Author Share Posted October 19, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/24374-variable-help/#findComment-111484 Share on other sites More sharing options...
HuggieBear Posted October 19, 2006 Share Posted October 19, 2006 No trouble...1. Open phpMyAdmin2. 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 want5. Put a dot in the box called SQL under the table list6. 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.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24374-variable-help/#findComment-111493 Share on other sites More sharing options...
craygo Posted October 19, 2006 Share Posted October 19, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/24374-variable-help/#findComment-111499 Share on other sites More sharing options...
witham Posted October 19, 2006 Author Share Posted October 19, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/24374-variable-help/#findComment-111509 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.