Wednesday, June 11, 2008

the form below has the following fields: username- password and search area. The user will type their username/password and key in search criteria to search my vdatabase. Then the PHP script below will process it.

I would like the search bit to be on the main page on my website (just like Yahoo or Google:-) but unlike Yahoo/Google- when the user presses search- they will be asked to provide their login info i.e. user and pass. If all if well- they will get the results from the database.

How can i modify the code below to achieve this? thanks a lot.
<form method="post" action="search.php">
User: <input type="text" name="username">
Password:<input type="password" name="password">
Search for: <input type="text" name="search">
<input type="submit" name="submit" value ="Search">
</form>
<?php

$user = $_POST[ username ];
$pass = $_POST[ password ];


If ($_POST[submit] == "Search") {

mysql_connect("mysql"- $user- $pass)
Or die(mysql_error());
echo "<p>Thanks for using PowerSearch. Your search results for <b>$_POST[search]</b> are: </p>";
mysql_select_db("Country");
$query = "select * from Articles where Author like %$_POST[search]% ";
$result = mysql_query($query);

echo "<table width= 600 border= 1 cellpadding= 5 ><tr>";
echo "<th align= left width= 200 >Title</th><th align= left width= 100 >Author</th><th align= left width= 200 >Content</th>
<th align= left width= 100 >Date</th></tr>";

while($row = mysql_fetch_array($result)) {
echo "<tr><td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "<td>".$row[3]."</td></tr>";
}
echo "</table>";


}

?>
Mike- thanks for that suggestion: yes i tried exactly that: first a form to ask for search criteria- then in one page i created a form for passd and username and php script- all in one page- but used action="php-self" thing instead of the search.php as shown above for the form to submit to itself. i got it wrong in how to store the search string- so it didnt work: ) but what you suggested is exactly what i wish to do.

topnotch- that would require a "real" techie to do that it seems :-)))
also the If ($_POST[submit] now got me confused :-)
C B that is an interesting point- but as a newbie- I am not sure about how that happens. How could users access the database otherwise? thanks man.

can just use flash+php&Mysql- if so how?

<?php
$username= $_POST[ username ] ;
$offence = $_POST[ offence ] ;
$punishment=$_POST[ punishment ];
$offence_text=$_POST[ offence_text ];

$dbhost= localhost ;
$dbuser = root ;
$dbpass = a ;

mysql_connect($dbhost-$dbuser-$dbpass) or die( Sorry T- error! );
echo "Connected to MySQL <br />";

mysql_select_db("offender_list") or die(mysql_error());


mysql_query("INSERT INTO watch_list VALUES( $username - $offence - $punishment- $offence_text -)");
Print "Your information has been successfully aded to the database.";


?>


I have mysql adminstrator...and i created the table prior to executing that code- no luck. I tried creating the table in the above code by including

CREATE TABLE "watch_list" (


`username` VARCHAR (30) NOT NULL-
`offence` VARCHAR(45) NOT NULL-
`punishment` VARCHAR(45) NOT NULL-
`offence_text` VARCHAR(500) NOT NULL-
PRIMARY KEY (`username`)
)


But that causes errors for the php.

Even if I have the table- it is not being populated.
Ok Ive altered the syntax- and it seems that I am a step further- I can now getting an SQL error:

$query=mysql_query("INSERT INTO watch_list( username - offence - punishment - offence_text )VALUES( $username - $offence - $punishment - $offence_text )");

i would like to have a database for a preferred vendor list...what is a good database program where i can build a database that can add a vendor- modify a vendor- delete a vendor and search for a vendor and then have a link on the database that links to a survey for a vendor rating?? i want to be able to store all of this information and have reports when my employees are entering the information...so which do you recommend for something like this? MySQL? Microsoft Access? or anything else??

also- what is involved in building a database? what is the criteria? for the information that i mentioned above should i build one Master table or do I need more? any information on this would be great! 10 points for great answer and a lot of info

I m trying to pull data from a database were one of the columns look like this:

html_title=
meta_description=Having trouble sleeping?
meta_keywords=Sleep- Relaxation- relaxed sleep
robots=index- follow
googlebot=
copyright=

that is what the whole cell per row looks like. Of course- with changes to the values after the "=". How do I- in maybe 1 mysql statement and not using php- break the cell into several columns?
Ok- more details. What i want is to pull data from a joomla database. one of the columns is called metadata and it has a text field with key/values separated by a new line. I know I know- majorly retardation! but what i want is to parse these colums and to create a normalized table. so i want to turn the text
"
title=Chocolate is great
keywords=chocolate- dark- milk
description=chocolate is great dark- milk or almods
"

into separate columns; title- keywords and description.

I can pull the data and have php break it up by newline and then break up the key/values by using the "=" as the delimiter- but can mysql do this for me?

Hi i am creating a website at moopgames.com and i want to have a rounded box around each of the game catagories. Now i know how to do rounded corners on normal text using 4 corner images but for some reason no matter what i do it wont work on my site because all of the "boxes" are generated from a mysql database using php. the boxes only show up around the group header.
Thanks Angel but that is the method i was using and it doesn t seem to work when php is generating the content

No comments: