Hello All. I have a problem with a form that I am trying to create. What happens is: I have a person enter a UserName and select some values using radio buttons. They submit the form, and the next page is intended to echo their information back. I was able to get the first page to write values to the database, but when I add the second page, the values do not write to the database and I get an error.
Here is a pared-down version of the code, with comments:
<!-- FIRST PAGE -->
<html>
<head>
<?php
include("db.php "); //CONNECTS TO DATABASE
?>
</head>
<body>
<form name="form1" method="post" action="myinfor mation.php">
<p>Name: <input name="UserName" type = "text"></p>
<?php
$_SESSION['$UserName'] = $UserName;
?>
<p><input name="v1" value="Value1" type="hidden">
<input name="Input1" onclick="g1.val ue = v1.value" type="radio">Va lue1</p>
<!-- IF SELECTED, THIS PUTS THE VALUE ASSOCIATED WITH THE RADIO BUTTON "V1" INTO THE TEXT BOX "G1", WHICH I WANT TO PUT IN THE MYSQL DATABASE -->
</form>
<?php dbConnect('my_d atabase');
if (isset($_POST['submitok'])) {
$Submit_sql = "INSERT INTO Info (UserName, G1)
VALUES ('$UserName', '$g1')
mysql_query($Su bmit_sql) or die(mysql_error ());
} ?>
</body>
</html>
<!-- IF I HAVE NOTHING IN THE NEXT PAGE, myinformation.p hp, THE VALUES WILL WRITE TO THE DATABASE. HOWEVER, I WANT TO ECHO BACK THE VALUES FOR THE USER SO THEY CAN PRINT THEM. -->
<!--SECOND PAGE -->
<html>
<head>
<?php
include("db.php "); //CONNECTS TO DATABASE
?>
</head>
<body>
<h1><?php echo $UserName;
$_SESSION['$UserName'] = $UserName;?>'s Information</h1>
<p>
<?php
dbConnect('my_d atabase');
$sql_g1 = "SELECT G1 FROM Info WHERE UserName = '$UserName'";
$result_g1 = mysql_query($sq l_g1);
$g1 = mysql_result($r esult_g1, 0);
echo $g1;
?>
</p>
</body>
</html>
<!-- THE INFORMATION DOES NOT WRITE TO THE DATABASE WHEN I HAVE THIS IN MY SECOND PAGE AND I GET THE ERROR "Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 5 in /home/theweekl/public_html/NCAA2007/myinformation.p hp on line xxx", BECAUSE THE DATA IS NOT THERE -->
Any help is greatly appreciated!
Cheers,
Seth
Here is a pared-down version of the code, with comments:
<!-- FIRST PAGE -->
<html>
<head>
<?php
include("db.php "); //CONNECTS TO DATABASE
?>
</head>
<body>
<form name="form1" method="post" action="myinfor mation.php">
<p>Name: <input name="UserName" type = "text"></p>
<?php
$_SESSION['$UserName'] = $UserName;
?>
<p><input name="v1" value="Value1" type="hidden">
<input name="Input1" onclick="g1.val ue = v1.value" type="radio">Va lue1</p>
<!-- IF SELECTED, THIS PUTS THE VALUE ASSOCIATED WITH THE RADIO BUTTON "V1" INTO THE TEXT BOX "G1", WHICH I WANT TO PUT IN THE MYSQL DATABASE -->
</form>
<?php dbConnect('my_d atabase');
if (isset($_POST['submitok'])) {
$Submit_sql = "INSERT INTO Info (UserName, G1)
VALUES ('$UserName', '$g1')
mysql_query($Su bmit_sql) or die(mysql_error ());
} ?>
</body>
</html>
<!-- IF I HAVE NOTHING IN THE NEXT PAGE, myinformation.p hp, THE VALUES WILL WRITE TO THE DATABASE. HOWEVER, I WANT TO ECHO BACK THE VALUES FOR THE USER SO THEY CAN PRINT THEM. -->
<!--SECOND PAGE -->
<html>
<head>
<?php
include("db.php "); //CONNECTS TO DATABASE
?>
</head>
<body>
<h1><?php echo $UserName;
$_SESSION['$UserName'] = $UserName;?>'s Information</h1>
<p>
<?php
dbConnect('my_d atabase');
$sql_g1 = "SELECT G1 FROM Info WHERE UserName = '$UserName'";
$result_g1 = mysql_query($sq l_g1);
$g1 = mysql_result($r esult_g1, 0);
echo $g1;
?>
</p>
</body>
</html>
<!-- THE INFORMATION DOES NOT WRITE TO THE DATABASE WHEN I HAVE THIS IN MY SECOND PAGE AND I GET THE ERROR "Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 5 in /home/theweekl/public_html/NCAA2007/myinformation.p hp on line xxx", BECAUSE THE DATA IS NOT THERE -->
Any help is greatly appreciated!
Cheers,
Seth
Comment