0

Hi, im currently designing a form on dreamweaver and it allows a client to enter their Name, Email and Comments. At the same time i want this data to store in my mysql database which i created.
The php code that i used is shown below, but the problem is that when i press on submit on my form it doesnt not go to my mysql database and instead downloads a file of my php codes.
Does anyone have a solution to this? Thank you

<?php
$u="root";
$db="cascadeglobal";

$Name=$_POST['Name'];
$Email=$_POST['Email'];
$Comments=$_POST['Comments'];
mysql_connect(localhost,$u);
@mysql_select_db($db)or die("failed to connect the database");

$insert="insert into Comments(Name,Email,Comments)values('$Name','$Email','$Comments')";
if(mysql_query($insert))
{
echo('records have been updated');
}
else
{
echo("records failed to be updated").mysql_error();
}
?>
2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by diafol
0

sounds like you don't have php installed. or that you're not storing your site in the right folder.

Edited by diafol: n/a

0

You are right my folder location was wrong. But now it captures my Name and my Email but doesnt capture my Comments/Suggestions. So when i write the code for displaying the records in mysql that row appears empty while the other 2 have data in it.

1

OK a couple of things:

clean your input as a ' could mess it up - so use mysql_real_escape_string():

$Name=mysql_real_escape_string($_POST['Name']);
$Email=mysql_real_escape_string($_POST['Email']);
$Comments=mysql_real_escape_string($_POST['Comments']);

also ensure that you backtick your fields, but I don't think this should affect you:

$insert="INSERT INTO `Comments` (`Name`,`Email`,`Comments`) VALUES ('$Name','$Email','$Comments')";

Ensure that you've named your columns correctly. In addition, ensure that the comments box has a name attribute of 'Comments'. If there are other instances of other form elements with name="Comments", this could cause a problem.

0

THANK YOUUUUUUUUUUUU SO MUCH..
The error was my spelling, instead of email i wrote mail..
But
THANK YOU SO MUCH

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.