PHP & MySQL Problem

JelvisChan

Registered
I just enabled PHP on my iMac 2008 ( Leopard ).

What I want to do is make a regular html form that, when submitted, goes into a database -- which I have used MySQL.

I made the html form, put I do not know how to link PHP and MySQL to process the form.

Please don't make your answer too technical because I am HIGHLY a beginner.


Also, I looked into just PHP form processing and this is what I came up with:

index.html-

Code:
<html>
Test form:

<form name="test" action="welcome.php" method="post">
<input type="text" name="fname" length="15" value="Type text here..." />
<input type="submit">
</form>
</html>

and the PHP processor:

welcome.php-

PHP:
<html>
<body>

Welcome <?php echo $_POST["fname"]; ?>.<br />

</body>
</html>

I tried this by putting them both in my Sites secton in my home directory and when I filled in the text box on index.html ( 1st one ), it just gave me the PHP file. What do I have to do to make it so that when you click submit on index.html, the php file gives you the summarization of what you filled out, which should be:

Welcome Jelvis.

Help me?
 

ScottW

Founder
Staff member
Or just:

PHP:
<?php echo $_POST[fname]; ?>

ALSO SHOULD WORK

PHP:
<?php print "$_POST[fname]"; ?>

to view all form data in an array:

PHP:
print_r($_POST);
 

JelvisChan

Registered
Jeff-

Your php code only gave me Welcome . whenever I typed in my name.

Scott-

Your php code never showed up when I entered my name -- just a blank screen on both codes.

Is there something wrong with my mac or....
 

ScottW

Founder
Staff member
To know if your system is parsing the PHP, just put

PHP:
<? phpinfo(); ?>

on a page called (for example) phpinfo.php and call it and see if it displays anything.
 

ScottW

Founder
Staff member
Load it in your browser... remember, these PHP pages must be served by a web server (usually apache), simply loading them in your browser with file:/// is not going to work, it will need to be an http call.
 

ScottW

Founder
Staff member
What do you mean nothing happens. Do you get a blank page or do you see your PHP code displayed in plain text? Where is your file at, how are you calling it in the browser, more info would be helpful.
 

JelvisChan

Registered
It is a blank page.

I am putting the phpinfo.php file in the Home Directory/Users/Sites folder.

When I call it, I go to:

file:///Users/Jeff/Sites/phpinfo.php


I really don't think I am doing anything wrong.
 

ScottW

Founder
Staff member
Yea, that's what I said earlier... you can't call it with file:///, PHP files are "parsed" by a web server and loading a page in your browser directly means your browser is just reading the file and it is clueless on what to do with it.

If you have web sharing turned on:

Try this:

http://localhost/~Jeff/phpinfo.php
 

ScottW

Founder
Staff member
If all you see is the PHP code you typed and no output...

Go to terminal and edit this file:

Code:
sudo nano -w /private/etc/apache2/httpd.conf

type in your password when it asks...

Control-w (for searching in Nano), then type 'php' and hit return

You will see this:

Code:
#LoadModule php5_module        libexec/apache2/libphp5.so

Uncomment that line so it just shows

Code:
LoadModule php5_module        libexec/apache2/libphp5.so

save the file (control-x, then Y for yes)

Now go in and start/stop your web sharing in System Preferences -> Sharing.

Load the phpinfo page again and you should be gold.
 

ScottW

Founder
Staff member
Failed to Connect

My Web Sharing is on.

Do I have to type something in on the localhost part?

In your web sharing, when you turn it on, it gives you the URL of your site. If localhost doesn't work, try:

127.0.0.1 in place of localhost, or use the link Apple gives you in web sharing.
 
Top