Ēriks Rudzītis Posted February 7, 2006 Report Share Posted February 7, 2006 Sveiki! Man nestrādā standarta grāmatas skripts!Kāpēc man rāda undefined variable??? Man register_globals ir ON! HTML fails strādā ok... "SEARCH.HTML" <html> <head> <title>Book-O-Rama Catalog Search</title> </head> <body> <h1>Book-O-Rama Catalog Search</h1> <form action="results.php" method="post"> Choose Search Type:<br> <select name="searchtype"> <option value="author">Author <option value="title">Title <option value="isbn">ISBN </select> <br> Enter Search Term:<br> <input name="searchterm" type="text"> <br> <input type=submit value="Search"> </form> </body> </html> Toties php failam rāda to UNDEFINED VARIABLE "RESULTS.PHP" <html> <head> <title>Book-O-Rama Search Results</title> </head> <body> <h1>Book-O-Rama Search Results</h1> <? trim($searchterm); if ((!isset($searchtype)) || !(isset($searchterm))) { echo "You have not entered search details. Please go back and try again."; exit; } $searchtype = addslashes($searchtype); $searchterm = addslashes($searchterm); @ $db = mysql_pconnect("localhost", "bookorama", "bookorama"); if (!$db) { echo "Error: Could not connect to database. Please try again later."; exit; } mysql_select_db("books"); $query = "select * from books where ".$searchtype." Like '%".$searchterm."%'"; $result = mysql_query($query); $num_results = mysql_num_rows($result); echo "<p>Number of books found: ".$num_results."</p>"; for ($i=0; $i <$num_results; $i++) { $row = mysql_fetch_array($result); echo "<p><strong>".($i+1).". Title: "; echo htmlspecialchars( stripslashes($row["title"])); echo "</strong><br>Author: "; echo htmlspecialchars (stripslashes($row["author"])); echo "<br>ISBN: "; echo htmlspecialchars (stripslashes($row["isbn"])); echo "<br>Price: "; echo htmlspecialchars (stripslashes($row["price"])); echo "</p>"; } ?> </body> </html> LŪŪŪDZU PALĪDZIET!!! Jau iepriekš paldies! Link to comment Share on other sites More sharing options...
v3rb0 Posted February 7, 2006 Report Share Posted February 7, 2006 un kāpēc lai nebļautu? trim($searchterm); if ((!isset($searchtype)) || !(isset($searchterm))) vispirms it kā grib ar trim kko sadarīt un tad skatamies vaij vispar tāds $searchterm ir. Link to comment Share on other sites More sharing options...
Paulinjsh Posted February 7, 2006 Report Share Posted February 7, 2006 Tu nepaarbaudi vai taads searchterm ir nodefineets un uzreiz kko ar shamo dari! Link to comment Share on other sites More sharing options...
Ēriks Rudzītis Posted February 7, 2006 Author Report Share Posted February 7, 2006 Bet kā tad man viņu NODEFINĒT un kur man viņu nodefinēt???? Jo - grāmatā par to nekas nebija teikts... Link to comment Share on other sites More sharing options...
Ēriks Rudzītis Posted February 7, 2006 Author Report Share Posted February 7, 2006 Vai šajās rindiņās tie !isset ir obligāti?? if ((!isset($searchtype)) || !(isset($searchterm))) Link to comment Share on other sites More sharing options...
Ēriks Rudzītis Posted February 7, 2006 Author Report Share Posted February 7, 2006 Brīnumainā veida TO erroru vairs nerāda... Nu nevaru saconnectēties ar datubāzi... Bet tā problēma moš tāpēc, ka nepareizā vietā man tas php un html fails ir saglabāts?? Es visu testēju ar localhostu Kur man tie faili jāsaglabā? Link to comment Share on other sites More sharing options...
Ēriks Rudzītis Posted February 7, 2006 Author Report Share Posted February 7, 2006 Problēma atrisināta... Link to comment Share on other sites More sharing options...
v3rb0 Posted February 7, 2006 Report Share Posted February 7, 2006 a grāmata tā tur php pa solim? tad jau labāk sāc ar šo http://3a3-interactive.net/php_reference/ (jau kuro reizi te forumā pieminēts) Link to comment Share on other sites More sharing options...
Ēriks Rudzītis Posted February 7, 2006 Author Report Share Posted February 7, 2006 Grāmata - Sams - PHP and MySQL Web Development Link to comment Share on other sites More sharing options...
Blitz Posted February 7, 2006 Report Share Posted February 7, 2006 (edited) ja angliski tad labak ir PHP and MySQL for dummies, viss siki izstastits kas un kaa + vel izmanto globals off Edited February 7, 2006 by Blitz Link to comment Share on other sites More sharing options...
Ēriks Rudzītis Posted February 7, 2006 Author Report Share Posted February 7, 2006 Skaidrs... Bet šajā jau līdz 1/3 esmu ticis, tik 3x esmu uzkāries, kā arī man ir register_globals on Nekāda lielā atšķirība jau nav... Tik kad globals ir off, kods mazliet garāksss.... Link to comment Share on other sites More sharing options...
v3rb0 Posted February 7, 2006 Report Share Posted February 7, 2006 aha, garāks par veselu $_GET[''] un $_POST[''] garumu :) tādus globals on ar likumu vajadzeja iznīdēt, vismaz grāmatās for dummies! Link to comment Share on other sites More sharing options...
Ēriks Rudzītis Posted February 7, 2006 Author Report Share Posted February 7, 2006 to V3RB0 Kāpēc gan??? Gandrīz VISI serveri to akceptē... Kad beigs akceptēr, tad arī mācīšos ar globals off... Link to comment Share on other sites More sharing options...
Stopp Posted February 7, 2006 Report Share Posted February 7, 2006 nākamajā php versijā jau vairs register globals vispār nebūs. bet nu kas tur ko mācīties. vai nu nodefinē katru variabli (ieteicamākais variants), vai nu extract() Link to comment Share on other sites More sharing options...
Recommended Posts