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 [email protected] - 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
https://forums.phpfreaks.com/topic/103984-solved-mysql-insert-into-help/
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 [email protected] - 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!";

?>

<?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 [email protected] - 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?

 

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

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); 

    } 

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!";}

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.

Archived

This topic is now archived and is closed to further replies.

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