kbllau Posted April 23, 2009 Share Posted April 23, 2009 Hi I need help with this code to make it works. I am new at PHP. I want to check if the file number exist at my database before i use it to open a new file. I use input form to fill in my query then send it to this code. here is the code: <?php // Make a MySQL Connection mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("main") or die(mysql_error()); $id = $_POST['fileno']; $sql = mysql_query("SELECT fileno FROM master"); //or die('Error: ' . mysql_error()); if ($id==$sql){print " The file number already in use try onther one"; } else{ print " you can use this file number"; } ?> Link to comment https://forums.phpfreaks.com/topic/155338-help-with-this-code/ Share on other sites More sharing options...
jackpf Posted April 23, 2009 Share Posted April 23, 2009 You need to use mysql_fetch_array() to actually retrieve the data from the database. Link to comment https://forums.phpfreaks.com/topic/155338-help-with-this-code/#findComment-817254 Share on other sites More sharing options...
Yesideez Posted April 23, 2009 Share Posted April 23, 2009 Or mysql_fetch_assoc() or mysql_fetch_object() Link to comment https://forums.phpfreaks.com/topic/155338-help-with-this-code/#findComment-817267 Share on other sites More sharing options...
jackpf Posted April 23, 2009 Share Posted April 23, 2009 However, you can emulate either of these with mysql_fetch_array(). But yes. Link to comment https://forums.phpfreaks.com/topic/155338-help-with-this-code/#findComment-817268 Share on other sites More sharing options...
kbllau Posted April 23, 2009 Author Share Posted April 23, 2009 Thanks for the help but i Still confused i updated the code <?php // Make a MySQL Connection mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("mandoma") or die(mysql_error()); $id = $_POST['fileno']; $query = "SELECT '$id' FROM master"; $result = mysql_query($query)or die(mysql_error()); $row = mysql_fetch_array($result) or die (mysql_error()); echo $row['fileno']; if ($id==$row){print " The file number not in use try onther one"; } else{ print" you can not use this file number"; } ?> Link to comment https://forums.phpfreaks.com/topic/155338-help-with-this-code/#findComment-817290 Share on other sites More sharing options...
revraz Posted April 23, 2009 Share Posted April 23, 2009 I think you misunderstand the SELECT Query, is your Field Name the FILENO stored in $id? I think you want this: query = "SELECT fileno FROM master"; Link to comment https://forums.phpfreaks.com/topic/155338-help-with-this-code/#findComment-817300 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.