Connecting Tech Pros Worldwide Forums | Help | Site Map

New to php

Newbie
 
Join Date: Mar 2008
Posts: 10
#1: Mar 9 '08
Ok, this is probably going to sound pretty stupid...so please bear in mind that I'm completely new to php programming. Interested in the buzz about php I've recently downloaded the newest version 5.2.5 as well as MySQL server 5.0 and will be hosting web apps on Apache 2.2. I wrote a very simple program to get a feel for the syntax of php/MySQL programming...
[php]
Test.php - user-entered name and username

<html>
<form action="Insert.php5" method="post">
<table width=50% align="Center">
<tr>
<td width=50%>Enter your name:</td>
<td width=50%><input type="text" name="name" /></td>
</tr>
<tr>
<td>Enter your UserName:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" /></td>
</tr>
</table>
</form>
</html>

Insert.php5 - php page that appends users input into MySQL table:
<?php
$dbhost = 'localhost:3306';
$dbuser = 'user';
$dbpass = 'Password';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$Currentdb = mysql_select_db("test", $conn);
$FName = $_POST['name'];
$UName = $_POST['username'];
$sql="INSERT INTO Users (Name, UserName) VALUES ('".$FName."', '".$UName."')";

$result = mysql_query($sql, $conn) or die('Query failed: ' . mysql_error());
mysql_close($conn);
?>[/php]This works all fine and dandy when executed through a trial edition of NuSphere but when i simply open my webbrowser to the testpage and enter a name and username it does not execute the php, instead it displays the code as though it's a text file. Is there some sort of packaging I need to include within the php page or framework needed to execute this code for regular deployment? Thanks in advance.
Jason

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,948
#2: Mar 9 '08

re: New to php


have you tried changing it from php5 to .php
Not sure if this is the cause.
Newbie
 
Join Date: Mar 2008
Posts: 10
#3: Mar 9 '08

re: New to php


good suggestion but that didn't seem to do the trick.? is there maybe a copilation path or something that i may be missing in the php ini file? the host is seeing the pages, it's just not compiling the php script?
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,948
#4: Mar 9 '08

re: New to php


Silly question, but is apache running?
(just a suggestion: install something like xampp or phpeasy - they're all bundled with php and mysql(myadmin) )
Newbie
 
Join Date: Mar 2008
Posts: 10
#5: Mar 9 '08

re: New to php


apache is running...the script hits the web service when executed/compiled with Nusphere. any other suggestions??... i'd rather not uninstall/unconfigure my mysql and php installations but if i can't figure this out i may give phpeasy a try. thanks for the help.
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#6: Mar 10 '08

re: New to php


New to PHP or not, you still must enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

moderator
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,948
#7: Mar 10 '08

re: New to php


Unfortunately, no, i don't have anymore suggestions.
Try asking in an apache specific forum.
Reply