sql 쿼리, for문~~

· 2013-02-19 (화) 13:07:12 · 5226 · 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' ";
2013-02-19 (화) 14:16:24
답변감사드립니다.^^
하지만, 수정후, 역시나 되지 않네요... ㅠㅠ
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 질문답변

66,531건

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

+
제목 글쓴이 날짜 조회
13-02-19 조회 802
13-02-19 조회 1,037
13-02-19 조회 596
13-02-19 조회 1,107
13-02-19 조회 1,049
13-02-19 조회 1,351
13-02-19 조회 1,752
13-02-19 조회 1,290
13-02-19 조회 873
13-02-19 조회 5,227
13-02-19 조회 1,049
13-02-19 조회 625
13-02-19 조회 1,229
13-02-19 조회 1,025
13-02-19 조회 1,051
13-02-19 조회 1,097
13-02-19 조회 1,101
13-02-19 조회 2,356
13-02-19 조회 3,409
13-02-18 조회 2,523