Hi Experts,I have 2 pages with the name farmmgmt.php and assigndoc.php. In farmmgmt.php I insert certain fields like cowid and then get redirected to assigndoc.php for assigning doctors.

After assigning when I update the table it does not do so..
I want to update the table for the recently inserted cowid only..

Here's the code of farmmgmt.php

$insert = "INSERT INTO `farmlogin` (`uid`, `name`, `imgpath`, `gender`, `date`, `age`, `bb`, `htno`, `htunit`, `lno`, `lunit`, `pric`, `clr`, `insured`, `inscomp`, `polname`, `premiumtype`, `premiumamt`, `insstdate`, `matdate`, `remk`) VALUES ('$d', '$n', '$f', '$gen', '$dt', '$umar', '$bo', '$hgt', '$unitht', '$lgt', '$unitl', '$pr', '$colo', '$check', '$cname', '$poly', '$premtype', '$amt', '$insurancedat', '$mat', '$rk')";
$result = mysql_query($insert);

$latest = mysql_insert_id();//to get the latest inserted aoutoincremented cowid from the table




$i = $_GET['y'];

$sql = "UPDATE `farmlogin` SET `doc` = '$i' WHERE `cowid` = '$latest'";
echo "$sql";
$data = mysql_query($sql);

//$ve = intval($_GET['d']);
//$s = "UPDATE `farmlogin` SET `vend` = '$ve' WHERE `cowid` = '$latest' AND `doc` = '$i'";
//echo "$s";
//$d = mysql_query($s);


    if($result)
        {
            echo "<script>location.href='http://localhost/assigndoc.php'</script>";
        } 
        else
        {
            echo "hello";
        }

Next is of assigndoc.php

if(isset($_REQUEST['submit']))
        {

            $q = "SELECT `docid`, `doctor`, `hospital` FROM `docinfo` WHERE `city` = '$cc'";

            $r = mysql_query($q);




            echo "<b>Doctor</td>";
            echo "<td><b>Hospital Name</td>";
            echo "<td><b>Assign Doctors</b></td>";
            echo "<tr>";
            while($row = mysql_fetch_array($r))
            {
                echo "<td>".$row[doctor]."</b></td>";
                echo "<td>".$row[hospital]."</td>";
                echo "<td><a href=farmmgmt.php?y={$row['docid']}>Assign</a></td>";
                echo "</tr>";


            }

Please help out

Member Avatar

diafol

Please help out

Please place your code in code tags so it is easier to read.

Does the echoed $sql give you what you expected to see? Does the thing below look right when echoed to the screen?

UPDATE `farmlogin` SET `doc` = '$i' WHERE `cowid` = '$latest'

If so, try running the sql in the SQL window of phpmyadmin. It should give you an idea of where the query's going wrong.

yes, `doc`='' is showing blank... thats why its not running.. but how to resolve it..

Member Avatar

diafol

$i = $_GET['y'];
$sql = "UPDATE `farmlogin` SET `doc` = '$i' WHERE `cowid` = '$latest'";

Ok, maybe you're sending data to this page by a form as opposed to a querystring. It is best to send forms via POST method as opposed to the GET method. Maybe you need to change that...

$i = $_POST['y'];

I am not posting variable 'y'.It's the variable containing doctor's ID that i am assigning in assigndoc.php..and retreiving it in farmmgmt.php . Look at this line in assigndoc.php

echo "<td><a href=farmmgmt.php?y={$row['docid']}>Assign</a></td>";

I am not posting variable 'y'.It's the variable containing doctor's ID that i am assigning in assigndoc.php..and retreiving it in farmmgmt.php . Look at this line in assigndoc.php

echo "<td><a href=farmmgmt.php?y={$row['docid']}>Assign</a></td>";

Just want to add that.. I am getting this 'y' value appended with the URL. but shows blank in the query.Have no clue where am i making mistake.

In the row

echo "<td><a href=farmmgmt.php?y={$row['docid']}>Assign</a></td>";

you need to add the cowid, or you won;t know which cow to assign the doctor to.

echo "<td><a href=farmmgmt.php?y={$row['docid']}&amp;cowid={$latest}>Assign</a></td>";
Member Avatar

diafol

OK, I see you have to use $_GET. My oversight, sorry.
AFAICS the whole thing revolves around getting the 'y' value from the querystring (url) and placing it into the $i variable, which is then used in your query.

echo out the $i variable to the screen, e.g.

echo "The value of i is $i";

This should tell you where the passing of information is going wrong.

Is the value of y an integer? If not, it could be that you have some odd symbols in it?? THis shouldn't really make a difference, but non-escaped quotes can sometimes cause a problem. You can cirumvent this by cleaning/sanitizing your post and get variables, thus:

$i = mysql_real_escape_string($_GET['y']);

In fact, you should do this to all your passed variables anyway.

Tried it..the value of y is still showing blank.

It's because it is running before any doctor get assigned only.Unless an until it gets the value of y from assigndoc.php, it shouldn't run only.
Once I allocate a doctor, its only after that,it should get the value in $i and proceed to run the update query...

Hopefully.. I am thinking correct, but don't know how to get this done.

Would Appreciate your help ardav..

Member Avatar

diafol

$i = $_GET['y'];

This is independent of anything else that happens on your page. This is absolute. If your page url is something like: page.php?y=128, then $i will be 128. I can't see how this is not the case.

Just thinking, you are sending this info (y=128) to the page before you try to access the 'y' value ($_GET) right?