$values = 'VALUES ("'.$user_name.'", "'.$user_name.'", "'.$user_name.'", "'.$user_pass.'", "'.$user_email.'", "'.user_ip.'")';
$insert = mysql_query("INSERT INTO member(user_name, bidder_name, seller_name, user_pass, user_email, user_ip) " .$values);
if($insert)
{
///Yippie it's done, now ask that guy to login
header('location: login.php');
}
}
mysql_close($conn);
?>
In the member database, the columns are user_name, bidder_name, seller_name, user_pass, user_ip, user_email in that order. The registration form just asks for username, password and e-mail address. I am using
PHP version 5.3.10
MySQL version 5.0.95-community
What could be wrong? How come when someone submits the form and it says it’s successful, but there are no entries in the database? Could it be because I upgraded my version of MYSQL?
// Get values from form
$name=$_POST[‘name’];
$lastname=$_POST[‘lastname’];
$email=$_POST[‘email’];
// Insert data into mysql
$sql=“INSERT INTO $tbl_name(name, lastname, email)VALUES(‘$name’, ‘$lastname’, ‘$email’)”;
$result=mysql_query($sql);
// if successfully insert data into database, displays message “Successful”.
if($result){
echo “Successful”;
echo “<BR>”;
echo “<a href=‘form.php’>Back to main page</a>”;
}
else {
echo “ERROR”;
}
// close connection
mysql_close();
?>
Try this, this way you will know if the error is in sql statement or not.
There is something wrong with the insert statement. Can you give more details about the all the database fields you have and your insert statement. Then I would be glad to help you.
<?php
session_start();
///What i need to do here is to check the length of password and username
$LengthName = strlen($user_name);
$LengthPass = strlen($user_pass);
if(($LengthName > 10)&&($LengthPass > 10))
{
echo 'Maximum length is 10 for password and username';
exit();
}
///Second step is to find out whether user input the password correctly
$a = $_POST['user_pass'];
$b = $_POST['user_pass2'];
if($a != $b)
{
echo 'Your password does not match... Go back and retype your password';
exit();
}
///Check for email address
if(empty($_POST['user_email']))
{
echo 'Enter your email address';
exit();
}
///Check for image verification to prevent registerBot
$number = $_POST['image'];
if(md5($number) != $_SESSION['image_random_value'])
{
echo 'Verification does not match.. Go back and refresh your browser and then retype your verification';
exit();
}
else
{
///Open connection for registration process
include 'inc/config.php';
include 'inc/conn.php';
///Check whether username exist
$sql = "SELECT * FROM member WHERE user_name = '".$_POST['user_name']. "'";
$CheckUser = mysql_query($sql, $conn);
$NumRow = mysql_num_rows($CheckUser);
if($NumRow == 1)
{
echo 'Username '.$user_name. ' exist.. Please choose different username';
mysql_close($conn);
exit();
}
///Ok... no record found. I can process the registration
$values = 'VALUES ("'.$user_name.'", "'.$user_name.'", "'.$user_name.'", "'.$user_pass.'", "'.$user_email.'", "'.user_ip.'")';
$insert = mysql_query("INSERT INTO member(user_name, bidder_name, seller_name, user_pass, user_email, user_ip) " .$values);
if($insert)
{
///Yippie it's done, now ask that guy to login
header('location: login.php');
}
}
mysql_close($conn);
?>
I had to insert a ; after the echo part to make it work, and I got this:
INSERT INTO member(user_name, bidder_name, seller_name, user_pass, user_email, user_ip) VALUES (“”, “”, “”, “”, “”, “”)
Warning: Cannot modify header information - headers already sent by (output started at /home/domain/public_html/process.php:50) in /home/domain/public_html/process.php on line 55
You guys are awesome! mrana, your tutorial link helped me understand the codes better, and r937, you guided me in the right direction. Cups, you are a lifesaver! I shall read the info on that link. I’ve got the majority of the Sitepoint books but was too lazy to finish reading them (they are awesome, btw!) and figured I might as well use this script I found. It was driving me crazy for days! Thank you so much!!! There is no rep button here, is there?