Jump to content

[SOLVED] MYSQL INSERT INTO help!


fonecave

Recommended Posts

Why is this code not adding anything?

 

It connects ok but doesnt add a recordset

 

<?php
if (isset ($_POST['submit']))

{
$name=$_POST["name"];
$address=$_POST["address"];
$password=$_POST["password"];

$con = mysql_connect("localhost","my_db","password"); //these are correct login details table is called Members
if (!$con)
  {
  die('Contact support@fonecave.co.uk - Could not connect: ' . mysql_error());
  }
mysql_select_db("fonecave_00001", $con);
mysql_query("INSERT INTO members (name, email, password) VALUES ('$name', '$address', '$password')");

echo "Registration Complete!";

?>

Link to comment
Share on other sites

try this

<?php
if (isset ($_POST['submit']))

{
$con = mysql_connect("localhost","my_db","password"); //these are correct login details table is called Members
if (!$con)
  {
  die('Contact support@fonecave.co.uk - Could not connect: ' . mysql_error());
  }
mysql_select_db("fonecave_00001", $con);
mysql_query("INSERT INTO members (name, email, password) VALUES ('$_POST[name]', '$_POST[address]', '$_POST[password]')");

echo "Registration Complete!";

?>

Link to comment
Share on other sites

<?php
if (isset ($_POST['submit']))

{
$con = mysql_connect("localhost","my_db","password"); //these are correct login details table is called Members
if (!$con)
  {
  die('Contact support@fonecave.co.uk - Could not connect: ' . mysql_error());
  }
mysql_select_db("fonecave_00001", $con);
mysql_query("INSERT INTO members (name, email, password) VALUES ('$_POST[name]', '$_POST[address]', '$_POST[password]')");

echo "Registration Complete!";
}
?>

what about now?

 

Link to comment
Share on other sites

Sure the DB Table isnt Members? and not members like you wrote.

 

Sounds stupid but could be it.

 

Have you set the fields to the right settings? Like..your not trying to isntert text into an ENUM field etc.

 

screenshot of the DB? Form HTML?

 

Hope that helps.

Link to comment
Share on other sites

Table structure for: Members

 

  Field Name                              Type                    Null                  Key                      Default                      Extra

  name                                      varchar(20)            No                                            Unknown 

  email                                      varchar(30)            No                  PRI 

  password                                varchar(20)            No

 

Ihave tried members and Members neither work

Link to comment
Share on other sites

This is raw code from one of my projects:

 

$sql_email_check = mysql_query("SELECT email FROM users 

            WHERE email='$email' AND status='Alive'"); 

$sql_username_check = mysql_query("SELECT username FROM users 

            WHERE username='$reg_username'"); 



$email_check = mysql_num_rows($sql_email_check); 

$username_check = mysql_num_rows($sql_username_check); 



if(($email_check > 0) || ($username_check > 0)){ 

    echo ""; 

    if($email_check > 0){ 

        $message= "*This email address has already been used by another player!"; 

        unset($email); 

    } 

    if($username_check > 0){ 

        $message="*That desired username is already in use!"; 

        unset($reg_username); 

    } 

Link to comment
Share on other sites

ok i get this now:

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /www/110mb.com/f/o/n/e/c/a/v/e/fonecave/htdocs/login.php on line 406

 

$sql_email_check = mysql_query("SELECT email FROM members WHERE email='$address'"); 

$email_check = mysql_num_rows($sql_email_check);   //line406

if($email_check > 0) {

echo 'Registration Failed, Already Registered!';
}
else {

mysql_select_db("fonecave_00001", $con);
mysql_query("INSERT INTO members (name, email, password) VALUES ('$name', '$address', '$password')");
echo "Registration Complete!";}

Link to comment
Share on other sites

Replace:

$sql_email_check = mysql_query("SELECT email FROM members WHERE email='$address'"); 

 

With this:

$query = "SELECT email FROM members WHERE email='$address'";
$sql_email_check = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); 

 

If it's not obvious what needs to be fixed from the resulting error, post more information.

Link to comment
Share on other sites

Thanks for the tip, i must use that more.

 

Heres what i got...

 

Error: No database selected with query SELECT email FROM members WHERE email='user@fonecave.co.uk'

 

it was obvious what i had to do so now fixed!

 

Thank You all so much for your help yet again!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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