-
Submit Form
hey all,
sorry for the newb question but my host has global_variables OFF and for the life of me i cannot get a form to submit :(
PHP Code:
<?
if(isset($_POST['submit'])):
$info = isset($_REQUEST['info']) ? $_REQUEST['info'] : '';
$sql = "UPDATE tourney_admin SET tourney_info='" . addslashes($info) . "'";
$result = mysql_query($sql)
or die("Update failed.\n");
echo "Tournament info has been added/updated.\n";
else:
?>
<center><b>View/Edit Tourney Info</b>
<form method="post" action="index.php?action=info">
<textarea rows="15" name="info" cols="63" value="<?= $row['tourney_info'] ?>"></textarea><br>
<input type="image" src="/images/buttons/submit.gif" value="Submit!" alt="Submit!" name="submit">
</form>
</center>
<?
endif;
?>
can anyone see anything wrong with that and tell me why it wont submit??
when i click the submit button, all it does is refresh the page, but nothing goes to the database.
thanks for the help
-
1| what the hell are you trying to do here:
PHP Code:
$info = isset($_REQUEST['info']) ? $_REQUEST['info'] : '';
???
and u could have asked me for help today at school in the comp room, i was bored out of my brain !!! :p
2| I like the way you style ur ELSE ENDIF thing's ;)
my solution: give me a definition of exactly what you want to do and i'll we write that code for you. :rolleyes:
-
lol, i have no idea what that is, im using it because i get no errors about undefined index and with $info = $_REQUEST['info'] i get errors ;)
and all im trying to do is get what the user types in the textarea named info to go into my database :(
i have never been able to get a form to work and its REALLY pissing me off :rolleyes:
-
FYI:
PHP Code:
$info = isset($_REQUEST['info']) ? $_REQUEST['info'] : '';
That is similar to the vb IIF. If the first part is true, then it returns the second part , else it returns the third part.
It is just checking if $_REQUEST['info'] is set and return it if it is (wow...4 two letter words beginning in 'i'!).
-
you need a "where" clause in your UPDATE sql statement for 1, unless you want all the records to contain the same info.
Secondly, you should add .mysql_error() to your die() function as it will give you a more detailed error message.
Thirdly, check to see if you are connected to the database.
-Matt
-
ok, so the updated code is this
PHP Code:
<?
if(isset($_POST['submit'])):
$info = isset($_REQUEST['info']) ? $_REQUEST['info'] : '';
$sql = "UPDATE tourney_admin SET tourney_info='" . addslashes($info) . "'WHERE id=1";
$result = mysql_query($sql)
or die("Update failed.\n");
echo "Tournament info has been added/updated.\n";
else:
?>
<center><b>View/Edit Tourney Info</b>
<form method="post" action="index.php?action=info">
<textarea rows="15" name="info" cols="63" value="<?= $row['tourney_info'] ?>"></textarea><br>
<input type="image" src="/images/buttons/submit.gif" value="Submit!" alt="Submit!" name="submit">
</form>
</center>
<?
endif;
?>
but i dont have any problems with the database, my problem is the form wont "submit". it just keeps refreshing the page when i click Submit and doesnt acknowledge that the user has entered the information in the form.
-
well, i cant figure out EXACTLY what you want, but i menaged to convert the following code:
PHP Code:
<?
if(isset($_POST['submit']))
{
$submit = $_POST['submit'];
$sql = "UPDATE tourney_admin SET tourney_info='" . .addslashes($info) . "'WHERE id=1";
$result = mysql_query($sql) or die("Submit Query Failed");
ECHO "Tournament info has been added/updated.\n";
} ELSE {
?>
<center><b>View/Edit Tourney Info</b>
<form method="post" action="index.php?action=info">
<textarea rows="15" name="info" cols="63" value="<?= $row['tourney_info'] ?>"></textarea><br>
<input type="submit" value="Submit!">
</form>
</center>
<?
}
unset($submit);
?>
-
I notice you have the action for your form set to : index.php?action=info
I did this once and it caused problems for me, what you should do is make a hidden field to store that value like so:
<input type="hidden" name="action" value="info" />
And you need a space between ' and where
-
still nothing, and cpradio, im not exactly sure what your talking about :confused:
-
you have this (red area is where I have had a problem in the past):
<form method="post" action="index.php?action=info">
I would change that to:
<form method="post" action="index.php">
<input type="hidden" name="action" value="info" />
-Matt
-
why have action=info if all you are doing is checking for submit? if you want action then do it like this
PHP Code:
<?
switch ($_POST["action"]){
case "info":
$info = isset($_POST['info']) ? $_POST['info'] : '';
$sql = "UPDATE tourney_admin SET tourney_info='" . addslashes($info) . "'WHERE id=1";
$result = mysql_query($sql)
or die("Update failed.\n");
echo "Tournament info has been added/updated.\n";
break;
default:
?>
<center><b>View/Edit Tourney Info</b>
<form method="post" action="index.php?action=info">
<textarea rows="15" name="info" cols="63" value="<?= $row['tourney_info'] ?>"></textarea><br>
<input type="image" src="/images/buttons/submit.gif" value="Submit!" alt="Submit!" name="submit">
</form>
</center>
<?
}
?>
if you you are not using action then just take it off.
-
is therea way you can do that straight to your e-mail address?