Jump to content

[SOLVED] can't make the simplest PHP work!!!


starscream.pt

Recommended Posts

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?

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ?>

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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! ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.