a1amattyj Posted May 12, 2008 Share Posted May 12, 2008 Hello, For some reason, my code will submit the data i input, but it will also input a second field for no reason with the ID auto increments +1 from the real query. if($_GET['act'] == 'add'){ $name = $_POST['name']; $type = $_POST['type']; $email = $_POST['email']; $q = "INSERT INTO `{$db_prfix}help` ( `name` , `type` , `email` ) VALUES ('$name', '$type', '$email')"; $rs = mysql_query($q) or die(mysql_error()); echo "<h1>Add Help Staff</h1>"; echo "Added '$name' to the help system."; echo "<br /><br />"; echo '<form action="support.php" method="post"><input type="submit" value="Go Back"></form>'; } From phpmyadmin.. INSERT INTO `help` VALUES(25, '', '', ''); INSERT INTO `help` VALUES(24, 'jkjhk', 'hjgh', 'gjjhj'); INSERT INTO `help` VALUES(23, '', '', ''); INSERT INTO `help` VALUES(22, 'admin', 'user', '[email protected] '); Ta Link to comment https://forums.phpfreaks.com/topic/105259-double-inseting/ Share on other sites More sharing options...
jaymc Posted May 12, 2008 Share Posted May 12, 2008 Seems pretty clean what you have posted What are the conditions before if($_GET['act'] == 'add'){ As it looks like it is being called twice Maybe best to post all the php in this instance Make sure your not calling $rs anywhere in your script, not sure why you have assigned the mysql_query() to a var anyway, could be the root issue Link to comment https://forums.phpfreaks.com/topic/105259-double-inseting/#findComment-538933 Share on other sites More sharing options...
a1amattyj Posted May 12, 2008 Author Share Posted May 12, 2008 Whole code: <? require('header.php'); if(!$_GET){ ?> <h1>Support Team</h1> This is a list of the support team which are listed on your home page under the support section. You may delete or add new support members here. You can view the support team on your main page <a href="../support.php">here</a>. <br /><br /> <table width="98%" border="0" cellspacing="1" cellpadding="1"> <tr> <td><b>Name</b></td> <td><b>Type</b></td> <td><b>Email</b></td> <td><b>Delete</b></td> </tr> <? $query = "select * from {$db_prfix}help"; $result = mysql_query($query); if (mysql_num_rows($result) !=0) { while($row = mysql_fetch_array($result)) { extract($row); echo "<tr> <td><a href=\"profile.php?id=$name\">$name</a></td> <td>$type</td> <td>$email</td>"; echo '<td><form action="support.php?act=del&name='.$name.'" method="post"><input type="submit" value="Delete"></form></td>'; echo " </tr>"; } } ?> <form action="support.php?act=add" method="post"> <tr> <td><input type='text' name='name'></td> <td><input type='text' name='type'></td> <td><input type='text' name='email'</td> <td><input type="submit" name="Submit" value="Add"></td> </tr> </table> <br> This will not make a user be able to enter the Admin Panel it will just add their name to the staff page list which can be found <a href="../support.php">here</a>. <? } if($_GET['act'] == 'del'){ $supportname = $_REQUEST['name']; ?> <script language=javascript1.1> var answer = confirm("Confirm Delete") if (answer){ } else{ alert("NOT DELETED!") window.location = "support.php"; } </script> <? echo "<h1>Delete Staff</h1>"; echo "Deleted '$supportname' from the help system."; echo "<br /><br />"; echo '<form action="support.php" method="post"><input type="submit" value="Go Back"></form>'; $sql = "DELETE FROM `{$db_prfix}help` WHERE name = '$supportname'"; $result = mysql_query($sql) or die(mysql_error()); } if($_GET['act'] == 'add'){ $name = $_POST['name']; $type = $_POST['type']; $email = $_POST['email']; $q = "INSERT INTO `{$db_prfix}help` ( `name` , `type` , `email` ) VALUES ('$name', '$type', '$email')"; $rs = mysql_query($q) or die(mysql_error()); echo "<h1>Add Help Staff</h1>"; echo "Added '$name' to the help system."; echo "<br /><br />"; echo '<form action="support.php" method="post"><input type="submit" value="Go Back"></form>'; } require("footer.php"); ?> Thanks! Link to comment https://forums.phpfreaks.com/topic/105259-double-inseting/#findComment-538936 Share on other sites More sharing options...
beansandsausages Posted May 12, 2008 Share Posted May 12, 2008 try this : in your querry $q = "INSERT INTO `{$db_prfix}help` ( `name` , `type` , `email` ) VALUES ('$name', '$type', '$email')"; take the space out before `name` Link to comment https://forums.phpfreaks.com/topic/105259-double-inseting/#findComment-538943 Share on other sites More sharing options...
a1amattyj Posted May 12, 2008 Author Share Posted May 12, 2008 try this : in your querry $q = "INSERT INTO `{$db_prfix}help` ( `name` , `type` , `email` ) VALUES ('$name', '$type', '$email')"; take the space out before `name` Still does it. Thanks! Link to comment https://forums.phpfreaks.com/topic/105259-double-inseting/#findComment-538945 Share on other sites More sharing options...
beansandsausages Posted May 12, 2008 Share Posted May 12, 2008 you tried taking the space after email as well? Link to comment https://forums.phpfreaks.com/topic/105259-double-inseting/#findComment-538949 Share on other sites More sharing options...
a1amattyj Posted May 12, 2008 Author Share Posted May 12, 2008 you tried taking the space after email as well? Yeah : if($_GET['act'] == 'add'){ $name2 = $_POST['name']; $type2 = $_POST['type']; $email2 = $_POST['email']; $q = "INSERT INTO `{$db_prfix}help` (`name`,`type`,`email`) VALUES ('$name2','$type2','$email2')"; $rs = mysql_query($q) or die(mysql_error()); echo "<h1>Add Help Staff</h1>"; echo "Added '$name2' to the help system."; echo "<br /><br />"; echo '<form action="support.php" method="post"><input type="submit" value="Go Back"></form>'; } I really have no idea why. Link to comment https://forums.phpfreaks.com/topic/105259-double-inseting/#findComment-538953 Share on other sites More sharing options...
beansandsausages Posted May 12, 2008 Share Posted May 12, 2008 okay giz 10min ill take a look on my localhost. Link to comment https://forums.phpfreaks.com/topic/105259-double-inseting/#findComment-538955 Share on other sites More sharing options...
beansandsausages Posted May 12, 2008 Share Posted May 12, 2008 try this : if($_GET['act'] == 'add'){ $name2 = $_POST['name']; $type2 = $_POST['type']; $email2 = $_POST['email']; mysql_query("INSERT INTO `{$db_prifix}help` (`name2`,`type2`,`email2`) VALUES ('{$name}','{$type2}', '{$email2}') ") or die(mysql_error()); echo "<h1>Add Help Staff</h1>"; echo "Added '$name2' to the help system."; echo "<br /><br />"; echo '<form action="support.php" method="post"><input type="submit" value="Go Back"></form>'; } the values mayneed changing Link to comment https://forums.phpfreaks.com/topic/105259-double-inseting/#findComment-538958 Share on other sites More sharing options...
a1amattyj Posted May 12, 2008 Author Share Posted May 12, 2008 mysql_query("INSERT INTO `{$db_prifix}help` (`name`,`type`,`email`) VALUES ('{$name2}','{$type2}', '{$email2}') ") or die(mysql_error()); BTW thanks for your time! but nope, it still does it Link to comment https://forums.phpfreaks.com/topic/105259-double-inseting/#findComment-538960 Share on other sites More sharing options...
a1amattyj Posted May 12, 2008 Author Share Posted May 12, 2008 Fixed: $name = $_POST['name']; $type = $_POST['type']; $email = $_POST['email']; if ($name != ""){ ?> <? $q = "INSERT INTO `{$db_prfix}help` ( `name` , `type` , `email` ) VALUES ( '$name', '$type', '$email')"; $rs = mysql_query($q) or die ("Could not execute query : $q." . mysql_error()); if ($rs){ echo "Support Added"; } } Thanks Link to comment https://forums.phpfreaks.com/topic/105259-double-inseting/#findComment-538963 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.