PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Nov 27, 2014 7:11 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Wed Apr 11, 2012 8:05 am 
Offline
Forum Newbie

Joined: Mon Apr 09, 2012 10:08 pm
Posts: 20
social_experiment wrote:
kwh01 wrote:
it inserted 2 rows at once. hmm. cannot figured it out why

How many subjects did you select?

perviously is two, but now i get some other error again = =


here is the query i trying to insert the subject number and student ID inserted

but now, no more inserted 2 row per once. it can insert into my table but show me this error.
Error: 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 '1' at line 1

and im trying to select 2 checkbox but it only insert the 1st record into table only


Last edited by kwh01 on Sat Apr 14, 2012 3:58 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Wed Apr 11, 2012 8:15 am 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2775
Location: .za
The syntax for the query seems ok; the column you are inserting into (i'm guessing it will be subjectnumber), is it marked 'unique'?

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
PostPosted: Wed Apr 11, 2012 8:18 am 
Offline
Forum Newbie

Joined: Mon Apr 09, 2012 10:08 pm
Posts: 20
social_experiment wrote:
The syntax for the query seems ok; the column you are inserting into (i'm guessing it will be subjectnumber), is it marked 'unique'?


hmm, nope. i did not set any key for subjectnumber or studentID in table


Top
 Profile  
 
PostPosted: Wed Apr 11, 2012 8:47 am 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2775
Location: .za
Amend the code to the example below and paste the data printed to the browser
Syntax: [ Download ] [ Hide ]
<?php
foreach($_POST['stusubject']  as $subjectnumber)
                                {
                                        $sql="INSERT INTO $tbl_name(studentID,subjectnumber)VALUES('$_SESSION[stuID]','$subjectnumber')";
                                        echo $sql . '<br />';
                                        /*
                                        $qry = mysql_query($sql);
                                        if (!mysql_query($qry))
                                        {
                                        //die('Error: ' . mysql_error());
                                            echo
                                        }
                                        */

                                }
?>

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
PostPosted: Wed Apr 11, 2012 8:47 am 
Offline
Forum Newbie

Joined: Mon Apr 09, 2012 10:08 pm
Posts: 20
Syntax: [ Download ] [ Hide ]
if (!mysql_query($qry))
 {
die('Error: ' . mysql_error());
}
 


sir, after i removed this line, it works like a charm. omg.


Top
 Profile  
 
PostPosted: Wed Apr 11, 2012 8:51 am 
Offline
Forum Newbie

Joined: Mon Apr 09, 2012 10:08 pm
Posts: 20
thank you sir for assisting me . finally i can check the checkbox and insert into my database.
thanks alot


Last edited by kwh01 on Sat Apr 14, 2012 3:58 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Wed Apr 11, 2012 9:08 am 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2775
Location: .za
what did you do to solve the issue

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
PostPosted: Wed Apr 11, 2012 11:45 pm 
Offline
Forum Newbie

Joined: Mon Apr 09, 2012 10:08 pm
Posts: 20
social_experiment wrote:
what did you do to solve the issue

Syntax: [ Download ] [ Hide ]
if (!mysql_query($qry))
 {
    die('Error: ' . mysql_error());
}
 



Hi social_experiment, i just removed this line and it work perfectly.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group