Jump to content

not able to get an output pls help


Go to solution Solved by Barand,

Recommended Posts

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;
 
 
 
?>
 
Edited by udaystrad
Link to comment
https://forums.phpfreaks.com/topic/283911-not-able-to-get-an-output-pls-help/
Share on other sites

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/>';
 

 
//;
?>

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') ");
 
Edited by udaystrad
  • Solution

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/>';    
    }
}
 
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.