for($y=1;$y<=$x;$y++){

$query="insert into attendance values('$admission_no[$y]','$date','$state_id')";
     $result=mysql_query($query);
        }

sopme one can help me to know is this code right

What is the code supposed to be doing?

If $admission_no[$y] is only supposed to output the value of $y then you can replace "$admission_no[$y]" with just "$y".

Without more of the code and not knowing what it's supposed to do, we can't help much. Could you please provide more of the code. Censor any passwords that may be in the code, obviously. Could you also use the BB Tag when providing PHP code please.[code=php] BB Tag when providing PHP code please.

suppose there is a database.there is a one table call attendance.that table is available 3 field call admission no,date and state(student percent,student absent)
there are 3 arrays 1st one with admission no , 2 nd one with state .the admission no's array explode and get the admission no one by one.

$admission = array($admission_n);
$admission_no = explode("~",$admission);

for($y=1;$y<=$x;$y++){

$query="insert into attendance values('$admission_no[$y]','$date')";
     $result=mysql_query($query);
        }

that i wanted to know .that u think the admission no array 10 admission no available.
after that array explode .i want to enter that admission no one by one into database.
there for when i write the query i put $admission_no[$y] inside the value.i wanted to know is this correct.

$query="insert into attendance values('$admission_no[$y]','$date')";

Should be:

$query="insert into attendance(field1, field2) values('" . $admission_no[$y] . "','" . $date . "')";

You must select the field(s) to insert the value(s). $var="variable $var" and $var = "variable " . $var are not same.

if we put query like this is this not correct

$query="insert into attendance values('$admission_no[$y]','$date')";

without putting like this

$query="insert into attendance values('" . $admission_no[$y] . "','" . $date . "')";

but i have use some querys like this way those are working

$query="insert into attendance values('$admission_no','$date')";

Hi,

May be the fault is depends on the variable $x. Check whether the variable $x contains any values.

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.