Jump to content

Recommended Posts

Hey Guys,

 

Here's my problem which I think may be simple to solve hopefully, I'm new to searching mysql databases.

 

I have this setup http://www.invisionblue.com/designs/gdogs which goes along with http://www.invisionblue.com/designs/gdogs/db.gif

 

It has over 100,000 listings. Right now i have it displaying the results by the SZNummer column. However I'm wanting it to be where I type in the dog name (Hundename) it will display the results instead of by SZNummer. You'll notice the tables and information isn't in english, that's because the client is from another country. Below is my code, should be simple I believe. Thanks in advance for the help!

 

<form action="index.php" method="post">
<p>ID For Hundename: <input type="text" name="id" /></p>
<p><input type="submit" /></p>
</form>


<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("host","user","pass"); //(host, username, password)

//select which database you want to edit
mysql_select_db("garydogs"); 

//select the table
$id = (int)$_POST['id'];
$result = mysql_query("select * from Hundestamm WHERE ( `Hundestamm` . `SZNummer` = $id ) limit 1");

//grab all the content
while($r=mysql_fetch_array($result))
{	
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
  
   $title=$r["Hundename"];
   $zwing=$r["Zwingername"];
   $ges=$r["Geschlecht"];

   
   //display the row
   echo "<b>Hundename:</b><br>$title<br><br><b>Zwingername:</b><br>$zwing<br><br><b>Geschlecht:</b><br>$ges<br><br>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/59456-solved-simple-mysql-search-problem/
Share on other sites

Change the column to Hundename, escape it, make sure it's in quotes...

 

<?php

// ...

$result = mysql_query(sprintf('SELECT * FROM Hundestamm WHERE Hudename = "%s"', mysql_real_escape_string($_POST['id']));

// ... or a "starts with" variant

$result = mysql_query(sprintf('SELECT * FROM Hundestamm WHERE Hudename LIKE "%s%%"', mysql_real_escape_string($_POST['id']));

?>

Right, a missing closing parenthesis in both cases.

 

Corrected:

 

<?php

// ...

$result = mysql_query(sprintf('SELECT * FROM Hundestamm WHERE Hudename = "%s"', mysql_real_escape_string($_POST['id'])));

// ... or a "starts with" variant

$result = mysql_query(sprintf('SELECT * FROM Hundestamm WHERE Hudename LIKE "%s%%"', mysql_real_escape_string($_POST['id'])));

?>

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.