Jump to content

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

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.