Jump to content

MySQL insert problem


XeroXer

Recommended Posts

Hi!

I have a problem inserting information into my database.
I am making a login site and the problem I am having is regarding the registration process.
My database looks like this:
[code]CREATE TABLE `v2_users` (
`id` int(5) NOT NULL auto_increment,
`name` varchar(65) NOT NULL default '',
`pass` varchar(65) NOT NULL default '',
`jdate` varchar(65) NOT NULL default '',
`banned` varchar(5) NOT NULL default '0',
PRIMARY KEY  (`id`),
KEY `name` (`name`,`pass`,`jdate`,`banned`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;[/code]
This might look strange and thats because I'm not used to using my database that much.

The code I use for inserting information is this:
[code]include("config/database.php");
$password = md5($password);
$con = mysql_connect("$mysqlhost","$mysqlusr","$mysqlpass");
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db($db_name, $con);
mysql_query("INSERT INTO v2_users (name, pass, jdate, banned) VALUES ($username, $password, $date, '0')");
mysql_close($con);
echo "Registration completed. You can now log in...";[/code]

I have a feeling I have done something wrong but I get no error.
So please help me...
Link to comment
https://forums.phpfreaks.com/topic/30624-mysql-insert-problem/
Share on other sites


[code=php:0]

include("config/database.php");
$password = md5($password);
$con = mysql_connect("$mysqlhost","$mysqlusr","$mysqlpass");
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db($db_name, $con);
$results = mysql_query("SELECT * FROM v2_users WHERE name=".$username);
if (mysql_num_rows($results) < 0) {
mysql_query("INSERT INTO v2_users (name, pass, jdate, banned) VALUES ('$username', '$password', '$date', '0')");
echo "name already exists";
} else {
echo "Registration completed. You can now log in...";
}
mysql_close($con);
[/code]

something like that made, think it looks right
Link to comment
https://forums.phpfreaks.com/topic/30624-mysql-insert-problem/#findComment-141055
Share on other sites

Not quite, try this...

[code]<?php
include("config/database.php");
$password = md5($password);
$con = mysql_connect("$mysqlhost","$mysqlusr","$mysqlpass") or die('Could not connect: ' . mysql_error());

mysql_select_db($db_name, $con);
$results = mysql_query("SELECT * FROM v2_users WHERE name = '$username'");
if (mysql_num_rows($results) > 0) {
  echo "name already exists";
}
else {
  mysql_query("INSERT INTO v2_users (name, pass, jdate, banned) VALUES ('$username', '$password', '$date', '0')");
  echo "Registration completed. You can now log in...";
}
mysql_close($con);
?>[/code]

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/30624-mysql-insert-problem/#findComment-141064
Share on other sites

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.