starscream.pt Posted December 22, 2007 Share Posted December 22, 2007 It's driving me insane! I started learning this stuff 3 days ago, i've learned how to create databases and tables in mysql but then i noticed i could not do a simple submit information to the database with a submit form, so i tried something even EASYER, that is a simple "connected to mysql" message, here is what i ALWAYS get in the browser: ""; ?>" here is the code i'm using: <?php mysql_connect("localhost", "root") or die(mysql_error()); echo "Connected to MySQL<br />"; ?> i even tried taking off the "" because they make things go red on adobe dreamweaver, so i also tried this: <?php mysql_connect(localhost, root) or die(mysql_error()); echo "Connected to MySQL<br />"; ?> One thing i notice is that the <?php always show up in red. Mysql is working fine it seems, as i can execute the commands in the console and insert data into tables, but never from a PHP website ITS DRIVING ME NUTS!!!!! i have tried out dozens of examples NONE works!! can you guys help me out? Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/ Share on other sites More sharing options...
freebsdntu Posted December 22, 2007 Share Posted December 22, 2007 You have syntax error in your echo statement,first of all. I suggest you do a google search on the tutorial. Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421208 Share on other sites More sharing options...
kenrbnsn Posted December 22, 2007 Share Posted December 22, 2007 How are you invoking the script? PHP scripts must be invoked via a webserver. You're output indicates that you are not invoking it via a webserver. BTW, the simplest PHP script is <?php echo "Hello World"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421210 Share on other sites More sharing options...
starscream.pt Posted December 22, 2007 Author Share Posted December 22, 2007 i tried the hello world and it displays blank!! it is seriously driving me nuts, no sorts of white text, just plain blank! Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421212 Share on other sites More sharing options...
rab Posted December 22, 2007 Share Posted December 22, 2007 check the manual, mysql_connect() takes 3 arguments. Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421218 Share on other sites More sharing options...
kenrbnsn Posted December 22, 2007 Share Posted December 22, 2007 I ask again --- how are you invoking your script? If you're not using a webserver, it won't work. Ken Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421221 Share on other sites More sharing options...
john010117 Posted December 22, 2007 Share Posted December 22, 2007 View source. Does it output the full PHP code? Then you need a webserver. WAMP is good for Windows. Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421243 Share on other sites More sharing options...
ayok Posted December 22, 2007 Share Posted December 22, 2007 i tried the hello world and it displays blank!! it is seriously driving me nuts, no sorts of white text, just plain blank! First, take something that makes you relax. A cup of tea or a joint. I had a same experince. Then, you need to know what is required to see your test.php on your browser. You can download WAMP to set up your computer ready for php. I use Apache2Triad. If you work on webserver, see if it's support php. If you really have started 3 days ago, then you need to prepare some basic stuff. Good luck ayok Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421250 Share on other sites More sharing options...
starscream.pt Posted December 22, 2007 Author Share Posted December 22, 2007 First of all i read what the 3rd poster said twice, than i remembered i have uninstalled uniform server or dont have wamp. second i went outside to relax, now i'll install uniform sever again to text this thing and will let you guys know how it went, thank you for everything so far. Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421288 Share on other sites More sharing options...
nitation Posted December 22, 2007 Share Posted December 22, 2007 First of all what happens to the password of your database connection? You should be having sumthing like? <?php mysql_connect("localhost", "root", "password") or die(mysql_error()); echo "Connected to MySQL"; ?> Kindly note the "password" i added to you query. Try it and lets see. Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421298 Share on other sites More sharing options...
revraz Posted December 22, 2007 Share Posted December 22, 2007 That won't do any good if he can't even parse PHP. Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421304 Share on other sites More sharing options...
Warptweet Posted December 23, 2007 Share Posted December 23, 2007 In dreamweaver, I'm positive it saves the file as .htm or .html. Try renaming the file as .php and the PHP should work. Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421407 Share on other sites More sharing options...
starscream.pt Posted December 23, 2007 Author Share Posted December 23, 2007 i have the uniform server running, still, same problem happens, am i missing anything? @ the password issue, i do not have a password, but have tried with password and different mysql account, nothing works What i'm doing is, running uniform server, writting a php file in notepad (e.g. test.php) with the hello world code and problem is the same, i cant make anything happen, browser is blank or has the ?> Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421422 Share on other sites More sharing options...
Daukan Posted December 23, 2007 Share Posted December 23, 2007 Are you saving the file to your www root? I think in apache the default directory is htdocs Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421424 Share on other sites More sharing options...
starscream.pt Posted December 23, 2007 Author Share Posted December 23, 2007 i stoped uniform server and started wamp, seems nicer, started the apache service, server is online php file is in www directory, still not working Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421432 Share on other sites More sharing options...
Daukan Posted December 23, 2007 Share Posted December 23, 2007 Can you open normal html pages? Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421439 Share on other sites More sharing options...
starscream.pt Posted December 23, 2007 Author Share Posted December 23, 2007 Can you open normal html pages? yes, that is why it has to be some configuration on my PC otherwise it would not work with many known sites. Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421443 Share on other sites More sharing options...
Daukan Posted December 23, 2007 Share Posted December 23, 2007 hmm could do a test. Make a directory in the www folder called test. Make a file called test.php, which contains the hello world code <?php echo 'Hello world'; ?> Place test.php in the test directory Open a command window. start/run/ type in cmd, click ok copy this text cd \Apache2\htdocs\test C:\Apache2\modules\php\php.exe -c C:\Apache2\modules\php\php.ini -f test.php right click on command window then click paste, press enter key (may parse without hitting enter) If you are using the default install of wamp on drive C this should print Hello World if php is installed. You may need to find php.exe and adjust the file path so command can find it If your www isn't called htdocs you need to change that If your install isn't on drive C change the drive letters to the correct drive Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421447 Share on other sites More sharing options...
juapo2 Posted December 23, 2007 Share Posted December 23, 2007 First, are you sure you have PHP enbled? You should first check that, then check your code and database settings: your code for connecting to database, should be something like this: <?php $server = "localhost" //most of all servers $user = "youruser" //there goes your database username $pass = "yourpass" // here goes your database password mysql_connect("$server", "$user", "$pass") or die(mysql_error()); echo "Connected to MySQL<br />"; ?> I think that should work. Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421603 Share on other sites More sharing options...
ayok Posted December 23, 2007 Share Posted December 23, 2007 i stoped uniform server and started wamp, seems nicer, started the apache service, server is online php file is in www directory, still not working You have to save your php files on folder htdocs, and open it. Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421643 Share on other sites More sharing options...
dickiebow Posted December 23, 2007 Share Posted December 23, 2007 If you are using WAMP, which is wonderful IMHO, then in your browser type http://lolcalhost/ and you should see the wamp homepage. Then if you have put your file inside a folder within the c:\wamp\www directory, and named it index.php, once you click on that folder in the wamp homepage you will see the results of your coding. Is it as simple as that? Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421655 Share on other sites More sharing options...
PHP_PhREEEk Posted December 23, 2007 Share Posted December 23, 2007 If you are using WAMP, which is wonderful IMHO, then in your browser type http://lolcalhost/ and you should see the wamp homepage. Then if you have put your file inside a folder within the c:\wamp\www directory, and named it index.php, once you click on that folder in the wamp homepage you will see the results of your coding. Is it as simple as that? Typo: http://lolcalhost/ = http://localhost/ yes, that is why it has to be some configuration on my PC otherwise it would not work with many known sites. You're not being asked whether you can see 'known sites' whilst regularly browsing the Internet. That you're here posting proves that works fine. = ) You're being asked if html pages stored in your htdocs directory and called up with http://localhost work. Once you have localhost working, you can then test for PHP. PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421712 Share on other sites More sharing options...
starscream.pt Posted December 23, 2007 Author Share Posted December 23, 2007 omg finaly * opens bottle of champagne * nothing a classic restart and creating a folder inside www folder wont solve PHP is now running, i was able to say hello to the world and connect to mysql database *gee* that was tuff. Thanks to all of you great helpers that made me understand this better in a matter of hours. Cheers! Merry xmas! Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421718 Share on other sites More sharing options...
PHP_PhREEEk Posted December 23, 2007 Share Posted December 23, 2007 Grats! We'll see you at your first PARSE ERROR! = D PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/82825-solved-cant-make-the-simplest-php-work/#findComment-421721 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.