Jump to content


Photo

A 'next URL' option within a form?


  • Please log in to reply
3 replies to this topic

#1 pmg206

pmg206
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 26 April 2006 - 09:20 PM

I'm sure this is a no-brainer, but be gentle -- I'm a PHP newbie coming over from the Dark Side (ASP and MSSQL).

I have a form that, upon submission, ideally should allow me to kick them to a "success!" sort of page (and display a confirmation of their input, of course). Probably because I don't know how to phrase it, I can't for the life of me find the command/syntax for doing this.

The code I'm using is below. The page that houses this code is add_call.php, and the goal is, upon submit, forwarding the user to add_call-success.php. A quick point in the right direction, or even a good place to read up on forms, would be most appreciated.

Thanks in advance!

_____________________________________________________________

<?
//initilize PHP

if($_POST['submit']) //If submit is hit
{
//then connect as user
//change user and password to your mySQL name and password
mysql_connect("server","username","password");

//select which database you want to edit
mysql_select_db("ft4h");

//convert all the posts to variables:
$call_recd = $_POST['call_recd'];
$recd_by = $_POST['recd_by'];
$caller_name = $_POST['caller_name'];
$caller_source = $_POST['caller_source'];
$caller_phone = $_POST['caller_phone'];
$caller_altph = $_POST['caller_altph'];
$notes = $_POST['notes'];
$disp_to = $_POST['disp_to'];
$disp_by = $_POST['disp_by'];
$disp_date = $_POST['disp_date'];

//Insert the values into the correct database with the right fields
$result=MYSQL_QUERY("INSERT INTO calls (call_recd,recd_by,caller_name,caller_source,caller_phone,caller_altph,notes,disp_to,disp_by,disp_date)".
"VALUES ('$call_recd','$recd_by','$caller_name','$caller_source','$caller_phone','$caller_altph','$notes','$disp_to','$disp_by','$disp_date')");

//confirm
echo "Query Finished";
}

else
{
// close php so we can put in our code
?>
</p>
<form name="add" method="post" action="add_call.php"> //

... plain old HTML <table> with fields and such (add_call.php is the page here; we want to send 'em to add_call-success.php

</form></p>
<?
} //close the else statement
?>


#2 DepretioN

DepretioN
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 26 April 2006 - 09:27 PM

Well, first of all... you really want to do alot more validation on the input being submitted to your form.

But the code you are looking for ... put this after your query:

if ($result)
    header("Location: add_call-success.php");
else
    echo "Query failed, did not submit values";


#3 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 26 April 2006 - 09:28 PM

If you just need to figuire out the redirection part, just add:

header("location: thispage.php");

In your if statement, after you've done everything else you need to do.

(Note: I am at work and not really looking at things in much detail or focus...so I hope I did not misunderstand. Plus, I am in A.D.D mode. ;-) )
PHP Ninja

#4 pmg206

pmg206
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 26 April 2006 - 10:29 PM

Perfect -- it worked like a charm... thank you both!

Good feedback on the validation, too. This is a HUGE learning curve for me between letting Dreamweaver write some of the ASP and just validating it versus trying to do more hand-coding with php.net, this site and a Dummies book as my guides (the latter being a little too focused on their task list to help with the specific stuff). This particular form is just for me to track something personally, so I didn't get hung up on the validation -- yet -- but for the future project meant for the public, validation is a big 10-4.

Thanks again!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users