3motions Posted September 18, 2008 Share Posted September 18, 2008 Okay, so I'm having a weird experience with my code here.. This is the first time I've used cookies with PHP for site authentication and holding different variables, so I'm not sure if this is the cause or what's going on. But here's what happening.. I'm in the process of creating a GPT website (get paid to). In my staff section, I have a place where staff members can go in and put new offers in for the members of the website to fill out. However, using the code I've included below, when I go to type in a new offer for the users, two MySQL entries show up in the database. One with all of the information in the form, and the next entry with everything blank. Can anyone help me out here? <? include("inc_headerm.php"); ?> <tr> <td width="885" height="80" align="center"><img src="images/headers/member.jpg" width="885" height="80" border="0" alt="gpt network get paid to header welcome"></td> </tr> <tr> <td width="885" height="100%" valign="top" align="center"> <? // start final content // ?> <table width="885" height="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="100%" style="background-image: url(images/page_leftbg.jpg); width: 46px; background-position: top left; background-repeat: repeat-y"><img src="images/spacer.gif" width="46" height="1"></td> <td height="100%" width="798" style="background-color: #ffffff" valign="top" align="center"> <? // final content // ?> <table width="777" height="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="top" width="450" height="100%"> <? // left content section // ?> <? if(isset($_COOKIE['userid']) && $_COOKIE['userlevel']=='0'){ echo "<table width='777' border='0' cellpadding='0' cellspacing='0'>"; echo "<tr>"; echo "<td width='192' valign='top'>"; // member menu starts include("staff_menu.php"); // member menu ends echo "</td>"; echo "<td width='12'><img src='images/spacer.gif' width='12' height='1' alt='gpt get paid to network spacer 30' /><br /></td>"; echo "<td width='573' valign='top'>"; ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // begin header echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td style='border: 1px solid #000000'>"; echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"; echo "<tr>"; echo "<td style='border: 1px solid #ffffff; background-color: #000000; color: #ffffff; padding-left: 10px; font-weight: bold' valign='middle' height='25'>Add New Offer</td>"; echo "</tr>"; echo "</table>"; echo "</td></tr></table>"; // end header // begin header description echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td valign='top' style='padding: 10px'>"; echo "To add a new offer for the member's to fill out, complete the form below. ALL fields must be completed. NO EXCEPTIONS!<br>"; echo "</td></tr></table>"; // end header description $addnew1=$_GET["addnew"]; if($addnew1=='1'){ $add_offername=$_POST["add_offername"]; $add_urlrewrite=$_POST["add_urlrewrite"]; $add_description=$_POST["add_description"]; $add_url=$_POST["add_url"]; $add_points=$_POST["add_points"]; $add_level=$_POST["add_level"]; mysql_query("insert into offers (offerid,title,titlerewrite,description,url,pointworth,level,active)". "VALUES ('NULL','$add_offername','$add_urlrewrite','$add_description','$add_url','$add_points','$add_level','1')"); echo "<b>* The new offer has been added to the database.</b><br>"; echo "<br>"; } echo "<form name='addoffer' method='post' action='?addnew=1'>"; echo "<fieldset>"; echo "<legend><b>Offer Information</b></legend>"; echo "Offer Name:<br>"; echo "<img src='images/spacer.gif' height='5' width='1' border='0'><br>"; echo "<input type='text' name='add_offername' class='membertext'><br>"; echo "<img src='images/spacer.gif' height='5' width='1' border='0'><br>"; echo "Offer Name (URL Rewrite):<br>"; echo "<img src='images/spacer.gif' height='5' width='1' border='0'><br>"; echo "<input type='text' name='add_urlrewrite' class='membertext'><br>"; echo "<img src='images/spacer.gif' height='5' width='1' border='0'><br>"; echo "Offer Description:<br>"; echo "<img src='images/spacer.gif' height='5' width='1' border='0'><br>"; echo "<input type='text' name='add_description' class='membertext'><br>"; echo "<img src='images/spacer.gif' height='5' width='1' border='0'><br>"; echo "URL (NO trailing slash):<br>"; echo "<img src='images/spacer.gif' height='5' width='1' border='0'><br>"; echo "<input type='text' name='add_url' class='membertext'><br>"; echo "<img src='images/spacer.gif' height='5' width='1' border='0'><br>"; echo "Point Worth:<br>"; echo "<img src='images/spacer.gif' height='5' width='1' border='0'><br>"; echo "<input type='text' name='add_points' class='membertext'><br>"; echo "<img src='images/spacer.gif' height='5' width='1' border='0'><br>"; echo "Level 1 or 2?<br>"; echo "<img src='images/spacer.gif' height='5' width='1' border='0'><br>"; echo "<input type='text' name='add_level' class='membertext'><br>"; echo "<img src='images/spacer.gif' height='10' width='1' border='0'><br>"; echo "<input type='submit' name='addnew' value=' Add New Offer ' class='button'>"; echo "</fieldset>"; echo "</form>"; echo "</td>"; echo "</tr>"; echo "</table>"; } else{ echo "You do not have permission to access the staff section. Your attempt has been logged and will be looked at by our administrators.<br>"; } ?> <? include("inc_footerm.php"); ?> Thanks a ton to anyone who can help me figure this out. It's getting me pretty angry, haha.. Link to comment https://forums.phpfreaks.com/topic/124754-solved-my-code-is-creating-two-mysql-entries-weird/ Share on other sites More sharing options...
peranha Posted September 18, 2008 Share Posted September 18, 2008 try changing this section of code $addnew1=$_GET["addnew"]; if($addnew1=='1'){ $add_offername=$_POST["add_offername"]; $add_urlrewrite=$_POST["add_urlrewrite"]; $add_description=$_POST["add_description"]; $add_url=$_POST["add_url"]; $add_points=$_POST["add_points"]; $add_level=$_POST["add_level"]; mysql_query("insert into offers (offerid,title,titlerewrite,description,url,pointworth,level,active)". "VALUES ('NULL','$add_offername','$add_urlrewrite','$add_description','$add_url','$add_points','$add_level','1')"); echo "<b>* The new offer has been added to the database.</b><br>"; echo "<br>"; } to if (isset($_POST['addnew'] { $addnew1=$_GET["addnew"]; if($addnew1=='1'){ $add_offername=$_POST["add_offername"]; $add_urlrewrite=$_POST["add_urlrewrite"]; $add_description=$_POST["add_description"]; $add_url=$_POST["add_url"]; $add_points=$_POST["add_points"]; $add_level=$_POST["add_level"]; mysql_query("insert into offers (offerid,title,titlerewrite,description,url,pointworth,level,active)". "VALUES ('NULL','$add_offername','$add_urlrewrite','$add_description','$add_url','$add_points','$add_level','1')"); echo "<b>* The new offer has been added to the database.</b><br>"; echo "<br>"; } } You never check to see if submit is pressed. Link to comment https://forums.phpfreaks.com/topic/124754-solved-my-code-is-creating-two-mysql-entries-weird/#findComment-644386 Share on other sites More sharing options...
genericnumber1 Posted September 18, 2008 Share Posted September 18, 2008 it's likely not to be obvious. Judging by the fact that the second insert is empty, it's possible that the page is someone being run, the query is going off, and then the page refreshes, and with no values submitted on this refresh, the query goes through empty. Of course this is just speculation but the facts support it (your get is going through, but not your post). I don't see anything in your code that would cause a refresh, so it may be in the files you didn't show us and you might want to look into them. Link to comment https://forums.phpfreaks.com/topic/124754-solved-my-code-is-creating-two-mysql-entries-weird/#findComment-644387 Share on other sites More sharing options...
3motions Posted September 18, 2008 Author Share Posted September 18, 2008 try changing this section of code $addnew1=$_GET["addnew"]; if($addnew1=='1'){ $add_offername=$_POST["add_offername"]; $add_urlrewrite=$_POST["add_urlrewrite"]; $add_description=$_POST["add_description"]; $add_url=$_POST["add_url"]; $add_points=$_POST["add_points"]; $add_level=$_POST["add_level"]; mysql_query("insert into offers (offerid,title,titlerewrite,description,url,pointworth,level,active)". "VALUES ('NULL','$add_offername','$add_urlrewrite','$add_description','$add_url','$add_points','$add_level','1')"); echo "<b>* The new offer has been added to the database.</b><br>"; echo "<br>"; } to if (isset($_POST['addnew'] { $addnew1=$_GET["addnew"]; if($addnew1=='1'){ $add_offername=$_POST["add_offername"]; $add_urlrewrite=$_POST["add_urlrewrite"]; $add_description=$_POST["add_description"]; $add_url=$_POST["add_url"]; $add_points=$_POST["add_points"]; $add_level=$_POST["add_level"]; mysql_query("insert into offers (offerid,title,titlerewrite,description,url,pointworth,level,active)". "VALUES ('NULL','$add_offername','$add_urlrewrite','$add_description','$add_url','$add_points','$add_level','1')"); echo "<b>* The new offer has been added to the database.</b><br>"; echo "<br>"; } } You never check to see if submit is pressed. Hey! That worked! I went ahead and removed the GET call that checks to see if the form was submitted through the URL and just went through seeing if the submit button had been clicked. Do you think it's okay to do it this way? Any downfalls? Thanks a TON for your help. Man ... I've been working on trying to fix this stupid thing for 3 days now and gone through re-writing the code MANY times and you solved it with simplicity. Thank you so much again. Link to comment https://forums.phpfreaks.com/topic/124754-solved-my-code-is-creating-two-mysql-entries-weird/#findComment-644402 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.