Jump to content

FAILED TO INSERT DATA FROM FUNCTION();


sitinuraini

Recommended Posts

HELLO, I HAVE A PROBLEM TO INSERT DATA FROM OUTPUT FROM FUNCTION()...

I WANT TO STORE THE OUTPUT IN DATABASE, BUT FAILED TO INSERT...

 

===============================================

BELOW IS MY FUNCTION() CODE, academiaTotal.php

===============================================

<?php

$page = 'fkpacademia.php';

 

//connect db

 

function totalMac_ac1(){

$query1 = "SELECT AVG(MAC) FROM academia1";

$result1 = mysql_query($query1) or die(mysql_error());

 

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

echo "".number_format($row1['AVG(MAC)'],1);

 

$sql = "INSERT INTO fkpacademia (MAC) VALUES ('$row1['AVG(MAC)']')";

}

}

 

---?>

 

======================================

MY CALL FUNCTION fkpacademia.php

======================================

<?php require 'academiaTotal.php' ?>

 

<? totalMac_ac1(); ?>

 

 

 

**********************************************

MY PROBLEM NOW IS THE sql(INSERT, (AVG(MAC) output... )) NOT SUCCESS... NO DATA INSERTED IN fkpacademia table.. AND I WANT TO UPDATE ALWAYS (AVG(MAC) from academiaTotal )... (MEANS THAT fkpacademia only have 1 record of AVG(MAC)...)

 

hope anyone can help me...

Link to comment
Share on other sites

i have ask my friend about that.. should i need to insert and update also.. update must do in sql right? but, the problem now is i think the insert above not send any output. cause my table still empty.. i need to store the output from function(), store into db.. so that i do insert but not working... or me myself do wrong for above code..? can u explain to me clearly?

Link to comment
Share on other sites

phpMyAdmin - 2.11.7

Server version: 5.0.51b-community-nt

 

 

before this....

.........................

function totalMac_ac1(){

$query1 = "SELECT AVG(MAC) FROM academia1";

$result1 = mysql_query($query1) or die(mysql_error());

 

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

echo "".number_format($row1['AVG(MAC)'],1);

 

$sql = "INSERT INTO fkpacademia (MAC) VALUES ('$row1['AVG(MAC)']')";

$result=mysql_query($sql);

}

}

..........................

 

 

just now i have this,

bigTotal.php

==============

function bigMac_ac1(){

$sql = "INSERT INTO fkpacademia (MAC) VALUES ('$row1['AVG(MAC)']')";

$result=mysql_query($sql);

 

$query1a = "SELECT AVG(MAC) FROM fkpacademia";

$result1a = mysql_query($query1a) or die(mysql_error());

 

while($row1 = mysql_fetch_array($result1a)){

echo "".number_format($row1['AVG(MAC)'],1);

 

}

}

 

 

========================

fkpacademia.php

========================

<?php require 'bigTotal.php' ?>

<? bigMac_ac1(); ?>

 

 

 

problem: no data store in table fkpacademia..

please somenone help me where the wrong...

Link to comment
Share on other sites

I put your original code into my editor and it showed an error on your insert line. Try changing things to this and let me know..

 

echo "".number_format($row1['AVG(fcmb)'],1);
$NUM = number_format($row1['AVG(fcmb)'],1);
$sql = "INSERT INTO fkpacademia (MAC) VALUES ($NUM)";
$result=mysql_query($sql);

 

 

Link to comment
Share on other sites

thanks sunfighter...

i have try ur idea, it give what i want (to store in fkpacademia table), but a little problem, it goes to double row from the academia... (speak broken english..sorry), and so that i just change back to be like this,

 

echo "".number_format($row1['AVG(MAC)'],1);

$NUM = number_format($row1['AVG(MAC)'],1);

$sql = "INSERT INTO fkpacademia (MAC) VALUES ($NUM)";

$result=mysql_query($sql);

 

just change the name variable, it give only one row inserted.. and every changes of AVG, it go to next row in the table... (means i should do UPDATE here)... but its okay.. my problem solved right now.. THANKS A LOT...  :D

Link to comment
Share on other sites

-------------------------------------------

 

$sqll = "UPDATE fkpacademia SET MAC = '$NUM' WHERE BIL='$BIL' ";

    $result=mysql_query($sqll);

 

 

anyone, data above will be updated, after next to next row..

i want it updated from their row only...

like i want to set,  $NUM1 = $BIL1, $NUM2 = $BIL2, something like that...

how can i do that..?

 

i'm beginner in programming...

Link to comment
Share on other sites

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.