Jump to content

My PHP code can't be run


regdi

Recommended Posts

Hi!I'm a new member here..

I was working in order to complete my computer assignment..

First, I made a.htm :

<pre><form method=post action=d.php>
Nama	: <input type=text name=na size=25 maxlength=20>
Alamat	: <input type=text name=al size=40 maxlength=60>
No.Telp	: <input type=text name=no size=15 maxlength=15>
Gender	: <input type=radio name=ge value=L>Male
  <input type=radio name=ge value=P>Female
Message	: <textarea rows=5 cols=40 name=pe></textarea>
<input type=submit name=submit value=Daftar>
<input type=reset name=reset value=Batal>
</form></pre>

 

and : d.php

<?
$na=$_POST['na'];
$al=$_POST['al'];
$no=$_POST['no'];
$ge=$_POST['ge'];
$pe=$_POST['pe'];
$tgl=date("Y-m-d");
echo $tgl;

mysql_connect(connection details hidden for security purposes, but they definitely work); 
mysql_select_db("cb") or die("Database doesn't exist");

$sql="create table tamu(id int(3) auto_increment, nama varchar(20), alamat varchar(60), notelp varchar(15), gender set('L','P'), pesan text, tglcatat date, primary key (id))";
$hasil=mysql_query($sql);

$sql="insert into tamu (nama, alamat, notelp, gender, pesan, tglcatat) values('$na','$al','$no','$ge','$pe','$tgl')";
$hasil=mysql_query($sql);

$sql="select *from tamu";
$hasil=mysql_query($sql);

echo"<pre>";
while($data=mysql_fetch_array($hasil))
{
echo"ID			: $data[id]<br>";
echo"Nama		: $data[nama]<br>";
echo"Alamat		: $data[alamat]<br>";
echo"No.Telp	: $data[notelp]<br>";
echo"Gender		: $data[gender]<br>";
echo"Pesan		: $data[pesan]<br>";
echo"Tgl Catat	: $data[tglcatat]<br><br>";
}
?>

 

then, I open the a.htm, fill it, and push the submit button,but What I see is..

"; while($data=mysql_fetch_array($hasil)) { echo"ID : $data[id]
"; echo"Nama : $data[nama]
"; echo"Alamat : $data[alamat]
"; echo"No.Telp : $data[notelp]
"; echo"Gender : $data[gender]
"; echo"Pesan : $data[pesan]
"; echo"Tgl Catat : $data[tglcatat]

"; } ?>

 

What should I do??

Thank you :)

Link to comment
https://forums.phpfreaks.com/topic/254335-my-php-code-cant-be-run/
Share on other sites

If your seeing the PHP code instead of it being run, there are two likely causes for this:

 

1) Your using <? rather than <?php for your starting tag.  <? is known as a short tag and is not valid unless enabled (it is not enabled by default I believe).  You should always use <?php as it will always work.

 

2) Your server is not properly configured to parse PHP files.

 

 

Fix number one first and then try.  If you still have problems try re-installing your server.  If you still have problems you'll have to post more details about your setup (os, server software, how you installed it, etc).

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.