Ok, how do i make a button on a form redirect the user to another page?
Form Button Redirect, another cant beleive i forgot how to do this
A few ways depending on what you are trying to achieve
- Use the action="" parameter of the <form> tag to set where the form submit data to.
- use javascript on the onClick event of the button. document.location=
- have the form submit the page to a PHP script which runs a header( 'Location: addressToSendto');
It really depends what you're trying to do as to which is best.
well what im trying to do is submit information unto mysql and it will redirect to show the outcome on another page like "Thanks for uploading" or "The file is already in our database"
ok, and that will be after the echos? at the bottom? or untop?
A header() frunction must be used prior to any output, so you must have it before it echos anything.
//so here?
<FORM action="UploadC.php" name="upload" METHOD="POST" ENCTYPE="multipart/form-data">
<table width="100%" border="0" class="infotable">
<tr>
<td>Torrent</td>
<td><input type="file" name="torrent"></td>
</tr>
<tr>
<td>Optional name</td>
<td><input type=text name="filename" size=50 maxlength=200></td>
</tr>
<tr>
<td>Category</td>
<td><select name="type">
<option value="0">(Choose)</option>
<?php
$result = mysql_query("SELECT id, name FROM categories ORDER BY name ASC ") or sqlerr();
while ($row = mysql_fetch_assoc($result))
{
echo "<option value=\"";
echo $row['id'];
echo "\">";
echo $row['name'];
echo "</option>";
}
?>
</select>
<tr>
<td>Subcategory</td>
<td><select name="subtype">
<option value="0">(Choose)</option>
<?php
$result2 = mysql_query("SELECT id, name FROM subcategories ORDER BY name ASC ") or sqlerr();
while ($row2 = mysql_fetch_assoc($result2))
{
echo "<option value=\"";
echo $row2['id'];
echo "\">";
echo $row2['name'];
echo "</option>";
}
?>
</select>
<input type=hidden name=user_id size=50 value= >
<input type= hidden "radio" name="anonymous2" value="false" checked />
<input type= hidden "radio" name="anonymous" value="true" />
<input type= hidden checkbox name="autoset" value="enabled" checked></td>
</tr>
<tr>
<td>
Description </td>
<td>
<textarea name="info"></textarea> </td>
</tr>
<input type= hidden "radio" name="hideuser" value="false" />
<?}
?>
<tr>
<td> </td>
<td><input class="form_button" name="submit" type=submit value="Send"></td>
</tr>
</table>
</FORM>
Sorry looking at what you have right now that will direct them right to another page before any form processing or anything has happened. What you have right now is that when submitted the user will be taken to the UploadC.php page. What happens in the UploadC.php page?
well, exactly, it doesnt really reidrect at all, thats what im having problems with
Could you do the redirect on UploadC.php
You could do something like this .....
<?php // no html headers are sent yet
if (isset($_POST['submit'] {
var1 = $_POST['variable1'];
var2= $_POST['variable2'];
header("Location: http://yoursite/thanks.php");
exit();
}
else {
header("Location: http://yoursite/original_page.php");
}
Try this code it should submit and then go to UploadC.php
<FORM action="UploadC.php" name="upload" METHOD="POST" ENCTYPE="multipart/form-data">
<table width="100%" border="0" class="infotable">
<tr>
<td>Torrent</td>
<td><input type="file" name="torrent"></td>
</tr>
<tr>
<td>Optional name</td>
<td><input type=text name="filename" size=50 maxlength=200></td>
</tr>
<tr>
<td>Category</td>
<td><select name="type">
<option value="0">(Choose)</option>
<?php
$result = mysql_query("SELECT id, name FROM categories ORDER BY name ASC ") or sqlerr();
while ($row = mysql_fetch_assoc($result))
{
echo "<option value=\"";
echo $row['id'];
echo "\">";
echo $row['name'];
echo "</option>";
}
?>
</select>
<tr>
<td>Subcategory</td>
<td><select name="subtype">
<option value="0">(Choose)</option>
<?php
$result2 = mysql_query("SELECT id, name FROM subcategories ORDER BY name ASC ") or sqlerr();
while ($row2 = mysql_fetch_assoc($result2))
{
echo "<option value=\"";
echo $row2['id'];
echo "\">";
echo $row2['name'];
echo "</option>";
}
?>
</select>
<input type=hidden name=user_id size=50 value= >
<input type= hidden "radio" name="anonymous2" value="false" checked />
<input type= hidden "radio" name="anonymous" value="true" />
<input type= hidden checkbox name="autoset" value="enabled" checked></td>
</tr>
<tr>
<td>
Description </td>
<td>
<textarea name="info"></textarea> </td>
</tr>
<input type= hidden "radio" name="hideuser" value="false" />
<tr>
<td> </td>
<td><input class="form_button" name="submit" type=submit value="Send"></td>
</tr>
</table>
</FORM>
There were two while loops and they both were closed but later the code went to pure html then opend php again then had a <?} followed with a ?> on the next line it wrecked the code I merely cleaned up the error and not able to actually run the aql (I wasn't going to set up a new table to test it) I ran the HTML only and it works as I rewrote it and should work as I put it unless he has another problem with the SQL or database part.
with out the <? } ?> there will be a parse error
but it works once i out in the <? } ?>
Evidently there is an unclosed conditional statement in your code but what I copied from just had two while loops both close, so leave it alone if it works. My Editor can tell me about unclosed braces so I just made sure that what I reposted was correct minus the SQL sacuse I son't have your database structure on my machine. Glad it works for you.
yea thanks, and btw how do u do a php redirect?
header("Location: somepath/somefile")
WOW, lol, simple enough, kinda feel a lil dumb here! lol
Remember that there must be no output prior to using that function not even a space.
And it's a good idea to immediately follow a header("Location:..."); with exit;, because on its own PHP will happily continue processing even after redirecting the client.