Closed Thread Icon

Topic awaiting preservation: Problem withMySQL option block Pages that link to <a href="https://ozoneasylum.com/backlink?for=12010" title="Pages that link to Topic awaiting preservation: Problem withMySQL option block" rel="nofollow" >Topic awaiting preservation: Problem withMySQL option block\

 
Author Thread
Gynot
Bipolar (III) Inmate

From: Brooklyn, NY
Insane since: Jan 2002

posted posted 01-22-2002 05:58

Now I know this is something stupid, but once again I just don't see it.
Trying to call several field from a table via a select form.
What tells me that's it's something silly is because when you go to the next page you get an entry, but it pulls the first entry not the One selected from first script.

Here's both scripts..... first is the select page, second is the result page.

<?

// create connection
$connection = mysql_connect("host","user","pass")
or die("Couldn't make connection.");

// select database
$db = mysql_select_db("mydb", $connection)
or die("Couldn't select database.");


// create SQL statement
$sql = "SELECT title FROM journal
ORDER BY title ASC";

// execute SQL query and get result
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query.");

// put data into drop-down list box
while ($row = mysql_fetch_array($sql_result)) {

$title = $row["title"];
$option_block .= "<OPTION value=\"$title\">$title</OPTION>";
}

?>

<FORM method="post" action="journal-search.php">

<P>Search Journal Entries by Title:<br>
<SELECT name="title-search">

<? echo "$option_block"; ?>

</SELECT>

<P><INPUT type="submit" value="submit"></p>


</FORM>

===============journal-select.php================================

<?php
if ((!$title)) {
header("select.php");
exit;
}

else {

//create connection
$connection = mysql_connect("host","user","pass") or die ("Couldn't connect to the database.");

//select database
$db = mysql_select_db("mydb",$connection) or die ("Couldn't select database.");

//prepare SQL statement
$sql = "SELECT day , title , rant FROM journal LIKE '$title' LIMIT 1 ";

//execute SQl queries and exit if failure at any query
$sql_result = mysql_query($sql,$connection) or die ("Sorry your search showed no results!");

echo "<ul>";
while ($row = mysql_fetch_array($sql_result)) {
$search_result_day = $row["day"];
$search_result_title = $row["title"];
$search_result_rant = $row["rant"];
echo "<table border=\"4\"><td align=\"left\">$search_result_day </td></tr><tr><td align=\"center\">$search_result_title </td></tr><tr><td align=\"center\">$search_result_rant</td></tr></table>\n";
}
}
?>


Here is the working example.

http://www.citystylecreations.com/forms/select.php

~Peace~
Gary
http://citystylecreations.com

Gynot
Bipolar (III) Inmate

From: Brooklyn, NY
Insane since: Jan 2002

posted posted 01-22-2002 06:01

PS: <SELECT name="title-search">
is "title", not title search, i was just trying some variation before I posted this, forgot to change it back. Please be patiant with me, I'm in the PHP/MySQL enviroment for a week now, and I'm gonna be asking alot of begginer questions!~LOL

~Peace~
Gary
http://citystylecreations.com

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 01-22-2002 08:42
code:
<?php
if ((!$title)) {
header("select.php");
exit;
}



what do you mean? redirection? try: header('Location: select.php');
and for the if ((!$title))
try this instead:
if ( !isset($title) ) { .... }

as for:
<SELECT name="title-search">

nop! the '-' is not a valid character. name it exactly as you'll be refeering to it using PHP: $title -> name it then: <select name='title'>


good luck,



[This message has been edited by lallous (edited 01-22-2002).]

Gynot
Bipolar (III) Inmate

From: Brooklyn, NY
Insane since: Jan 2002

posted posted 01-22-2002 17:44

I got it going, what I did was;
SELECT * FROM journal WHERE title LIKE '%$title%' LIMIT 1

Been waiting for payday (My_cash=$today(LOL)) so I could grab a book on this, been stumbling my way thru for the last week!~LOL

Maybe you can clear this up for me...
Is there a difference between the if ( !isset($title) ) or ((!$title))??
I've seen them both used, and they both work. Is one more practical?
Also seen people use @mysql_var instead of plain ol' mysql_whatver.
Or does it all once again come down to neither is right or wrong and it's just prefference?

Anyway, it's payday, I'll buy some books, and try not to be a putz!~LOL
Here's the working drop now...
http://www.citystylecreations.com/select/drop.php

~Peace~
Gary
http://citystylecreations.com

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 01-23-2002 12:24

if ( !isset($title) ) : tests if the variable is set and doesn't not generate a warning if it is not set.

((!$title)): test if variable is true or false, it can be false if empty, or bool(false) or int(0), but it does generate a warning if not defined and it will generate a warning.
just enable all error reporting and see yourself:

error_reporting(E_ALL);

as for using @mysql_whatever or @whatever_function_call , the '@' operator is used to tell PHP not to output errors or warnings, so it is not really advisable to use the '@' .

« BackwardsOnwards »

Show Forum Drop Down Menu