make sql data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jmyeom
Forum Newbie
Posts: 8
Joined: Mon Jun 08, 2009 11:30 am

make sql data

Post 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 :(
User avatar
Raph
Forum Commoner
Posts: 43
Joined: Wed May 27, 2009 6:33 pm

Re: make sql data

Post 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?
Last edited by Benjamin on Mon Jun 08, 2009 1:10 pm, edited 1 time in total.
Reason: Changed code type from text to php.
jmyeom
Forum Newbie
Posts: 8
Joined: Mon Jun 08, 2009 11:30 am

Re: make sql data

Post 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...?
User avatar
Raph
Forum Commoner
Posts: 43
Joined: Wed May 27, 2009 6:33 pm

Re: make sql data

Post 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?
jmyeom
Forum Newbie
Posts: 8
Joined: Mon Jun 08, 2009 11:30 am

Re: make sql data

Post by jmyeom »

yes!!!, just like that, thanks!, you>=god :)
Post Reply