0

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>

Edited by mike_2000_17: Fixed formatting

4
Contributors
19
Replies
20
Views
7 Years
Discussion Span
Last Post by sugikrish
0

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

0

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')";
0

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.

0
$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.

Edited by urtrivedi: n/a

0

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.

0

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

Edited by mike_2000_17: Fixed formatting

0

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.

0

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.

Edited by rajarajan07: n/a

0

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.

0

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.

0

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.

Edited by rajarajan07: n/a

0

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";
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.