Jump to content

[SOLVED] What am I not seeing? - Form trouble.


surochek

Recommended Posts

The form works. Almost. The first field (Character="name") is the only one that won't accept the value and won't insert the data into the db. What is it that I'm missing?

 

The main page:

<?php
session_start();
include("connect.php");
?> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Twenty Questions</title>
<link rel="stylesheet" type="text/css" href="builder2.css" media="screen" />
<link rel="stylesheet" type="text/css" href="printbuilder.css" media="print" />
</head>
<body>
<div id="wrapper">
<div class="header">
<span class="title">The Ultimate Character Builder</span><br />
<h3>Part 2<br />
Twenty Questions</h3>
</div>
<br />
<br />
<div class="left">

<?php 
include_once("left.inc");
?>

</div>
<div class="content">

<?php  
$user=$_SESSION['username'];

if (isset($_POST['submit'])) { 

    $sql = "SELECT * FROM twentyquestions WHERE username = '$user'";
    $query = mysql_query($sql) or die (mysql_error(). " with query : ". $sql."<br>");
	$num=mysql_num_rows($query);

      if ($num<1){

      $user = $_SESSION['username']; 
	$name = $_POST['character_name'];
  $q1a = $_POST['1a'];
	$q1b = $_POST['1b'];
	$q2a = $_POST['2a'];
	$q2b = $_POST['2b'];

      $query = "INSERT INTO twentyquestions (username, character_name, 1a, 1b, 2a, 2b, ) 
VALUES ('$user','$name', '$q1a', '$q1b', '$q2a', '$q2b')";

$update=mysql_query($query) or die("<br>Error: ". mysql_error(). " with query : ". $query);

echo "<span style='color:#330099;'><h3 align='center'>Information saved!</h3></span>";
    }
    else{

	$user = $_SESSION['username']; 
	$name = $_POST['character_name'];
	$q1a = $_POST['1a'];
	$q1b = $_POST['1b'];
	$q2a = $_POST['2a'];
	$q2b = $_POST['2b'];  

       $query = "UPDATE twentyquestions SET character_name='$name', 1a='$q1a', 1b='$q1b', 
2a='$q2a', 2b='$q2b' WHERE username = '$user'";


$update=mysql_query($query) or die("<br>Error: ". mysql_error(). " with query : ". $query); 

echo "<span style='color:#330099;'><h3 align='center'>Form updaded successfully.</h3></span>"; 

$query = "SELECT * FROM twentyquestions WHERE username='$user'";
$result= mysql_query($query);
$info=mysql_fetch_array($result) or die (mysql_error());

	$name = $info['character_name'];
	$q1a = $info['1a'];
	$q1b = $info['1b'];
	$q2a = $info['2a'];
	$q2b = $info['2b'];
   
}
    }

$sql = "SELECT * FROM twentyquestions WHERE username = '$user'";
    $query = mysql_query($sql) or die (mysql_error(). " with query : ". $sql."<br>");
	$num=mysql_num_rows($query);

      if ($num!==0){

      $query = "SELECT * FROM twentyquestions WHERE username='$user'";
$result= mysql_query($query);
$info=mysql_fetch_array($result) or die (mysql_error());

	$name = $info['character_name'];
	$q1a = $info['1a'];
	$q1b = $info['1b'];
	$q2a = $info['2a'];
	$q2b = $info['2b'];

echo "<form action=".$_SERVER['SCRIPT_NAME']." method='post'>";
include("basicquestions.php");
}

else {
echo "<form action=".$_SERVER['SCRIPT_NAME']." method='post'>";
include("basicquestions.php");
}

?> 

</table>
</form>
</div>
<br />
<br />
<br />
</div>
</body>
</html>

 

The form itself:

 

<table border="0" cellpadding="3" cellspacing="3" summary="Twenty Questions" align="center">

<tr class="hide"><td colspan="4"><br />
<br />
<br />
<br />
</td></tr>

<tr><td colspan="4" align="center"><h3>List of Conflicts</h3></td></tr>

<tr><td> </td><td align="right"><b>Character:</b></td><td>
<textarea rows="1" cols="25" name="character_name"><?php echo $name?></textarea></td><td> </td></tr>

<tr><td></td><td><b>External</b></td><td><b>Internal</b></td><td></td></tr>

<tr><td>1</td><td>
<textarea rows="2" cols="25" name="1a"><?php echo $q1a?></textarea></td><td>
<textarea rows="2" cols="25" name="1b"><?php echo $q1b?></textarea></td><td></td></tr>

<tr><td>2</td><td>
<textarea rows="2" cols="25" name="2a"><?php echo $q2a?></textarea></td><td>
<textarea rows="2" cols="25" name="2b"><?php echo $q2b?></textarea></td><td></td></tr>

<tr><td> </td><td colspan="3"><center>
<?php 
    echo "<input type='submit' name='submit'>";
?>
</center></td></tr> 

 

...Ready to feel duh...

Link to comment
Share on other sites

That's the thing. I'm not getting errors. I can post from all the other fields and the data gets into the db, except for the first field ($name='character_name').

 

I can't see what's wrong, either. I'm not getting any mysql errors.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.