stevievelvet Posted November 18, 2008 Share Posted November 18, 2008 I have the following sample.html which calls sample.php, but I receive a blank page, what could be wrong ? (mysql 5.1.29) sample.html <html> <body> <form action=sample.php method=GET> Search for Country: <input type=text name=country size=25 maxlength=25> <p> <input type=submit> </form> </body> </html> sample.php <? mysql_connect (localhost, root, password); mysql_select_db (world); echo $country if ($country == "") {$country = '%';} $result = mysql_query ("SELECT * FROM Country WHERE Name LIKE '$country%'"); ql_close(); echo $result >? I've also referenced test.php n the above code, again a blank web page: <? echo 'hello!'; echo $country; ?> I SEE hello! on my webpage but not the value of $country ?? what could be wrong ? (1) Apache works & displays phpinfo (2) I'm using the world dsample database from mysql.com many thanks Sally Quote Link to comment https://forums.phpfreaks.com/topic/133200-falling-at-the-1st-hurdle-simple-php-script-calling-mysql/ Share on other sites More sharing options...
Maq Posted November 18, 2008 Share Posted November 18, 2008 -Most of your basic HTML syntax is wrong. You're missing quotes everywhere, your submit button doesn't have a name, you're declaring the GET method for your form but don't use it in sample.php. -Here's what you should do. Read up on basic HTML syntax. -Instead of using the GET method use the POST method. -In sample.php you need to use the POST method to get the input from country: $country = $_POST['country']; There's a lot more I could post here but try those first and come back with your updated files. Quote Link to comment https://forums.phpfreaks.com/topic/133200-falling-at-the-1st-hurdle-simple-php-script-calling-mysql/#findComment-692763 Share on other sites More sharing options...
revraz Posted November 18, 2008 Share Posted November 18, 2008 Along with the other issues, remove the % here WHERE Name LIKE '$country%'") Quote Link to comment https://forums.phpfreaks.com/topic/133200-falling-at-the-1st-hurdle-simple-php-script-calling-mysql/#findComment-692799 Share on other sites More sharing options...
stevievelvet Posted November 21, 2008 Author Share Posted November 21, 2008 thx revrax, constructively helpful! I took the code from a well known php-mysql tutorial site Sally Quote Link to comment https://forums.phpfreaks.com/topic/133200-falling-at-the-1st-hurdle-simple-php-script-calling-mysql/#findComment-695327 Share on other sites More sharing options...
PFMaBiSmAd Posted November 21, 2008 Share Posted November 21, 2008 The code is using register_globals, so it is at least 6 years out of date. Register_globals were turned off in php4.2 in the year 2002 and have been completely removed in php6. No new code, new books, new tutorials, or new hosting accounts should have been created after that point in time that relied on register globals being on. The code is also using short open tags <?. These can be disabled on any server and using them results in code that is non-portable. Always use a full <?php tag. The closing tag in sample.php is invalid and is probably causing a fatal parse error. You should be learning php, developing php code, and debugging php code on a local development system where error_reporting is set to E_ALL and display_errors is set to ON in your php.ini to get php to help you find errors like this one. Stop and start your web server to get any changes made to php.ini to take effect. Turning on these two settings would also point out the variables that are not defined due to the register_globals problem. Quote Link to comment https://forums.phpfreaks.com/topic/133200-falling-at-the-1st-hurdle-simple-php-script-calling-mysql/#findComment-695335 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.