brem13 Posted April 15, 2010 Share Posted April 15, 2010 i have a code made to check a database if a username already exists and its not running the mysql code to get the field and when i echo the result, it just shows the code 'select *.....' $user = $values['username']; mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); mysql_select_db($database) or die ("Could not select database because ".mysql_error()); $result = "select * from $table where username = '$user'"; //if username is taken if ($values['username'] == $result) $errors['username'] = 'Username already taken'; and here is the html code that displays it <td width="250px"><font face="tahoma" size=2>Username</font></td> <td width="250px"><input type="text" name="username" width="200px" value="<?= htmlentities($values['username']) ?>" style="font: 14px Tahoma; height=22px;"/></td> <?= $errors['username'] ?></td> any suggestions? Link to comment https://forums.phpfreaks.com/topic/198651-php-not-running-mysql-query/ Share on other sites More sharing options...
TeddyKiller Posted April 15, 2010 Share Posted April 15, 2010 What you have is a string, it's not a mysql_query. $result = "select * from $table where username = '$user'"; Try this. $result = mysql_query("select * from $table where username = '$user'"); Link to comment https://forums.phpfreaks.com/topic/198651-php-not-running-mysql-query/#findComment-1042456 Share on other sites More sharing options...
TeddyKiller Posted April 15, 2010 Share Posted April 15, 2010 As a fact, the code is quite a mess. mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); mysql_select_db($database) or die ("Could not select database because ".mysql_error()); $user = $values['username']; $result = mysql_query("select * from $table where username = '$user'"); $row = mysql_fetch_array($result); //if username is taken if ($values['username'] == $row['username']) { $errors['username'] = 'Username already taken'; } Link to comment https://forums.phpfreaks.com/topic/198651-php-not-running-mysql-query/#findComment-1042460 Share on other sites More sharing options...
brem13 Posted April 15, 2010 Author Share Posted April 15, 2010 thank you bud! it didnt work after i added the 'mysql_query' part, but did work after i added the $row = mysql_fetch_array($result); and $row['username']... what does that do? just for future ref? Link to comment https://forums.phpfreaks.com/topic/198651-php-not-running-mysql-query/#findComment-1042464 Share on other sites More sharing options...
TeddyKiller Posted April 15, 2010 Share Posted April 15, 2010 $row = mysql_fetch_array($result); What this does, is gets the data from the query, into an array. $row['username']; As $row is now an array, you can now specifically get a certain collum from the database. In this instance "username" is the collum name. So $row['username'] is the users username. Link to comment https://forums.phpfreaks.com/topic/198651-php-not-running-mysql-query/#findComment-1042494 Share on other sites More sharing options...
brem13 Posted April 15, 2010 Author Share Posted April 15, 2010 ok cool, thank you Link to comment https://forums.phpfreaks.com/topic/198651-php-not-running-mysql-query/#findComment-1042496 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.