coder9 Posted July 23, 2008 Share Posted July 23, 2008 every time my codes insert a new record it insert a duplicate. here is the first page. <? include('jpfunctions.php'); global $link; global $game_no_tempo; $game_no_tempo=1; //update the the game number get_last_record_game_no($game_no_tempo); echo "<br><br>"; $includes[content]=" <b>JACKPOT NUMBER 35</b> <br> <h1>This page is under construction...</h1> <br> "; //if new cell selected then store it to table. if($link != 0 || $link != '') { store_cell_number($link, $username); } ?> <?php //Connecting the right path. //$images_dir = 'http://' . $_SERVER['HTTP_HOST'] . '/mygallery/photos/'; //$referer2 = $_SERVER['HTTP_REFERER']; //$jp_dir= 'http://' . $_SERVER['HTTP_HOST'] . '?view=.{$view}.&sid=.{$sid}.&sid2=.{$sid2}.&siduid=.{$siduid}.'; //<a href=\"".$referer2."?link=1\"> $jp_dir= 'http://' . $_SERVER['HTTP_HOST'] . '/index.php?view='. $view . '&sid='. $sid . '&sid2='. $sid2 . '&siduid=' . $siduid . '&'; ?> <?php //check database of already selected numbers //then Display the table //Fill the array with color background. $tmpbakcolor = array_fill(1,100,'#FF0000'); $link=$_GET['link']; #get_selected_box(); ###get already selected box and display disabled background color to all selected box. //access all field name of jtablegrid $query = "SELECT * FROM jtablegrid WHERE game_no = 1"; $result = mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error()); $row = mysql_fetch_row($result); //get all value from jtablegrid and display disabled color $i=2; //database $filled_cell=0; $game_no_tmp=0; $link2=1; //table while($i <=101) { $i2 = $i-1; if($row[$i] != '') { if($row[$i] != '') { if($i2 == $link2) { #echo "$i2:$link2<br>"; $tmpbakcolor[$link2]="#C0C0C0"; } } //check if cell is already filled. //if filled assign variable. if($row[$i] != '') { $filled_cell++; $game_no_tmp=$filled_cell; } } $i++; $link2++; } //Show total number of filled cell. echo "variable game_no_tmp: " .$game_no_tmp; echo "<br>"; echo "variable game_no: " .$game_no; //add record if 100 cells are filled. addrecord_100cell($game_no_tmp, $game_no, $game_no_tempo); /* //assign background color to cell while($i<=100) { if($i == $link) { $tmpbakcolor[$link]="#C0C0C0"; } $i++; } */ #check_selected_box3(); ?> here is the 2nd page. <?php ### Jackpot Functions ### ### Getting the current game_no value and storing the value. function get_last_record_game_no($game_no_tempo) { //select last record and get the value of game_no //store it into $game_no_tempo //then call addrecord_100cell() function $query = "SELECT * FROM jtablegrid WHERE game_no = LAST_INSERT_ID()"; $result = mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error()); $row = mysql_fetch_row($result); $game_no_tempo = $row['game_no']; } ### Getting the game_no status and storing the value. function store_cell_number($link, $username){ #$query = "INSERT INTO jtablegrid (user_box" . $link . ") VALUES ('" . $link . "')"; #$query = "INSERT INTO jtablegrid (user_box" . $link . ") VALUES ('.$link.')"; //get status of jtablegrid get all column value. //concatenate the name. $tmp_name = 'user_box' . $link; //update if cell column not empty. if($tmp_name != 'user_box' || $tmp_name == '') { #$query = "INSERT INTO jtablegrid ($tmp_name) VALUES ('.$link.')"; $query = "UPDATE jtablegrid SET $tmp_name='$username' WHERE game_no = $game_no_tempo"; mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error()); } } //access all field name of jtablegrid function display_gameno() { $query = "SELECT * FROM jtablegrid WHERE game_no = $game_no_tempo"; $result = mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error()); $row2 = mysql_fetch_row($result); //this will display the game no. echo "Jackpot number: " . $row2['game_no']; } ###get already selected box and display disabled background color to all selected box. function get_selected_box() { //access all field name $query = "SELECT * FROM jtablegrid WHERE game_no = $game_no_tempo"; $result = mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error()); $row = mysql_fetch_row($result); $i=2; //database $link2=1; //table while($i <=100) { $i2 = $i-1; if($row[$i] != '') { if($row[$i] != '') { if($i2 == $link2) { #echo $row[$i]; $tmpbakcolor[$link2]="#C0C0C0"; echo "$i2:$link2<br>"; } } } $i++; $link2++; } } ###this will insert another record, another game. function addrecord_100cell($game_no_tmp, $game_no, $game_no_tempo) { //display blank table cells again and reset game. //display Jackpot no. //display 100 tickets remaining. //display previous winners. if($game_no_tmp==100){ //if 100 cell are filled increment game_no $game_no_tempo++; //update the value of $game_no_tempo $query = "INSERT INTO jtablegrid (game_no) VALUES($game_no_tempo)"; mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error()); } } ###get already selected box and display disabled background color to all selected box. function check_selected_box2() { //access all field name $query = "SELECT * FROM jtablegrid WHERE game_no = 1"; $result = mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error()); $i=0; while ($row = mysql_fetch_row($result)) { if(($row[$i] != '')&& (strlen(trim($row[$i]))> 0)) { echo "user" . $row[$i]; echo "<br>"; } $i++; } } ###get already selected box and display disabled background color to all selected box. function check_selected_box3() { //access all field name $query = "SELECT * FROM jtablegrid WHERE game_no = 1"; $result = mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error()); $row = mysql_fetch_row($result); $i=2; while($i <=100) { $i2 = $i-2; if($row[$i] != '') { #if($i == $link) { $tmpbakcolor[$link]="#C0C0C0"; #} } $i++; } } ?> the first page only call the function from the 2nd page. Thank you. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 23, 2008 Share Posted July 23, 2008 please.... Give more details ? You are inserting a record, which is identical to one that already exists ? Do a mysql_num_rows(); check with a SELECT of all the users. or whatever table. And die if that user already exists. Quote Link to comment Share on other sites More sharing options...
unkwntech Posted July 23, 2008 Share Posted July 23, 2008 I think that he is doing this and he is getting the record inserted twice, while only processing the script/data once. I to have had this problem but I don't remember why. Quote Link to comment Share on other sites More sharing options...
coder9 Posted July 23, 2008 Author Share Posted July 23, 2008 ok this is the updated (simplified) codes that i used above. this is the first page. <? include('jpfunctions.php'); global $link; global $game_no_tempo; $game_no_tempo=1; //update the the game number get_last_record_game_no($game_no_tempo); echo "<br><br>"; $includes[content]=" <b>JACKPOT NUMBER </b> <br> <h1>This page is under construction...</h1> <br> "; //if new cell selected then store it to table. if($link != 0 || $link != '') { update_cell_number($link, $username); } ?> <?php //Connecting the right path. $jp_dir= 'http://' . $_SERVER['HTTP_HOST'] . '/index.php?view='. $view . '&sid='. $sid . '&sid2='. $sid2 . '&siduid=' . $siduid . '&'; ?> <?php //Fill the array with color background. $tmpbakcolor = array_fill(1,100,'#FF0000'); $link=$_GET['link']; //check database of already selected cell numbers $query = "SELECT * FROM jtablegrid WHERE game_no = $game_no_tempo"; $result = mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error()); $row = mysql_fetch_row($result); //match selected number of cells and jtablegrid values. //and display disabled color $i=2; //database $filled_cell=0; $game_no_tmp=0; $link2=1; //table while($i <=101) { $i2 = $i-1; if($row[$i] != '') { if($row[$i] != '') { if($i2 == $link2) { #echo "$i2:$link2<br>"; $tmpbakcolor[$link2]="#C0C0C0"; } } //check if cell is already filled. //if filled assign variable. if($row[$i] != '') { $filled_cell++; $game_no_tmp=$filled_cell; } } $i++; $link2++; } //Show total number of filled cell. echo "variable game_no_tmp: " .$game_no_tmp; echo "<br>"; echo "variable game_no: " .$game_no_tempo; //add record if 100 cells are filled. addrecord_100cell($game_no_tmp, $game_no, $game_no_tempo); ?> and this is the page that has the functions. <? include('jpfunctions.php'); global $link; global $game_no_tempo; $game_no_tempo=1; //update the the game number get_last_record_game_no($game_no_tempo); echo "<br><br>"; $includes[content]=" <b>JACKPOT NUMBER </b> <br> <h1>This page is under construction...</h1> <br> "; //if new cell selected then store it to table. if($link != 0 || $link != '') { update_cell_number($link, $username); } ?> <?php //Connecting the right path. $jp_dir= 'http://' . $_SERVER['HTTP_HOST'] . '/index.php?view='. $view . '&sid='. $sid . '&sid2='. $sid2 . '&siduid=' . $siduid . '&'; ?> <?php //Fill the array with color background. $tmpbakcolor = array_fill(1,100,'#FF0000'); $link=$_GET['link']; //check database of already selected cell numbers $query = "SELECT * FROM jtablegrid WHERE game_no = $game_no_tempo"; $result = mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error()); $row = mysql_fetch_row($result); //match selected number of cells and jtablegrid values. //and display disabled color $i=2; //database $filled_cell=0; $game_no_tmp=0; $link2=1; //table while($i <=101) { $i2 = $i-1; if($row[$i] != '') { if($row[$i] != '') { if($i2 == $link2) { #echo "$i2:$link2<br>"; $tmpbakcolor[$link2]="#C0C0C0"; } } //check if cell is already filled. //if filled assign variable. if($row[$i] != '') { $filled_cell++; $game_no_tmp=$filled_cell; } } $i++; $link2++; } //Show total number of filled cell. echo "variable game_no_tmp: " .$game_no_tmp; echo "<br>"; echo "variable game_no: " .$game_no_tempo; //add record if 100 cells are filled. addrecord_100cell($game_no_tmp, $game_no, $game_no_tempo); ?> Again i still can't figure out why there is always a duplicate when i insert a new record. Please your help is very appreciated. Thank in advance. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.