It sais Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given on line74 and I tried a lot of things.

here is code

[$query="SELECT *
        FROM specificati,ofertant,suprafete,preturi,manopera
        WHERE ofertant.id_ofertant=preturi.id_ofertant
        AND preturi.id_manopera='Montaj parchet'
        AND preturi.id_manopera=manopera.id_manopera
        AND specificati.id_camera=suprafete.id_camera
        ";

         if (isset($query) && !empty($query)) {
        echo"<!--" . $query . "-->";
        $result=mysql_query($query)
        or die ("invalid query 4: " . mysql_error ());}
        //Multiple results per table (each ina a row)
        //start table

       while($row=mysql_fetch_array($result))
       {{
       echo "<table><table border='1'>
            <th>id_ofertant</th>
            <th>Denumire Camera</th> 
            <th>Manopera</th>
            <th>U.M</th>
            <th>Suprafata(mp)</th>
            <th>Pret</th>
            <th>Total</th>";

          echo "<tr><td>";
          echo $row['id_ofertant'];
          echo "</td><td>" ;
          echo $row['Denumire_camera']  ;             
          echo "</td><td>" ;
          echo $row['id_manopera'];
          echo "</td><td>" ;
          echo $row['um'] ;
           echo "</td><td>" ;
          echo $row['Paviment']; 
          echo "</td><td>" ;
          echo $row['Pret_manopera'];
          echo"</td><td>" ;
          $Total=$row['Pret_manopera']*=$row['Paviment'];
         echo $Total;
            echo"</td></tr>";
            echo "</table>";
            }
            }
            ?>
<?php

  $query1="INSERT INTO valoare_lucrari
                (
                id_ofertant,
                id_manopera,
                Denumire_camera,
                um,
                Cantitate,
                Pret_manopera,
                Total
                )Values(
            '" . $row['id_ofertant'] ."' ,
            '" . $row['id_manopera']."',
            '" . $row['Denumire_camera'] ."' , 
            '" . $row['um']."' ,
            '" . $row['Paviment']."', 
            '" . $row['Pret_manopera']."',
            '" .  $Total . "')";
             if (isset($query1) && !empty($query1)) {
            echo"<!--" . $query1 . "-->";
                $result1=mysql_query($query1)
            or die ("invalid query 5: " . mysql_error ());}

//Here is line 74

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

             echo "Insert succeded";

           };
Member Avatar for rajarajan2017

if seems mysql_fetch_array($result) $result is failed.Check for errors using

$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

if seems mysql_fetch_array($result) $result is failed.Check for errors using

$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

But i have that look few line above

Member Avatar for rajarajan2017

Sorry, I was not watched becoz of not with CODE tag. Okay,

echo $query;

Then from your browser copy the output of $query and paste it in phpmyadmin sql editor and execute it. To identify whether it returns rows?

I have echo query 1 and I get this on rows but every row display the table head to. Is this the problem?
1 Sufragerie Montaj parchet mp 32 5 160

Member Avatar for rajarajan2017

I didn't get you? Did you copied the result of query1 and paste it in your phpmyadmin sql editor? If it is executed properly then you get 1 rows affected or something. what you got?

Are you telling the row updated in the table. What the below is meant?

but every row display the table head to

Still you getting the warning message?

I have paste this:" Sufragerie Montaj parchet mp 32 5 160 LIMIT 0, 30'" on edit by phpmyadmin,
and I receive this
#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 '`valoare_lucrari`1 Sufragerie Montaj parchet mp 32 5 160' at line 1

I'm very sorry but I am a newbie with php so....

I get it the message error is:#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="SELECT * FROM specificati,ofertant,suprafete,preturi,manope' at line 1

Member Avatar for rajarajan2017

Sorry I meant should also follow the syntax, What is the output of echo query1, something start with Insert into... r8? because it is not a parsed result, it is just a string. What it outputs?

so the $query is ok but $query1 does not execute. I really need that some data from $query to be inserted in table valoare_lucrari. What's wrong with $query1 ?

I think you ask about this $Total=$row*=$row;
echo $Total;and it work fine it echoing ok

I need to insert some data from $query to tabel valoare_lucrari.it something wrong with $query1. What.?

I think the problem is that you try to fetch the result from an insert query. This is not possible. As you can read on php.net/mysql_query:

"For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error."

Concluding: mysql_fetch_array($result1) is not allowed. But you can query $result1 whether the query succeeded (true) or failed (false).

Member Avatar for rajarajan2017

Instead of this

$result1=mysql_query($query1)
or die ("invalid query 5: " . mysql_error ());}
//Here is line 74
while($row=mysql_fetch_array($result1)){

echo "Insert succeded";

};

Use this:

$result1 = mysql_query($query1) or die ("Error in query: $query1. ".mysql_error()); 
if (mysql_num_rows($result1) > 0) { 
   echo "Insert succeded";
}else echo "Rows not inserted";

I think the problem is that you try to fetch the result from an insert query. This is not possible. As you can read on php.net/mysql_query:

"For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error."

Concluding: mysql_fetch_array($result1) is not allowed. But you can query $result1 whether the query succeeded (true) or failed (false).

Thank you for your answer.

Member Avatar for rajarajan2017

Cristi08, Plz check with the above code

Use this:

$result1 = mysql_query($query1) or die ("Error in query: $query1. ".mysql_error()); 
if (mysql_num_rows($result1) > 0) { 
   echo "Insert succeded";
}else echo "Rows not inserted";

rajarajan07, this will give the same error as before because both mysql_num_rows and mysql_fetch_array expect a resource as parameter. An insert or delete query will return true or false, so you just need to check the result.

Member Avatar for rajarajan2017

Thanks pritaeas, but I dont know that and I have to test.

Cristi08, then just do as below

$result1 = mysql_query($query1) or die ("Error in query: $query. ".mysql_error());
// print message with ID of inserted record 
echo "New record inserted with ID ".mysql_insert_id();

My Dear rajararan unfortunately I get this:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Calculatii\Deviz.php on line 66
Rows not inserted
I will chek one more the curly braces and if it not from there i'l do something ...
Thank you for your effort

I don't have a column for id on this tabel

the message is New record with id 0

Pritaes the first query it a selecte * from , I use a new variable $Total and I try to put this data and $Total in to another table. It not a Select - Insert from Mysql?

Do you want to put several values from each selected row into the new table ? If this is what you want, then your code is in the wrong order.

Anyway, the mysql_insert_id() returns zero because you do not have an autoinc column in your table.

<?php
	$query = "SELECT * FROM specificati,ofertant,suprafete,preturi,manopera WHERE ofertant.id_ofertant=preturi.id_ofertant AND preturi.id_manopera='Montaj parchet' AND preturi.id_manopera=manopera.id_manopera AND specificati.id_camera=suprafete.id_camera";

	if (isset($query) && !empty($query)) {
		echo"<!--" . $query . "-->";
		$result = mysql_query($query) or die ("invalid query 4: " . mysql_error ());}
		//Multiple results per table (each ina a row)
		//start table
	
		while ($row = mysql_fetch_array($result)) {
			echo "<table><table border='1'><th>id_ofertant</th><th>Denumire Camera</th><th>Manopera</th><th>U.M</th><th>Suprafata(mp)</th><th>Pret</th><th>Total</th>";
			echo "<tr><td>{$row['id_ofertant']}</td>";
			echo "<td>{$row['Denumire_camera']}</td>"; 
			echo "<td>{$row['id_manopera']}</td>"; 
			echo "<td>{$row['um']}</td>"; 
			echo "<td>{$row['Paviment'}</td>"; 
			echo "<td>{$row['Pret_manopera'}</td>";
			$Total = $row['Pret_manopera'] * $row['Paviment'];
			echo "<td>$Total</td></tr>";
			echo "</table>";
			
			$query1 = "INSERT INTO valoare_lucrari (id_ofertant,id_manopera,Denumire_camera,um,Cantitate,Pret_manopera,Total)Values('{$row['id_ofertant']}','{$row['id_manopera']}','{$row['Denumire_camera']}','{$row['um']}','{$row['Paviment']}','{$row['Pret_manopera']}','{$Total}')";
			if (isset($query1) && !empty($query1)) {
				$result1 = mysql_query($query1);
				// if ($result1)
				//   echo "inserted";
			}
		}
	}
?>
Member Avatar for rajarajan2017

That is my thought too, cristi08 code is not formed properly (Confused me becoz of not within (code)) , If we follow the steps of the code, it must return only one row of first query and if he want to use the array then it probably should use within the first loop. If he wants to store all the values whatever he got from the result then the above pritaeas is the right code.

Cristi08, did you achieved?

PRITAES YOU DID IT but...
.no error but al the value inserted are" 0"

That is a different problem. I can only solve that if i have your tables and data. Note that the table column names in $row are case-sensitive. Other than that nothing comes to mind.

Thank you pritaes at least that I can do.I have a lot of problems because of the punctuation. I read a lot but i still can't get it. I ve lost 2 days because of the wrong curly braces.

Member Avatar for rajarajan2017

comment your while code and check with below to know really you getting values from table:

if (mysql_num_rows($result) > 0) { 
while ($row = mysql_fetch_array($result)) {
 echo $row['id_ofertant'];
 echo "<br/>";
}
}else "No records found";

If returns No records found, then the query may be wrong. or print something but not from the table. Then the column name may be wrong. Get back what you get?

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.