Jump to content

PHP doesnt recognize text in HTML FORM


quelle

Recommended Posts

Here's what i got, a part of poll script, actually this is for a user with some more priviliges... The problem I am facing is actually that my php code doesn't even recognize the text in HTML Form - the text boxes(at least thats what I think so). I made 2 errors - one if client didnt type the title of poll and one if there are lower than 2 answers. And the problem is Im getting those 2 problems all the time no mather what I type in textboxes


<?php 
}
function GetNewPollDetails(){
?>
  <h1>Nova anketa</h1>
<form name="frmAddPoll" action="managepoll.php?method=AddFinal" method="post">
<br />
  
Pitanje Ankete:<input type="text" name="$question" /> 
<br />
Odogovor 1:<input type="text" name="answer1" />
<br />
Odogovor 2:<input type="text" name="answer2" />
<br />
Odogovor 3:<input type="text" name="answer3" />
<br />
Odogovor 4:<input type="text" name="answer4" />
<br />
Odogovor 5:<input type="text" name="answer5" />
<br />
<input type="submit" value="Napravi" name="napravi" />
</form>
<?php
						}

function AddPoll(){

global $question;

global $answer1;

global $answer2;

global $answer3;

global $answer4;

global $answer5;

$numAnswers = 0;

$err = "";



if($answer1 != "")

{ $numAnswers++; }

if($answer2 != "")

{ $numAnswers++; }

if($answer3 != "")

{ $numAnswers++; }

if($answer4 != "")

{ $numAnswers++; }

if($answer5 != "")

{ $numAnswers++; }



if($question == "")

$err .= "<li>You didn't enter a title</li>";


if($numAnswers < 2)

$err .= "<li>You must enter at least two answer choices</li>";


if($err != "")

{

?>

<h1>Incomplete Fields</h1>

You didn't complete all of the details for this poll.

Take a look at the errors below and click the link

below to go back and correct them:

<ul>

<?php echo $err; ?>

</ul>

<a href="javascript:history.go(-1)">Go Back</a>

<?php

return;

}

include("dbvars.php");

@$svrConn = mysql_connect($host, $user, $pw) or die("Couldn't connect to the database server");

@$dbConn = mysql_select_db("websitenforum", $svrConn) or die("Couldn't connect to the database");


$strQuery = "INSERT INTO pollQuestions VALUES(";

$strQuery .= "0, '$question', '$answer1', '$answer2', '$answer3', '$answer4', '$answer5')";

if(mysql_query($strQuery)) {

echo "You made it, yes!";
}
}
?>

Link to comment
Share on other sites

Since you have this line outside of php and just html, you must have the start and stop for php code.

so this

Pitanje Ankete:<input type="text" name="$question" /> 

 

to this

Pitanje Ankete:<input type="text" name="<?php echo $question;?>" /> 

 

If you echoed the html code and needed the variable, no need to have the start and stops, but do need to have them wrapped in the correct quotes at times.

Link to comment
Share on other sites

well doing it on ur way I actually define nothing ... I tried it on this way

$question = $_POST['question'];
$answer1 = $_POST['answer1'];
$answer2 = $_POST['answer2'];
$answer3 = $_POST['answer3'];
$answer4 = $_POST['answer4'];
$answer5 = $_POST['answer5'];

But my whole script fucked up after I changed what u said, dunno what's the problem gotta go sleep now ill try tommorow

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.