LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-01-2005, 07:53 AM   #1
Alexander.s
Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Slackware, Gentoo!
Posts: 115

Rep: Reputation: 15
how do i reformat my query_string in PHP?


My problem is that when i search for something in my database it launches the entire database instead of the text im searching for...

And reformatting the query_string should solve this right?

So what is the syntax for reformatting your query_string in PHP ?

ps. does anyone know where i can find a php-script that inserts data into the database?

thanks! / Alexander
 
Old 05-02-2005, 02:16 AM   #2
coolguy_iiit
Member
 
Registered: Aug 2004
Posts: 51

Rep: Reputation: 15
Use google Dude!!
 
Old 05-02-2005, 09:19 AM   #3
Alexander.s
Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Slackware, Gentoo!
Posts: 115

Original Poster
Rep: Reputation: 15
thanks dude! iv allready done that!
 
Old 05-02-2005, 09:26 AM   #4
Alexander.s
Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Slackware, Gentoo!
Posts: 115

Original Poster
Rep: Reputation: 15
This is my php.index file.

--------------------------------------------------
<?php
// Functionen kan vara vettig att sätta i en annan fil som man
// kallar på med include. Då behöver du inte ha dina databas
// uppgifter, password i alla filer, om du gör sql förfrågningar
// i flera filer.
function texter()
{
global $conn;
$conn = mysql_connect("localhost", "user", "iwonttellyou") or die(mysql_error());
mysql_select_db("databas",$conn) or die(mysql_error());
}
?>

<html><head></head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
Sök efter: <input type="text" size="25" name="searchfor" /><br />
<input type="submit" value="Sök!" />
</form>

<?php
// isset() kollar ifall du gjort en sökning, alltså om det finns ett
// värde på $_POST['searchfor']. trim() trimmar bort tomma
// tecken i början och slutet. Förhindrar att allt kommer fram
// ifall du gör en tom sökning.
if (isset($_POST['searchfor']) && trim($_POST['searchfor']) != '')
{
texter();

$searchfor = addslashes($_POST['searchfor']);
$sql="SELECT title, text FROM texts,details WHERE title LIKE '%".$searchfor."%';";
$result=mysql_query($sql, $conn);

if(mysql_affected_rows()>0)
{
echo "Följande poster hittades:<br />";


while($row = mysql_fetch_array($result))
{
$details = $row['title'];
$texts = $row['text'];
printf("%s, %s<br />", $title, $text);
}

mysql_free_result($result);
}
else
echo "Inga poster hittades.<br />";

mysql_close($conn);
}
?>
</body>
</html>

--------------------------------------------------
As you can see my database is set up like this:

create database texter;
create table details (textid int not null primary key auto_increment,title varchar(255),date date);
create table texts (textid int not null,text longtext);

Thanks! / Alexander
 
Old 05-02-2005, 10:22 AM   #5
enemorales
Member
 
Registered: Jul 2004
Location: Santiago, Chile
Distribution: Ubuntu
Posts: 410

Rep: Reputation: 30
To be honest, I'm not very sure about what you are asking for, but when you write

Code:
$sql="SELECT title, text FROM texts,details WHERE title LIKE '%".$searchfor."%';";
I'll put

Code:
$sql="SELECT title, text FROM texts,details WHERE texts.textid = details.textid AND title LIKE '%$searchfor%'";

Why do you need addslashes?

I'll recommend you also to follow the next link: http://www.freewebmasterhelp.com/tutorials/phpmysql It is the first one when you put "mysql php tutorial" in google

Good luck!

EDIT: Misstyping.
 
Old 05-02-2005, 11:12 AM   #6
Alexander.s
Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Slackware, Gentoo!
Posts: 115

Original Poster
Rep: Reputation: 15
That page was pretty awesome thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using mod_rewrite and query_string to remove arguments KimVette Linux - Software 3 11-10-2005 10:11 PM
Should I reformat? dareino Fedora 2 06-15-2004 07:28 PM
browser does not convert query_string/url spaces to '+', seeking workaround? Sm0k3 Programming 0 11-25-2003 05:44 PM
How do i reformat Ogledbyoldmen Linux - Software 1 10-04-2003 10:51 AM
I got into XP and I am about to reformat. Mr_Floppy4 Linux - General 14 10-17-2002 06:15 PM


All times are GMT -5. The time now is 05:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration