Ibnatu Posted June 17, 2008 Share Posted June 17, 2008 Hello! i have a user database, in it are things set up like: username password email age number etc.... how can i make an input form, where you can put in a username, and it will show you a feild from this database i.e. 'number' so you can have a form, with submit button, if you put a username in, it will show you the number that the user inputted. and if theres no user with the username you put, it gives an error. i know how to do most of this, except getting the data with respect to the username you input! thats the hard part.. so far i have: if(isset($_POST['submit'])) { $username = mysql_real_escape_string($_POST['username']); $sql = mysql_query("SELECT username FROM user WHERE username = '$username'"); if(mysql_num_rows($sql) == 0) { echo("$username Is Not a Valid Username!"); } else { echo $username."'s Number is" . /*AAAAHHHH*/; } } Link to comment https://forums.phpfreaks.com/topic/110610-getting-mysql-data/ Share on other sites More sharing options...
MatthewJ Posted June 17, 2008 Share Posted June 17, 2008 <?php if(isset($_POST['submit'])) { $username = mysql_real_escape_string($_POST['username']); $sql = mysql_query("SELECT username, number FROM user WHERE username = '$username'"); $row = mysql_fetch_assoc($sql); if(mysql_num_rows($sql) == 0) { echo("$username Is Not a Valid Username!"); } else { echo $row['username'] . "'s Number is" . $row['number']; } } ?> That should work Link to comment https://forums.phpfreaks.com/topic/110610-getting-mysql-data/#findComment-567469 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.