Hi frnds,

I need to select some values in old table and send it into newtable. Here i placed my program. Anybody know say the corrections.

<?php

mysql_connect("localhost","root","");
mysql_select_db("menus") or die(mysql_error());


$idvalue=$_REQUEST['id'];
//$iv=$_REQUEST['z'];

 $result=mysql_query("select * from smenu where id='$idvalue'");

     while($row=mysql_fetch_array($result))
     {

     $projectid=$row['id'];
     $projectname=$row['main'];
     $projectcat= $row['itemm'];
     $scope=$row['descrip'];
     $location=$row['Category'];
     $rate=$row['Rate'];

     }
     echo " $projectid,$projectname,$projectcat,$scope,$location,$rate";


    $query="insert into orde values('$projectid','$projectname','$projectcat','$scope','$location','$rate' where id='$idvalue')";
       $dbase=mysql_query($query);
        echo "$dbase";     
     ?> 

</body>
</html>

what error/problem you are facing.

All items are displayed using echo statement. but not stored in table . not shown any error.

My doubts

1) you are echoing and inserting outside the while loop so this will show and insert only last record.
2) In your insert query. You can not write where id='idvalue'. following is the correct query. I have removed where portion after 'rate'

$query="insert into orde values('$projectid','$projectname','$projectcat','$scope','$location','$rate')";

echo statement not necessary here. just i know , items are displayed are not.I used ur query. But still didn't store values in table.

$query="insert into orde values('$projectid','$projectname','$projectcat','$scope','$location','$rate')";
echo $query;

error_reporting(E_ALL); 
ini_set("display_errors", 1);

copy the ouput of query from browser, run it in phpmyadmin and check whether your query works there or not.

Member Avatar for rajarajan2017

Hi sugikrish,

1. do you get any records inserted in your table or nothing get inserted in your table?

Echo your $idvalue may be the value is not present in the second table thats why not get inserted.

Hi thanks for your reply.......

Just I insert your coding in phpmy admin it produce the following error.

Error

SQL query:

$query = "insert into orde values('$projectid','$projectname','$projectcat','$scope','$location','$rate')";

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$query="insert into orde values('$projectid','$projectname','$projectcat','$scop' at line 1

And I add some codings with this then i show some error

    "select * from smenu where id='$idvalue'";

         while($row=mysql_fetch_array($result))
         {

         $projectid=$row['id'];
         $projectname=$row['main'];
         $projectcat= $row['itemm'];
         $scope=$row['descrip'];
         $location=$row['Category'];
         $rate=$row['Rate'];

        }

       $query="insert into orde values('$projectid','$projectname','$projectcat','$scope','$location','$rate')";
           $dbase=mysql_query($query);
            echo $dbase;
            error_reporting(E_ALL);
ini_set("display_errors", 1);    

error

Error

Error

SQL query: Documentation

"select * from smenu where id='$idvalue'";

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"select * from smenu where id='$idvalue'"' at line 1

First correct syntax in your phpmyadmin, then try to do it in php

Ya echo "$idvalue" display the value. just I want retrieve some values from existing table and posted into new table. I used where condition here for retrieve values. But no condition for storing values.already i done this in following way. select from one table and printed in one place and then moved to another table. I thing this long process. so only i need this way. sorry frnd my query also too long.

k frnd.

Member Avatar for rajarajan2017

Sugikrish, Please answer for the following queries:

i) Really you need where condition for the second query?
It will work only if you already have records with the idvalue in the orde table.
ii) Whether you have records with the same idvalue you passed from php?

Try to answer the following in a technical way.

1) I need "where" condition for the first query only for retrieving values from table.
I passed id from php . This id passed to next detail.php file like $idvalue=$_REQUEST; Then retrieve value from old table using where id='$idvalue.This underline id is one field of old table.

Have you checked and corrected your syntax in phpmyadmin

I dont know how checked in phpmyadmin. Bcoz i write query like "$idvalue=$_REQUEST". So according user selection it will retrieve the values. I don't know how check it in phpmyadmin.

Member Avatar for rajarajan2017

Mr sugikrish, As I already suggested in another post. you should first get into learning php and mysql environments and try with some code snippets available on the net. Your reply not making more sense.

I am printing your query at line no 5 and 22.
Run you page.
the final query will be printed on your browser
copy it and run it in phpmyadmin and see the error.

$query="select * from smenu where id='$idvalue'";
$result=mysql_query($query);

echo $query."<br>";

while($row=mysql_fetch_array($result))
{

$projectid=$row['id'];
$projectname=$row['main'];
$projectcat= $row['itemm'];
$scope=$row['descrip'];
$location=$row['Category'];
$rate=$row['Rate'];

}
echo " $projectid,$projectname,$projectcat,$scope,$location,$rate";


$query="insert into orde values('$projectid','$projectname','$projectcat','$scope','$location','$rate' where id='$idvalue')";
echo $query."<br>";
$dbase=mysql_query($query);
echo "$dbase";

Really thanks urtrivedi and rajarajan. Now am working on it.

Hey,
Always use

$dbase=mysql_query($query)or die(mysql_error());

the die part with mysql error for the development sides.This will clearly tell you the error that comes.

Thanks for your reply.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.