randydg Posted March 18, 2010 Share Posted March 18, 2010 First off im not a very good scripter. Second i'm trying to get this to do a mysql search on a database. Any help? Thanks <form name="name" method="POST" action="<?=$PHP_SELF;?>"> Enter Name to lookup <input name="name" type="text" id="name" size="50" /> <input type="submit" name="submit" /> </form> <?php if(isset($_POST['submit'])){ if(is_numeric($_POST['name'])) { $theidyouspecify = $_POST['name'];// define this as the id you specify }else{ $error[] = 'Id must be numeric.'; } // no error, so run the query if(!$error){ $db = mysql_connect("host","user","pass") or die("Couldn't connect"); mysql_select_db("worksheets",$db) or die("Couldn't select database"); $sql = "SELECT FROM customers WHERE name='$theidyouspecify'"; if(!mysql_query($sql)){ $error[] = 'failed to lookup worksheets table<br />'; }else{ $error[] = 'lOOKUP completed<br />'; } } } // get results // $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for //echo "<p>You searched for: "" . $var . ""</p>"; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["1st_field"]; echo "$result"; ?> <div id="error"> <?php $error[]=''; foreach($error as $value){ echo $value; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/195703-phpmysql-search-problem/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 18, 2010 Share Posted March 18, 2010 Kind of depends on what error, problem, or symptom you saw in front of you when you tried it. We only see the information you provide in your post and since we don't have access to your server or your database, you are the only one here who can actually run your code in your environment and tell someone not standing right next to you what happened. Quote Link to comment https://forums.phpfreaks.com/topic/195703-phpmysql-search-problem/#findComment-1028159 Share on other sites More sharing options...
randydg Posted March 18, 2010 Author Share Posted March 18, 2010 Couldn't execute query. No results display also in the code it has if(is_numeric($_POST['name'])) { Is there anyway to change this to if blank or just skip the if and just use the post part? thanks P.s. This code is supose to search for customers by name in the database. Database = worksheets table get info from = customers inside customers is field called name. its supose to search in the name field for a name that is typed in the search field Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/195703-phpmysql-search-problem/#findComment-1028169 Share on other sites More sharing options...
randydg Posted March 18, 2010 Author Share Posted March 18, 2010 this new code doesnt give an error, but doesnt post anything either. not sure where im going wrong. with the form code in search.php and this code in lookup.php. <? if (isset($_POST['submitnew'])) { $name2 = trim(stripslashes($_POST['name'])); $theidyouspecify = $_POST['id'];// define this as the id you specify $db = mysql_connect("host","user","pass") or die("Couldn't connect"); mysql_select_db("worksheets",$db) or die("Couldn't select database"); //$sql = "SELECT FROM customers WHERE name='$theidyouspecify'"; //Get Customer Data from datebase from $customerid $query="SELECT * FROM `customers` WHERE name='$theidyouspecify'"; $result=mysql_query($query); $name=mysql_result($result,$i,"name"); echo "$name"; } } ?> oops, sorry didnt mean to double post.wont happen again. Quote Link to comment https://forums.phpfreaks.com/topic/195703-phpmysql-search-problem/#findComment-1028279 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.