Click to See Complete Forum and Search --> : SQL problem


deep
01-07-2004, 05:29 PM
Hello, I just started out learning sql and I need your help!

I created my little db and added it to my site with no errors :) It looks like this:

CREATE TABLE friend_user (
id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
edUser CHAR(15),
edName CHAR(20),
edLastname CHAR(30),
edCity CHAR(20)
);



Now I want to add a user and I use this code:

<?php

$db = mysql_pconnect("localhost", "hello", "hello");
mysql_select_db("mydb", $db) or die ("error!");

if ($id) {
print "your username is taken, try a new one.";
} else {

$sql = "INSERT INFO `friend_user` (`edUser`, `edPass`, `edName`, `edLastname`, `edCity`)
VALUES ('$edUser', '$edPass', '$edName', '$edLastname', '$edCity')";

print "<b>Welcome $username</b><br>";
print "You are now a registered member";
}

?>


I know this is a noobs code but i need to start somewhere :) My problem is that the user info is not added to the database and im wondering what im doing wrong...

Another thing bothering me is the $id... how is the webpage going to remember you and your $id... so that when you come back it will know who you are..??? (if i understood the $id right that is)

plz help! :)

pnaj
01-07-2004, 05:48 PM
Excellent start!

It's just a typo: 'INSERT INFO' should be 'INSERT INTO'

Generally, the way to 'maintain state' between web pages on the same server (this is your problem) is to use sessions.

If you haven't heard of them yet, have a look at the manual before anything else sessions (http://www.phpbuilder.com/manual/ref.session.php)

Also, typing 'php sessions tutorial' into google brings up a ton of stuff. See how you get on and come back later (if you need to).

pyro
01-07-2004, 05:49 PM
$sql = "INSERT INFO `friend_user` (`edUser`, `edPass`, `edName`, `edLastname`, `edCity`)
VALUES ('$edUser', '$edPass', '$edName', '$edLastname', '$edCity')";

A little typo... Should be "INSERT INTO..."

Also, you need to add mysql_query($sql) to your script, after that line.

As far as remember users, you will want to use cookies (http://us2.php.net/manual/en/function.setcookie.php).