Jump to content

Recommended Posts

Ok so i have a form that when processed has action ="". Therefore it is coming back to the same page.

 

The code:

<?php

 

$user=$_POST['awarduser'];

$comment=$_POST['awardcomment'];

$type=$_POST['awardtype'];

 

 

$query="INSERT INTO ".TBL_AWARDS." VALUES (NULL, '$type','$user', now(), '$comment')";

 

if(!$comment || strlen($comment = trim($comment)) == 0)

    echo "Comment not entered";

else if(!$comment || strlen($comment = trim($comment)) < 10)

    echo "Comment too short, must be 10 characters at least";

else if (!$comment || strlen($comment = trim($comment)) > 10){

    echo "".$_SESSION['username'].", you have added an award to ".$_POST['awarduser']."'s Profile. ";

  mysql_query($query);}

 

?>

 

 

<h4>Award player</h4>

<form action="" method="POST">

Type:<select name="awardtype">

<option value="league1">League winner</option>

<option value="league2">League runner up</option>

<option value="league3">Leauge 3rd/play off winner</option>

</select>

Award: <select name="awarduser">

<?php

    $res=mysql_query("SELECT username FROM ".TBL_USERS."") or die(mysql_error());

  while($row=mysql_fetch_assoc($res)){

    $username=htmlspecialchars($row['username']);

    echo "<option value=\"$username\">$username</option>";

  }

?>

</select>

Comment:<textarea name="awardcomment" rows="2" cols="30" ></textarea>

<div align="right"><input type="submit" name="submit" value="Award Player"></div>

</form>

 

The problem is, the comment not entered comes up as soon as i load the page, as there is no comment entered. Whats the best way around this that enables the form and processing to be done on the same page? thanks

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.