Page 1 of 1

make sql data

Posted: Mon Jun 08, 2009 11:33 am
by jmyeom
i need a php script that will read data from a text box and put it into a database in mysql.... e.g:

textbox1 = username
textbox2 = generratedcode

... so it inputs the username and the generrated code

so when on a different page, when i input the generrated code, that i saved onto the database, it will show there username :)


p.s, i did have a look for a bloody code.. but it failed and totally messed up, so i binned it and cant find it :(

Re: make sql data

Posted: Mon Jun 08, 2009 12:54 pm
by Raph

Code: Select all

<?php
if(isset($_POST['submit'])) {
mysql_query("INSERT INTO table (username, generratedcode)
VALUES ('". trim(addslashes($_POST['textbox1'])) ."', '". cleanup_function_of_choise($_POST['textbox2']) ."')");
}
?>
That what you were looking for?

Re: make sql data

Posted: Mon Jun 08, 2009 1:13 pm
by jmyeom
yes thanks, just what i was looking for! <3
but what if i wnat it to check if the username has allready been submitted, and if it has to echo some text...?

Re: make sql data

Posted: Mon Jun 08, 2009 2:02 pm
by Raph
I think there are alot of beginners guides regarding this type of thing. Nevertheless, here's one way to do it:

Code: Select all

 
# if isset bla bla
$sql = mysql_query("SELECT * FROM table WHERE username = '$username' LIMIT 1");
 
 if(mysql_num_rows($sql) > 0) {
 # The username is taken.
 echo "bla bla username taken pick new one";
 }
 
Like that?

Re: make sql data

Posted: Mon Jun 08, 2009 3:45 pm
by jmyeom
yes!!!, just like that, thanks!, you>=god :)