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();
}
?>
Member Avatar for diafol

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

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.

Member Avatar for diafol

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.

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

Member Avatar for diafol

Excellent, if it's solved, mark it so with the link below.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.