<input type="hidden" 정보가 다음 페이지로 전달 안되는 문제
본문
<body>
$username = $_GET["username"];
/*
$bio= $_GET["bio"];
$website= $_GET["website"];
$color= $_GET["color"];
$major= $_GET["major"];
*/
$bio = $website = $color = $major = "";
$next= "";
include 'db_connect.php'; // db connect
$result = mysql_query("SELECT * FROM sung2 WHERE Username = '".$_GET['username']."'");
if (!$result)
{
die('Invalid query');
}
$row = mysql_fetch_assoc($result);
?>
<h1>| TITLE |</h1>
<div class="outer">
<div class="wrap">
<div class="head">
<h2> Hello <?php echo $row['Username'];?>!</h2>
<h3><i> WELCOME!</i></h3>
<br /><br />
<!--<a href="index.php" >SIGN UP</a>-->
</div>
<div class="form">
<form method="GET" action="p4.php" >
<label>Edit <?php echo '<strong>'.$row['Username'].'</strong>';?>'s Profile</label><br /><br />
<label>Password: **************</label><br/>
<label>Email: <?php echo $row['Email'];?></label><br/>
<label>Gender: <?php echo $row['Gender'];?></label><br/>
<label>Zipcode: <?php echo $row['Zipcode'];?></label><br/><br/>
<!--
<label for="email">Email: </label><br/>
<input type="email" name="email" value="<?//php echo $row['Email'];?>"></input><br />
<label for="zip">Zipcode: </label><br />
<input name="zip" type="text" value="<?//php echo $row['Zipcode'];?>"></input><br/>
-->
<label>Website</label><br/>
<input type="url" name="website" value="http://" /><br />
<label>Favority Color</label><br/>
<input type="text" name="color" value="" /><br />
<label>Major</label><br/>
<input type="text" name="major" value="" /><br />
<label>Bio</label><br/>
<input type="text" name="bio" value="" /><br /><br />
<!-- send account info -->
<input type="hidden" name="username" value="<?php echo $_GET["username"]; ?>" />
<input type="hidden" name="website" value="<?php echo $_GET["website"]; ?>" />
<input type="hidden" name="color" value="<?php echo $_GET["color"]; ?>" />
<input type="hidden" name="major" value="<?php echo $_GET["major"]; ?>" />
<input type="hidden" name="bio" value="<?php echo $_GET["bio"]; ?>" /> <!-- 77 라인 -->
<input type="submit" name="submit" value="Submit!" />
</form>
</div>
</div>
</div>
</body>
위의 코드를 p4.php 로 전송하는데 위의 입력받은 $bio, $website, $color, $major 의 히든코드를 함께 보내져야 하는데 p4.php 에서 아래의 에러 메세지가 뜹니다.
Bio: Notice: Undefined index: bio in /home/students/p3.php on line 77
Website: Notice: Undefined index: website in /home/students
Color: Notice: Undefined index: color in /home/students
Major: Notice: Undefined index: major in /home/students
아래는 p4.php 파일 코드입니다.
<body>
<h1>| CONNECTAGRAM |</h1>
<div class="outer">
<div class="wrap">
<?php
$username = $_GET["username"];
$bio = $_GET["bio"];
$website = $_GET["website"];
$major = $_GET["major"];
$color = $_GET["color"];
/*
echo $_GET["username"];
echo $_GET["bio"];
echo $_GET["website"];
echo $_GET["major"];
*/
// connect DB
include 'db_connect.php'; // include localhost, username, password, database
mysql_query("UPDATE `sung2` SET `Bio`='$bio', `Website_URL`='$website', `Major`='$major', `Color`='$color' WHERE `Username` = '".$_GET['username']."'");
$result1 = mysql_query("SELECT * FROM sung2 WHERE Username = '".$_GET['username']."'");
if (!$result1)
{
die('Invalid query');
}
$row = mysql_fetch_assoc($result1);
?>
<div class="head">
<h2> Hello <?php echo $row['Username'];?>!</h2>
<h3><i> WELCOME!</i></h3>
<br /><br />
<a href="index.php">sign-out</a>
</div>
<div class="profile">
<p> <strong><?php echo $row['Username'];?>'s Profile</strong></p>
<p> Password: *********************</p>
<p> Email: <?php echo $row['Email'];?></p>
<p> Gender: <?php echo $row['Gender'];?></p>
<p> Zipcode: <?php echo $row['Zipcode'];?></p>
<p> Bio: <?php echo $row['Bio'];?></p>
<p> Website: <?php echo $row['Website_URL'];?></p>
<p> Color: <?php echo $row['Color'];?></p>
<p> Major: <?php echo $row['Major'];?></p>
</div>
</div>
</div>
</body>
!-->!-->
답변 4
major
이 객체요.
hidden도 있지만 text로도 있어요
배열이라는 거죠
print_r( $_GET["major
"] );
이것을 실행 해보세요
배열을 첨자가 있어야 해요
p4.php 죠...
그쪽으로 데이터를 전달하는 것잖아요
print_r은 배열에 값을 확인 하는 함수에요
major가 배열이에요.
배열인데.. 일반 변수 같이 사용하니 에러가 나는 거에요
print_r을 이용하여 배열에 담김 값을 확인 하고 그것에 맞춰서 변수 처리 하시면 되요
Undefined index
에러가 이렇게 나오잖아요
해결했습니다.
첫번째 파일 p3.php 의 하단에아래 코드 삭제하니 잘됩니다. 보네는 입력정보가 없는데 어떻게 된거죠?
<!-- send account info -->
<input type="hidden" name="username" value="<?php echo $_GET['username']; ?>" />
<input type="hidden" name="website" value="<?php echo $_GET['website']; ?>" />
<input type="hidden" name="color" value="<?php echo $_GET['color']; ?>" />
<input type="hidden" name="major" value="<?php echo $_GET['major']; ?>" />
<input type="hidden" name="bio" value="<?php echo $_GET['bio']; ?>" />
답변을 작성하시기 전에 로그인 해주세요.