Record not being added to my database

Lord Of The Land

New Member
Messages
26
Reaction score
0
Points
0
My database is realising that a record is being added but isn't show up. Im using php. Heres the code:

PHP:
<html>
<head>
</head>
<body>
<?php
include('V1/config.php');
$tbl_name=web_members;
$sql="INSERT INTO $tbl_name(email)VALUES('$email')";
$email=$_POST['email'];
$result=mysql_query($sql);
if($result){
echo "Successful";
echo "<br>";
echo "<a href='http://lordoftheland.x10hosting.com'>Back to the main page</a>";
}
else {
echo "ERROR (MySQL Error) - Please contact the administrator!";
}
mysql_close();
?>
</body>
</html>

Could some help me or correct the code! Thanks!
 

easykey

New Member
Messages
45
Reaction score
0
Points
0
$email was assigned after $sql. Corrected below:

PHP:
 <html>
<head>
</head>
<body>
<?php
include('V1/config.php');
$tbl_name=web_members;
$email=$_POST['email'];
$sql="INSERT INTO $tbl_name(email)VALUES('$email')";
$result=mysql_query($sql);
if($result){
echo "Successful";
echo "<br>";
echo "<a href='http://lordoftheland.x10hosting.com'>Back to the main page</a>";
}
else {
echo "ERROR (MySQL Error) - Please contact the administrator!";
}
mysql_close();
?>
</body>
</html>
 

easykey

New Member
Messages
45
Reaction score
0
Points
0
What is going into the database? Are you sure you get the POST data?

Do an echo $sql before the query to see what will be inserted - should help you troubleshoot...
 

mmyers

New Member
Messages
7
Reaction score
0
Points
0
Do you need the single quotes around the VALUES parameter ('$email')?
$sql
="INSERT INTO $tbl_name(email)VALUES('$email')";

Did you try the alternate INSERT ... SET command?
$sql="INSERT INTO $tbl_name SET email = $email";


 

sunils

New Member
Messages
2,266
Reaction score
0
Points
0
Sorry, i had no time to look into the your problem deeply, but here i am posting a lightly modified version of the code which you have posted already.

<html>
<head>
</head>
<body>
<?php
include('V1/config.php');
$tbl_name=web_members;
$email=$_POST['email'];
$sql="INSERT INTO ".$tbl_name."(email) VALUES('".$email."')";
$result=mysql_query($sql);
if(
$result){
echo
"Successful";
echo
"<br>";
echo
"<a href='http://lordoftheland.x10hosting.com'>Back to the main page</a>";
}
else {
echo
"ERROR (MySQL Error) - Please contact the administrator!";
}
mysql_close();
?>
</body>
</html>

if any further error has appeared, then post the error too.
 

Lord Of The Land

New Member
Messages
26
Reaction score
0
Points
0
Sorry, i had no time to look into the your problem deeply, but here i am posting a lightly modified version of the code which you have posted already.

<html>
<head>
</head>
<body>
<?php
include('V1/config.php');
$tbl_name=web_members;
$email=$_POST['email'];
$sql="INSERT INTO ".$tbl_name."(email) VALUES('".$email."')";
$result=mysql_query($sql);
if($result){
echo "Successful";
echo "<br>";
echo "<a href='http://lordoftheland.x10hosting.com'>Back to the main page</a>";
}
else {
echo "ERROR (MySQL Error) - Please contact the administrator!";
}
mysql_close();
?>
</body>
</html>

if any further error has appeared, then post the error too.

Thats the one that worked thanks to all that posted! :biggrin:
 
Top