SQL query... enters info twice
Posted: Tue Jun 03, 2003 9:47 pm
Hey all...
I'm inserting info using PHP/MySQl and I have a problem. When I run an insert query, I get two entries in to my database.
One is all the info I wanted, and the other is totally empty. Here's the code:
I can't find anything, so I hope you can.
Note: When I have the SQL print at the end of the script, it only shows that the script was run once, not twice. Weird huh?
I'm inserting info using PHP/MySQl and I have a problem. When I run an insert query, I get two entries in to my database.
One is all the info I wanted, and the other is totally empty. Here's the code:
Code: Select all
function select_game() {
echo "<table cellpadding=0 cellspacing=0 border=0 align="center">
<tr><td>";
echo "<form method="post" action="index.php?f=addreview">";
echo "<select name="game">";
$sql = mysql_query("select game , id from game_index");
while ($info = mysql_fetch_array($sql)) {
$game = $info['game'];
$id = $info['id'];
echo "<option value="$id">" .$game;
}
echo "</select> <input type="submit" value="Select Game"";
echo "</td></tr></table>";
}
function new_review() {
echo "<BR><BR>";
echo "<form method="post" action="index.php?f=infusereview">";
$indexid = $_POST['game'];
$author = $_SESSION['gp_username'];
$sql = mysql_query("select id from reviews where indexid = '$indexid'");
$num = mysql_num_rows($sql);
if ($num != 0) { die (" A review has already been written for this game! "); }
echo "<form method='post' action='cp_index.php?action=ireview'>";
echo "<input type='hidden' name='indexid' value='$indexid'>";
echo "<textarea name='introduction' rows='5' cols='25'>Introduction</textarea><BR><BR>";
echo "<b>Gameplay Rating:</b> <select name='gameplay_rating'>";
echo "<option>10";
echo "<option>9";
echo "<option>8";
echo "<option>7";
echo "<option>6";
echo "<option>5";
echo "<option>4";
echo "<option>3";
echo "<option>2";
echo "<option>1";
echo "<option>0";
echo "</select><BR>";
echo "<input type='text' name='gameplay_header' value='Gameplay Header'><BR>";
echo "<textarea name='gameplay' rows='5' cols='25'>This will be Gameplay</textarea><BR><BR>";
echo "<b>Graphics Rating:</b> <select name='graphics_rating'>";
echo "<option>10";
echo "<option>9";
echo "<option>8";
echo "<option>7";
echo "<option>6";
echo "<option>5";
echo "<option>4";
echo "<option>3";
echo "<option>2";
echo "<option>1";
echo "<option>0";
echo "</select><BR>";
echo "<input type='text' name='graphics_header' value='Graphics Header'><BR>";
echo "<textarea name='graphics' rows='5' cols='25'>This will be graphics</textarea><BR><BR>";
echo "<b>Sound Rating:</b> <select name='sound_rating'>";
echo "<option>10";
echo "<option>9";
echo "<option>8";
echo "<option>7";
echo "<option>6";
echo "<option>5";
echo "<option>4";
echo "<option>3";
echo "<option>2";
echo "<option>1";
echo "<option>0";
echo "</select><BR>";
echo "<input type='text' name='sound_header' value='Sound Header'><BR>";
echo "<textarea name='sound' rows='5' cols='25'>This will be Sound</textarea><BR><BR>";
echo "<b>Funfactor Rating:</b> <select name='funfactor_rating'>";
echo "<option>10";
echo "<option>9";
echo "<option>8";
echo "<option>7";
echo "<option>6";
echo "<option>5";
echo "<option>4";
echo "<option>3";
echo "<option>2";
echo "<option>1";
echo "<option>0";
echo "</select><BR>";
echo "<input type='text' name='funfactor_header' value='funfactor Header'><BR>";
echo "<textarea name='funfactor' rows='5' cols='25'>This will be Fun Factor</textarea><BR><BR>";
echo "<b>Plasmafactor Rating:</b> <select name='plasmafactor_rating'>";
echo "<option>10";
echo "<option>9";
echo "<option>8";
echo "<option>7";
echo "<option>6";
echo "<option>5";
echo "<option>4";
echo "<option>3";
echo "<option>2";
echo "<option>1";
echo "<option>0";
echo "</select><BR><BR>";
echo "<input type='text' name='plasmafactor_header' value='Plasmafactor Header'><BR>";
echo "<textarea name='plasmafactor' rows='5' cols='25'>This will be Plasmafactor</textarea><BR><BR>";
echo "<input type='text' name='conclusion_header' value='Conclusion Header'><BR>";
echo "<textarea name='conclusion' rows='5' cols='25'> This will be the Conclusion</textarea><BR><BR>";
echo "<input type='submit' value='Submit Review'>";
echo "</form>";
}
function infuse_review(){
$indexid = $_POST['indexid'];
$author = $_SESSION['gp_username'];
$introduction = $_POST['introduction'];
$conclusion = $_POST['conclusion_header'];
$conclusion_body = $_POST['conclusion'];
$gameplay_rating = $_POST['gameplay_rating'];
$gameplay= $_POST['gameplay_header'];
$gameplay_body = $_POST['gameplay'];
$sound_rating = $_POST['sound_rating'];
$sound = $_POST['sound_header'];
$sound_body = $_POST['sound'];
$funfactor_rating = $_POST['funfactor_rating'];
$funfactor = $_POST['funfactor_header'];
$funfactor_body = $_POST['funfactor'];
$graphics_rating = $_POST['graphics_rating'];
$graphics = $_POST['graphics_header'];
$graphics_body = $_POST['graphics'];
$plasmafactor_rating = $_POST['plasmafactor_rating'];
$plasmafactor = $_POST['plasmafactor_header'];
$plasmafactor_body = $_POST['plasmafactor'];
$fscore_add = $gameplay_rating + $sound_rating + $funfactor_rating + $graphics_rating + $plasmafactor_rating;
$finalscore_rating = $fscore_add / 5;
$sql = "insert into reviews ( finalscore , author , introduction , conclusion , conclusion_body , gameplay_rating , gameplay_body , gameplay , sound_rating , sound_body , sound , funfactor_rating , funfactor_body , funfactor , graphics_rating , graphics_body , graphics , plasmafactor_rating , plasmafactor_body , plasmafactor , indexid )
values ( '$finalscore_rating' , '$author' , '$introduction' , '$conclusion' , '$conclusion_body' , '$gameplay_rating' , '$gameplay_body' , '$gameplay' , '$sound_rating' , '$sound_body' , '$sound' , '$funfactor_rating' , '$funfactor_body' , '$funfactor' , '$graphics_rating' , '$graphics_body' , '$graphics' , '$plasmafactor_rating' , '$plasmafactor_body' , '$plasmafactor' , '$indexid')";
$act = mysql_query($sql);
echo "<b>" .$sql. "</b>";
}Note: When I have the SQL print at the end of the script, it only shows that the script was run once, not twice. Weird huh?