anon Posted January 13, 2008 Share Posted January 13, 2008 Hi guys, as I said, this is more assistance than anything. Here's my code for adding a "User" to my Database <? // Make mysql connection below $mysql_conn = @mysql_connect("****", "*****", "******") or die("Could not connect to the Database, Please send us an e-mail in the contact section");\ @mysql_select_db("*******", $mysql_conn) or die("DataBase does not exist"); // prepare the form values for insert $name = mysql_real_escape_string($_POST['name']); $password = mysql_real_escape_string($_POST['password']); $email = mysql_real_escape_string($_POST['email']); $values = mysql_real_escape_string($_POST['value1' , 'value2' , 'value3' , 'value4' , 'value5' , 'value6' , 'value7' , 'value8' , 'value9' , 'value10']); // now i'm going to insert all the values into the database $sql = "INSERT INTO '****' ( 'name' , 'password' , 'email' , 'values' ) VALUES ('$name' , '$password' , '$email' , '$values')"; $res = mysql_query($sql) or die(mysql_error()); // now, i'm going to let people know when something has gone wrong, or if its gone right. if(!$res){ echo "Had a bit of a problem with the database, please report this in the help section so that we can totally freak out and fix it."; } else { echo "Successfully added you as a member, now you can go and edit your account. First though, you will need to complete subscription in your email inbox"; } // that concludes the script, thanks for using this service. HAHA!! World domination will be mine. Soon.... ?> I just want to know if this would work? I'm especially not sure of the variable $values, I want lots of values stored in one field, and then recall it later as a list. Quote Link to comment https://forums.phpfreaks.com/topic/85864-assistance-with-add-user-script/ Share on other sites More sharing options...
revraz Posted January 13, 2008 Share Posted January 13, 2008 Dont use single quotes around your Tablename or Fieldnames. Could be other errors too, I just noticed that. Quote Link to comment https://forums.phpfreaks.com/topic/85864-assistance-with-add-user-script/#findComment-438299 Share on other sites More sharing options...
anon Posted January 13, 2008 Author Share Posted January 13, 2008 So I should use " " And, the field with lots of values in it will work right? Quote Link to comment https://forums.phpfreaks.com/topic/85864-assistance-with-add-user-script/#findComment-438306 Share on other sites More sharing options...
revraz Posted January 13, 2008 Share Posted January 13, 2008 This "INSERT INTO '****' ( 'name' , 'password' , 'email' , 'values' ) Should be like "INSERT INTO tablename ( name , password , email , values ) You can have as many values as you want Quote Link to comment https://forums.phpfreaks.com/topic/85864-assistance-with-add-user-script/#findComment-438311 Share on other sites More sharing options...
anon Posted January 13, 2008 Author Share Posted January 13, 2008 Cool man, thanks a lot! Another question - How would you go about setting up some thing where every person who registers receives an email to confirm. Is there something in CPanel for this? Quote Link to comment https://forums.phpfreaks.com/topic/85864-assistance-with-add-user-script/#findComment-438318 Share on other sites More sharing options...
trq Posted January 13, 2008 Share Posted January 13, 2008 mail(). Quote Link to comment https://forums.phpfreaks.com/topic/85864-assistance-with-add-user-script/#findComment-438319 Share on other sites More sharing options...
revraz Posted January 13, 2008 Share Posted January 13, 2008 CPanel means a Control Panel, and it depends on what you mean. Are you referring to a Hosting Site CPanel or a script's CPanel? CMS Systems have their own types of CPanels, but if this is a script you made, then you need to code the registration and confirmations yourself. There are tutorials on how to do that floating around. Quote Link to comment https://forums.phpfreaks.com/topic/85864-assistance-with-add-user-script/#findComment-438320 Share on other sites More sharing options...
anon Posted January 13, 2008 Author Share Posted January 13, 2008 No, I mean CPanel, as in the web hosting thing. Its the one with Fantastico and all that. So I must just look for a tutorial on sending an email to people to confirm registration? Quote Link to comment https://forums.phpfreaks.com/topic/85864-assistance-with-add-user-script/#findComment-438322 Share on other sites More sharing options...
Fyorl Posted January 13, 2008 Share Posted January 13, 2008 This "INSERT INTO '****' ( 'name' , 'password' , 'email' , 'values' ) Should be like "INSERT INTO tablename ( name , password , email , values ) You can have as many values as you want That should probably be: "INSERT INTO `tablename` (`name`,`password`,`email`,`values`) Quote Link to comment https://forums.phpfreaks.com/topic/85864-assistance-with-add-user-script/#findComment-438335 Share on other sites More sharing options...
revraz Posted January 13, 2008 Share Posted January 13, 2008 Not if you don't use reserved names. This "INSERT INTO '****' ( 'name' , 'password' , 'email' , 'values' ) Should be like "INSERT INTO tablename ( name , password , email , values ) You can have as many values as you want That should probably be: "INSERT INTO `tablename` (`name`,`password`,`email`,`values`) Quote Link to comment https://forums.phpfreaks.com/topic/85864-assistance-with-add-user-script/#findComment-438339 Share on other sites More sharing options...
Fyorl Posted January 13, 2008 Share Posted January 13, 2008 It's better practice to encase them in backticks so you don't accidentally use a reserved name and trash your table/database. Quote Link to comment https://forums.phpfreaks.com/topic/85864-assistance-with-add-user-script/#findComment-438347 Share on other sites More sharing options...
revraz Posted January 13, 2008 Share Posted January 13, 2008 It's better practice to not use reserved names as well. And you won't trash your DB, it just won't work. It's better practice to encase them in backticks so you don't accidentally use a reserved name and trash your table/database. Quote Link to comment https://forums.phpfreaks.com/topic/85864-assistance-with-add-user-script/#findComment-438348 Share on other sites More sharing options...
Fyorl Posted January 13, 2008 Share Posted January 13, 2008 Hmm it's debatable really. Whether a clear database schema with informative field names takes precedence over the practice of not using reserved names. I would vote that if a reserved name is the best descriptor of the field's contents then you should use it. But that may be because I encase all my table/field names in backticks and so I can use reserved names if I want without having to worry. Other people who don't follow this practice are limited. Quote Link to comment https://forums.phpfreaks.com/topic/85864-assistance-with-add-user-script/#findComment-438352 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.