whats wrong with this php code?

For the discussion of Perl, Python, Ruby, and PHP and other interpreted languages.

whats wrong with this php code?

Post by chrisx16x2008 on Wed Feb 04, 2009 9:43 pm
([msg=17400]see whats wrong with this php code?[/msg])

Code: Select all
<?php
mysql_connect('host', 'user', 'pass');
mysql_select_db(database);
$user = $_POST['user'];
$pass = $_POST['pass'];
$passconf = $_POST['passconf'];
$type = $_POST['type'];
$location = $_POST['location'];
$description = $_POST['description'];
mysql_query("INSERT INTO users VALUES ('$user','$pass','$passconf','$type','$location','$description'");
?>


It goes through but then i check the database and it wasn't submitted... Also after i get this code to submit do i go about extracting the values from the database and printing them on a page?
Last edited by chrisx16x2008 on Wed Feb 04, 2009 11:03 pm, edited 1 time in total.
chrisx16x2008
New User
New User
 
Posts: 36
Joined: Tue Jan 13, 2009 9:53 pm
Blog: View Blog (0)


Re: whats wrong with this php code?

Post by Xive on Wed Feb 04, 2009 10:53 pm
([msg=17401]see Re: whats wrong with this php code?[/msg])

First of all you might wanna remove your Sql database credentials from your post.
about the code.. you need to double quote the db name:
Code: Select all
mysql_select_db('db_name');

and to extract data from the db, check this site out.
also i recommend adding some sanitization to your user's input to avoid xss.
Rule to live by: Never trust your user's input :mrgreen:
Xive
New User
New User
 
Posts: 8
Joined: Sat Jan 17, 2009 1:01 am
Blog: View Blog (0)


Re: whats wrong with this php code?

Post by chrisx16x2008 on Wed Feb 04, 2009 11:08 pm
([msg=17402]see Re: whats wrong with this php code?[/msg])

THANK YOU! finally got it working, it was the quotes and also i found another problem which was i forgot a ")". Also yea thanks for the tip on not posting my credentials and xss, usually careful about that that kind of stuff.
chrisx16x2008
New User
New User
 
Posts: 36
Joined: Tue Jan 13, 2009 9:53 pm
Blog: View Blog (0)



Return to Interpreted Languages

Who is online

Users browsing this forum: No registered users and 0 guests