[MySQL] Help with inserting/deleting

Newbie Spellweaver
Joined
Feb 15, 2008
Messages
53
Reaction score
0
How would I insert data from a form in php, into some mysql tables?
How would I from php delete a table in mysql ?
By the way, someone got the simpliest registration + login system? I can go with md5 hash for password too, even if it's easy to decrypt :)


Thanks, Kadir.
 
DELETE pretty much the same as SELECT and UPDATE.

PHP:
SELECT * FROM `table` WHERE `id` =  "1" LIMIT 1
UPDATE `table` SET `field` = "value" WHERE `id` = "1" LIMIT 1
DELETE `field` FROM `table` WHERE `id` = "1" LIMIT 1

EDIT:

You should use PhpMyAdmin because it tells you the query you execute as your working. It's great for beginner, that's how I learned MySQL.
 
Last edited:
Sorry if it's wrong, it's on the fly.

Registration:
PHP:
<?php
	$uid = $_POST['uid']; // Username
	$pwd = $_POST['pwd']; // Password
	/* md5 pwd */
	$pwd = md5($pwd);

	if (!$uid or !$pwd)
	{
		echo 'Please fill out the entire form.';
	}
	else if (mysql_num_rows(mysql_query("SELECT * FROM `table` WHERE `uid` = '" . $uid . "'")) > 0)
	{
		echo 'That username is already taken.';
	}
	else
	{
		mysql_query("INSERT INTO `database`.`table` (`uid`, `pwd`) VALUES ('" . $uid . "', '" . $pwd . "')");
		echo 'Registration successful!';
	}
?>

I'll write the login later im too hungover.

Edit:
Okay, I'm back.

Login:
PHP:
<?php
	$uid = $_POST['uid']; // Username
	$pwd = $_POST['pwd']; // Password
	$pwd = md5($pwd); // Encrypt $pwd

	if (!$uid or !$pwd)
	{
		echo 'Please fill out the entire form.';
	}
	else
	{
		$result = mysql_query("SELECT * FROM `database`.`table` WHERE `uid` = '" . $uid . "'");
		while ($row == mysql_fetch_array($result))
		{
			$uid_real_pass = $row['pwd'];
		}
		// Test our's against the database
		if ($pwd == $uid_real_pass)
		{
			$hour = time() + 3600;
			setcookie('UID', $uid, $hour);
			setcookie('PWD', $pwd, $hour);
			header("Location: members.php");
		}
		else
		{
			echo 'The passwords did not match!';
		}
	}
?>
 
Last edited:
Back