udaystrad Posted November 15, 2013 Share Posted November 15, 2013 Heres the code dont kno wats the problem <?php $host="localhost"; // Host name $username="root"; // Mysql username $password="india123"; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $myusername="maruti"; $mypassword="india123"; $dim="MID"; // column name $mid="SELECT $dim FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; echo $mid; ?> Link to comment https://forums.phpfreaks.com/topic/283911-not-able-to-get-an-output-pls-help/ Share on other sites More sharing options...
udaystrad Posted November 15, 2013 Author Share Posted November 15, 2013 phpMyAdmin 2.11.11.3 NO errors out put-- SELECT MID FROM members WHERE username='maruti' and password='india123' the ouput should be -- 009 (which i m nt able to get) Link to comment https://forums.phpfreaks.com/topic/283911-not-able-to-get-an-output-pls-help/#findComment-1458334 Share on other sites More sharing options...
mac_gyver Posted November 15, 2013 Share Posted November 15, 2013 the code you have posted is not running the sql query statement at all, nor is it fetching and using the data from the query statement, so just exactly how did you expect your code to produce the expected output? Link to comment https://forums.phpfreaks.com/topic/283911-not-able-to-get-an-output-pls-help/#findComment-1458350 Share on other sites More sharing options...
Barand Posted November 15, 2013 Share Posted November 15, 2013 mysql_query mysql_fetch_assoc mysql_fetch_row or, better, use the mysqli_ versions as mysql_ functions are deprecated Link to comment https://forums.phpfreaks.com/topic/283911-not-able-to-get-an-output-pls-help/#findComment-1458355 Share on other sites More sharing options...
udaystrad Posted November 16, 2013 Author Share Posted November 16, 2013 Hey sir but the same codes worked out for me after some changes..... or n may be i didnt understand what exactly u r tryin to say bcoz u r an expert and ur chances are more to be right....bt stil i have solved my issue... Here is the code below <?php $host="localhost"; // Host name $username="root"; // Mysql username $password="india123"; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $myusername="maruti"; $mypassword="india123"; // If result matched $myusername and $mypassword, table row must be 1 row $dim="MID"; $attendance="attendance"; // Table name $takevalue=mysql_query("SELECT $dim FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"); $array = mysql_fetch_array($takevalue); $mid=$array['MID']; echo $mid.'<br/>'; //; ?> Link to comment https://forums.phpfreaks.com/topic/283911-not-able-to-get-an-output-pls-help/#findComment-1458512 Share on other sites More sharing options...
udaystrad Posted November 16, 2013 Author Share Posted November 16, 2013 Sir pls guide me what exactly u wer tryin to say...or i have got it by myself???? n i m also stuck with one more databse problem heres the code its nt workin???? thers no output(not getin inserted in database) NO error showing. let me remind you i have tried sme other format also (which didnt work)...although dont have it .... pLs give me the line you think is right coz i have been stuck on this for a while.... mysql_query("INSERT INTO $attendance ('MemberId,TimeIn,TimeOut,Day,Month,Year') VALUES ('$mid','$timein','$timeout','$day','$month','$year') "); Link to comment https://forums.phpfreaks.com/topic/283911-not-able-to-get-an-output-pls-help/#findComment-1458514 Share on other sites More sharing options...
Barand Posted November 16, 2013 Share Posted November 16, 2013 put in some checks $sql = "SELECT $dim FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $takevalue=mysql_query($sql); // check for errors in query if (!$takevalue) { echo "$sql<br>" . mysql_error(); } else { // check if any records found if (mysql_num_rows($takevalue)==0) { echo "No matching records<br>"; } else { $array = mysql_fetch_array($takevalue); $mid=$array['MID']; echo $mid.'<br/>'; } } Link to comment https://forums.phpfreaks.com/topic/283911-not-able-to-get-an-output-pls-help/#findComment-1458532 Share on other sites More sharing options...
udaystrad Posted November 18, 2013 Author Share Posted November 18, 2013 k... thank you so much sir.... i did follow this method of checks for some of my codes. even the last one worked out for me. My codes are much more easy to understand. Link to comment https://forums.phpfreaks.com/topic/283911-not-able-to-get-an-output-pls-help/#findComment-1458747 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.