sql 쿼리, for문~~

· 13년 전 · 5149 · 3
for문을 통해, 테이블 필드 안에, 생성 하려고 그러는데, 데이터가 생성 되지 않네요... ㅠㅠ
지금 테이블 및 필드는 생성되어있습니다.~~

소스는 아래와 같습니다.

<?
include_once("./_common.php");

if($mode=="create")
{

for($i = 100000; $i <= 999999; $i++) {
$sql = "insert into non_mb (bk_num) values ($i)";
}
$result = mysql_query($sql);


if(!$result)
{
echo "<script>
window.alert('생성실패입니다. 재확인바랍니다');
history.go(-1);
</script>";
exit;

}

echo "<script>
window.alert('데이터가 생성되었습니다.');
</script>";
echo "<meta http-equiv='refresh' content='0;url={$g4[path]}/'>";


exit;


}//mode=create의 끝


?>
<html>
<head>
<style>
body,table{font-size:12px;font-family:굴림;}
</style>
</head>
<body>
<center>
<table border=0 cellpadding=0 cellspacing=1 bgcolor=#cccccc width=500>
<form name=form1 method=post action="<?=$PHP_SELF?>">
<tr height=25 bgcolor=#f2f2f2>
<td align=center ><b>popup 테이블 생성하기</b></td>
</tr>
<tr height=50 bgcolor=#ffffff>
<td align=center >생성.</td>
</tr>
<tr height=25 bgcolor=#f2f2f2>
<td align=center >
<input type=hidden name="mode" value="create">
<input type=submit value="테이블 생성"></td>
</tr>
</form>
</table>
</center>


</body>
</html>
|

댓글 3개

$sql = "insert into non_mb (bk_num) values ($i)";

다음과 같이 수정.

$sql = "insert into non_mb set bk_num = '$i' ";
답변감사드립니다.^^
하지만, 수정후, 역시나 되지 않네요... ㅠㅠ
for($i = 100000; $i <= 999999; $i++) {
$sql = "insert into non_mb (bk_num) values ($i)";
}
$result = mysql_query($sql); <--- for문 내에서 쿼리를 실행해야 디비에 저장 되죠
for문이 끝나고 쿼리문을 한번만 실행하고 있잖아요
} 안으로 옮기세요
그리고 그누보드에서는 mysql_query($sql) 대신 그냥 sql_query($sql) 하면 됩니다
댓글을 작성하시려면 로그인이 필요합니다.

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기 기존 게시물은 열람만 가능합니다.

+
제목 글쓴이 날짜 조회
13년 전 조회 745
13년 전 조회 975
13년 전 조회 528
13년 전 조회 1,035
13년 전 조회 986
13년 전 조회 1,274
13년 전 조회 1,684
13년 전 조회 1,215
13년 전 조회 791
13년 전 조회 5,150
13년 전 조회 966
13년 전 조회 550
13년 전 조회 1,152
13년 전 조회 952
13년 전 조회 974
13년 전 조회 1,005
13년 전 조회 1,026
13년 전 조회 2,294
13년 전 조회 3,336
13년 전 조회 2,450