₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,065 members, 8,420,128 topics. Date: Thursday, 04 June 2026 at 11:49 AM

Toggle theme

Is This Code Logical? Function Parameters Insert Statement - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingIs This Code Logical? Function Parameters Insert Statement (1184 Views)

1 Reply (Go Down)

Is This Code Logical? Function Parameters Insert Statement by uvalued(op): 6:09pm On Aug 04, 2016
Note: Using mysql is deliberate but will convert it to pdo.

Am trying to use INSERT statement in a function and send data as parameters which should be inserted into the database.

I ran the codes below but it failed ....

is it a correct way of running such?
summary($no112m,$name112m,$remark112m);
function summary($no,$name,$remark)
{
$query2 = "insert INTO summary
(
sn,
no,
name,
grade
) ".
"VALUES
( '',
'$no',
'$name',
'$remark'

)";
begin();// transaction begins
$result = mysql_query($query2);
if($result){
commit();
// transaction rolls back
echo "COMMITTED 112";

}else
{
rollback();
echo "Transacton failed 112";
exit;

}

}
Re: Is This Code Logical? Function Parameters Insert Statement by Nobody:
uvalued:
Note: Using mysql is deliberate but will convert it to pdo.

Am trying to use INSERT statement in a function and send data as parameters which should be inserted into the database.

I ran the codes below but it failed ....

is it a correct way of running such?
1) You should run a function after declaration...
2) It seems you have syntax errors in your Insert statement,
3) Mysql is deprecated, use mysqli instead.
4) exit is an inbuilt function, so you should use exit() instead.

The logic is OK, take a look at code igniter.. A PHP framework that eases development
Re: Is This Code Logical? Function Parameters Insert Statement by Codenister: 9:33pm On Aug 04, 2016
Well, I didn't really take time out to study the correctness of your code, but I can tell you what you have done is logically correct.
Also, I'm assuming in your proper code, you will declare the function before invoking it.
Re: Is This Code Logical? Function Parameters Insert Statement by uvalued(op): 7:17am On Aug 05, 2016
DanielTheGeek:
1) You should run a function after declaration...
2) It seems you have syntax errors in your Insert statement,
3) Mysql is deprecated, use mysqli instead.
4) exit is an inbuilt function, so you should use exit() instead.

The logic is OK, take a look at code igniter.. A PHP framework that eases development
thanks a lot... i got it working...on cogeigniter, i have this laziness to learn becos of huh? i just lay my finger on it solidly...in your opinion what is that simple thread that makes it thick..a little push may give me some good light
Re: Is This Code Logical? Function Parameters Insert Statement by uvalued(op): 7:18am On Aug 05, 2016
Codenister:
Well, I didn't really take time out to study the correctness of your code, but I can tell you what you have done is logically correct.
Also, I'm assuming in your proper code, you will declare the function before invoking it.
thanks got it working
Re: Is This Code Logical? Function Parameters Insert Statement by furthest(m): 4:36pm On Aug 07, 2016
Codenister:
Well, I didn't really take time out to study the correctness of your code, but I can tell you what you have done is logically correct.
Also, I'm assuming in your proper code, you will declare the function before invoking it.
talking about functions an invocation..pls can i call functions directly 4rm my my operating system?
1 Reply

Java Programmers ,I Need Help Fixing This Code.Please Someone Should Help Me With This Code.PHP Code To Insert And Retrieve Images From Mysql Server234

Introducing Randgen, Codeigniter Library For Generating...How To Add Script On Drupal Header?Konga Launches Game Of Codes Developer Challenge For Nigeria University Students