Jump to content

haveing a problem with mysql_query("insert


shortj75

Recommended Posts


hey everyone i am haveing a problem inserting into my db my code works it inserts the input to the db but when it does it inserts it 2-3 times when i hit the submit button i have benn trying to figure this out for a white now and i cant figure it out and was wondering if any one can help it would be great here it the code and thanks in advance


if($_POST['submit']==true){

$getforums="SELECT * from forum";
$getforums2=mysql_query($getforums) or die(mysql_error());
while($getforums3=mysql_fetch_array($getforums2))
{
$cat=$_POST['cid'];
$for=$_POST['fid'];
$user=$_SESSION['user'];
$date=date("n/j/y g:i:s A");
$title=$_POST['title'];
$subject=$_POST['subject'];
$post=$_POST['post'];
$sql="INSERT into posted(forum,cat,user,date,title,subject,post)values('$for', '$cat', '$user', '$date', '$title', '$subject', '$post')";
mysql_query($sql) or die ("Could not Post");
mysql_query("UPDATE register set post=post ++1 where user='$_SESSION[user]'") or die("could not update posts");
}

print "<center><table cellpaddin=0 cellspacing=0 width=50% class=td><th class=th>$ID<TR><TD classspecialtable>";
echo "Post Submitted <a href=viewcat.php?cid=$cat&fid=$for>back to forum</a>";
echo "</center></th></tr></td></table></center>";
}else{
$ID=$_GET['cid'];
$for=$_GET['fid'];
print "<center><table cellpaddin=0 cellspacing=0 width=50% class=td><th class=th>$ID<TR><TD>";
if (isset($_SESSION['user']))
{
$user = $_SESSION['user'];
$getuser = "SELECT * from register where user='$user'";
$getuser2 = mysql_query($getuser) or die("Could not get user info");
$getuser3 = mysql_fetch_array($getuser2);

print "<table cellpadding=0 cellspacing=0 width=100%><TD class=specialtable>
<form method=post action=post.php>
<input type=hidden name=cid value=$ID>
<input type=hidden name=fid value=$for>
Title:&nbsp<input type=text name=title><BR>
Subject:&nbsp<input type=text name=subject><BR>
Post:<BR>
<textarea name=post cols=60 rows=15></textarea><br>
<input type=submit name=submit value=Post style=border-style:solid;border-color:black;border-width:1px;bgcolor:silver;color:black;>
</form></th></td></table>";
print "</th></td></table>";
}}
Link to comment
Share on other sites

this is the part of the code that is inserting twice

[code]$cat=$_POST['cid'];
$for=$_POST['fid'];
$user=$_SESSION['user'];
$date=date("n/j/y g:i:s A");
$title=$_POST['title'];
$subject=$_POST['subject'];
$post=$_POST['post'];
$sql="INSERT into posted(forum,cat,user,date,title,subject,post)values('$for', '$cat', '$user', '$date', '$title', '$subject', '$post')";
mysql_query($sql) or die ("Could not Post");[/code]
Link to comment
Share on other sites

[!--quoteo(post=355262:date=Mar 15 2006, 02:00 AM:name=shortj75)--][div class=\'quotetop\']QUOTE(shortj75 @ Mar 15 2006, 02:00 AM) [snapback]355262[/snapback][/div][div class=\'quotemain\'][!--quotec--]
this is the part of the code that is inserting twice

[code]$cat=$_POST['cid'];
$for=$_POST['fid'];
$user=$_SESSION['user'];
$date=date("n/j/y g:i:s A");
$title=$_POST['title'];
$subject=$_POST['subject'];
$post=$_POST['post'];
$sql="INSERT into posted(forum,cat,user,date,title,subject,post)values('$for', '$cat', '$user', '$date', '$title', '$subject', '$post')";
mysql_query($sql) or die ("Could not Post");[/code]
[/quote]


Your insert takes place inside a while loop which iterates through each row returned in "SELECT * from forum"
Link to comment
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.