Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Why it will insert more than one time into the tables???

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Why it will insert more than one time into the tables???

Postby acswilson » Sat Aug 30, 2003 4:44 am

Code: Select all
<? include ("./verify_session1.php"); ?>
<HTML>
<style>
BODY {
   BACKGROUND-COLOR: #12A9E2;  FONT-FAMILY: Arial Narrow; FONT-SIZE: 12pt; TEXT-DECORATION: none; scrollbar-3dlight-color: #12A9E2; scrollbar-arrow-color: #4169E1; scrollbar-darkshadow-color: #4169E1; scrollbar-face-color: #FFFFFF; scrollbar-highlight-color: #4169E1; scrollbar-shadow-color: #4169E1; scrollbar-track-color: #E9E9E9
}
</style>
<BODY BGCOLOR="#12A9E2">
<table width="99%" border="0" align="center">
  <tr>
    <td width="20%">
      <div align="left"><font face="Arial Narrow" size="4">Welcome, <b>
        <?php
        (" $HTTP_COOKIE_VARS as $username1" );
        print ( "$username1" );
         ?>
        </b> ! </font></div>
    </td>
    <td width="69%">
      <h1 align="center"><font face="Arial Narrow">Online Attendance System</font></h1>
    </td>
    <td width="11%">
      <div align="right"><font face="Arial Narrow"><a href="welcome.php">Log Out</a></font>
      </div>
    </td>
  </tr>
</table>
<form method = "POST" action = "main1.php">
  <?
   if ($society == NULL)
   {
      
      echo"Please Try Again!!!<br><br><br>";
      echo"NO Society<br><br><br>";
        echo "Click <a href=\"society1.php\">here</a> to try again !!<br>";
       exit;
   }
   else
   { 
 
            $mysql_access = mysql_connect("localhost", "root", "");
                mysql_select_db("mw");
            $result = mysql_query("select * from society2");
                $number_of_rows = mysql_num_rows($result);
                $i=0;
                $check=0;
                while ($number_of_rows != 0)
                   {
                     $row =  mysql_fetch_row($result);
                     $number_of_rows--;
                 
                     if ($value==$row[0] && $username1==$row[1])
                        {
                        echo "<br>Invalid society <BR>Currently the $value has been checked!!<br>";
                        echo "<BR>Click <a href=\"society1.php\">here</a> to try again !!<br>";
                        exit;
                        }
                          else
                          {
                     foreach ($society as $key => $value)
                     {
                     $query = "INSERT INTO society2 values(\"$value\",\"$username1\")";
                     mysql_query($query, $mysql_access);
                     

                     echo "<br>\n<font face=\"Arial Narrow\"><font size=\"3\">Society :$value</font><br>\n";
                       echo "<font face=\"Arial Narrow\"><font size=\"3\">Username :$username1</font><br>\n";
                     }
                  }
               }
            
   }
?>
  <h1><FONT Align=Center COLOR= "Blue" ><font face="Arial Narrow" color="#000000">You
    had successfully send a message to other user. </font></Font> </h1>
  <h2><FONT   Align=Center COLOR= "Green" ><BR>
    <font face="Arial Narrow" color="#FFFFFF">These information has been stored
    into the database</font></Font><font face="Arial Narrow"><BR>
    </font></h2>

    <PRE>
   
</PRE>
  <div align="left">
    <INPUT TYPE ="submit"  VALUE = "Continue >>>" ALIGN = middle >
    <BR>
    <BR>
    <BR>
  </div>
</FORM>
</BODY>
</HTML>


acswilson
New php-forum User
New php-forum User
 
Posts: 18
Joined: Thu Jul 17, 2003 7:42 am

Postby Joel » Sat Aug 30, 2003 1:57 pm

Code: Select all
                     foreach ($society as $key => $value)
                     {
                     $query = "INSERT INTO society2 values(\"$value\",\"$username1\")";
                     mysql_query($query, $mysql_access);
                     

                     echo "<br>\n<font face=\"Arial Narrow\"><font size=\"3\">Society :$value</font><br>\n";
                       echo "<font face=\"Arial Narrow\"><font size=\"3\">Username :$username1</font><br>\n";
                     }


I don't know why you posted the whole lot of code, but I think the problem will be in this bit. I noticed your Insert query is in a for each loop, and if it is inserting more than once - then you must have for than one existence of $society. Which it is hard to tell, as you did not post the part of the code where society is assigned a value, or many values. Do you understand how a for loop works?

Also I notice this in your code.

Code: Select all
        <?php
        (" $HTTP_COOKIE_VARS as $username1" );
        print ( "$username1" );
         ?>


What is the point of that? It seems like you are saying "Put this array as the variable $username1 and print out that variable."
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

I think u don't know what i means

Postby acswilson » Sun Aug 31, 2003 4:38 am

in the coding i need to insert more than one society value, then i need the for loop. However, there are the duplicate value for one society.
Example,
When i checked 4 check box and post the value as society[], then i use the for loop to insert the values.
Each of the value will be duplicate insert into the tables.
For an example,
- first check box value is IT Society
- second check box value is Image Society
- third check box value is Basketball Club
- forth check box value is Baseball Club
1st one will insert only one time.
2nd will insert two times.
3rd will insert four times.
4th will insert 8 times.
That is means the following value will be insert as previous multiply 2 times.
Please help me to solve this problem.
And the Cookies is just to store data (username1) but now i have delete it.
acswilson
New php-forum User
New php-forum User
 
Posts: 18
Joined: Thu Jul 17, 2003 7:42 am

multiple values

Postby ruturajv » Sun Aug 31, 2003 9:17 pm

I don't why you need multiple rows for it, you can rather make a comma separated value using an implode function and then store it with a single row

Is my suggestion what you can use :?:

I hope you just require to store those values any way !!
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

I must insert more than one values into the database

Postby acswilson » Sun Sep 07, 2003 5:01 am

i use the array to insert values into the database
acswilson
New php-forum User
New php-forum User
 
Posts: 18
Joined: Thu Jul 17, 2003 7:42 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.