Jump to content

Why can't insert but can update, Thx a lot


Shawn

Recommended Posts

Red highlight item.$query=mysql_query("select * from member");while (list($mno,$id,$pw,$nick,$team)=mysql_fetch_row($query)){ $mgoal=$_POST["goal$mno"]; $massist=$_POST["assist$mno"]; $attend=$_POST["attend$mno"]; if ($attend!="") { $attend="checked"; } $check=mysql_query("select * from record where matchid='$no' and mno='$mno'"); $row=mysql_num_rows($check); if ($row==0) $record="insert record (matchid,mno,mgoal,massist,attend) values ('$no','$mno','$mgoal','$massist','$attend')"; mysql_query($record); echo "a"; } else { $update="update record set mgoal='$mgoal',massist='$massist',attend='$attend' where matchid='$no' and mno='$mno'"; mysql_query($update); echo $no; }}

Link to comment
Share on other sites

Guest gahzinia
if ($row==0)  $record="insert record (matchid,mno,mgoal,massist,attend)   values ('$no','$mno','$mgoal','$massist','$attend')";  mysql_query($record);
Shouldn't it be$record = "insert into record (matchid,mno,mgoal,massist,attend) values ('$no','$mno','$mgoal','$massist','$attend')";?Also, what is the error that you're getting? Just taking a quick look at the code, why do ou have the top 2/3 all in the while loop? Indenting the code would help a lot in tracing it.
Link to comment
Share on other sites

Sorry for my late reply,I have a input page before. below is my script. THanks :)$list=mysql_query("select * from member");while (list($mno,$id,$pw,$nick,$team)=mysql_fetch_row($list)){ $check=mysql_query("select * from record where matchid='$no' and mno='$mno'"); list($rno,$matchid,$mno,$mgoal,$massist,$attend)=mysql_fetch_row($check); $mgoal=$mgoal; $massist=$massist; echo "<tr><td>$nick"; echo "<td><input type=text name=goal$mno size=1 maxlength=2 value=$mgoal>"; echo "<td><input type=text name=assist$mno size=1 maxlength=2 value=$massist>"; echo "<td><input type=checkbox name=attend$mno $attend>";}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...