Jump to content

php/mysql search problem


randydg

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.