Jump to content

Recommended Posts

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', 'matt@easyforumz.com ');

 

 

Ta

Link to comment
https://forums.phpfreaks.com/topic/105259-double-inseting/
Share on other sites

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

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

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.