/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Form Reiteration

I have created a simple form which includes choosing a date & time. I would like the confirmation page to reiterate what date and time they chose.

My form gets processed by “signup.php” which then takes you to “confirmation.php”.

My problem is that all the data is showing not the one the was recently picked.

[SIZE=”5″]signup.php[/SIZE]

[code=php]<?php
include(“config.php”);
$connection=mysql_connect($hostname,$user,$pass) or die (“Failed to connect.”);
mysql_select_db($dbname,$connection) or die (“Cannot connect to DB”);

$sql=”
insert into compensation
(userid, Name, Ext, Time)
values
(”, ‘$Name’, ‘$Ext’, ‘$Time’)
“;

$result=mysql_query($sql,$connection) or die (“Could not insert data into the DB.”);

if ($result)
{
header (“Location:confirmation.php”);
}
?>[/code]

[SIZE=”5″]confirmation.php[/SIZE]

[code=php]<?php
include(“config.php”);
$connection=mysql_connect($hostname,$user,$pass) or die (“Failed to connect.”);
mysql_select_db($dbname,$connection) or die (“Cannot connect to DB”);

$userid=$_GET[‘userid’];

$sql = “SELECT * from compensation, compensation_times WHERE (compensation.Time = compensation_times.Time) “;
$result = mysql_query($sql);

?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html>
<head>
</head>
<body>
<p class=”head” align=”center”><br /><br /><br /><br />Thank you for your submission.</p>
<p class=”textc”>Please Print this page so that you have a record of your Date and Time.</p>
<p class=”subhead”>Date &amp; Time:</p>
<input type=”hidden” name=”userid” value=”<? echo $userid; ?>” />
<?php
while($row=mysql_fetch_assoc($result)){
?>
<p class=”head” align=”center”><? echo $row[‘Date’]; ?>
<?php
}
?>
<p class=”subhead” align=”center”>Please contact <a href=”mailto:[email protected]”>Lynn Blake</a> if you have any questions or concerns.</p>
</body>
</html>[/code]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@SrWebDeveloperJan 06.2010 — [B]In signup.php[/B]

Find:

[code=php]header ("Location:confirmation.php"); [/code]

Change to:

[code=php]header ("Location:confirmation.php?userid=".mysql_insert_id($connection)); [/code]

[B]In confirmation.php[/B]

Find:

[code=php]$userid=$_GET['userid'];

$sql = "SELECT * from compensation, compensation_times WHERE (compensation.Time = compensation_times.Time) "; [/code]


Change to:

[code=php]$userid=(isset($_GET['userid'])) ? intval(trim($_GET['userid'])) : -1;

$sql = "SELECT ct.Date from compensation c, compensation_times ct WHERE c.Time = ct.Time and c.userid='$userid' "; [/code]


[B]Note:

[/B]
You did not specify which table has the Date field so I assume it's in compensation_times because Date was not specified as a field name in the insert statement in signup.php. Adjust the query above (ct.Date to c.Date) accordingly if this is incorrect.

Other potential minor problems I noticed:

[LIST]
  • [*]The hidden form element containing the userid in confirmation.php is orphaned, there is no form wrapping it nor a submit of any type. Very confusing why it's there.

  • [*]You included your email in your OP on this forum. Hope you don't mind getting spammed! Be sure to edit those things out when posting code on forums on the Internet. FYI.

  • [*]The class names in the fully structured HTML in confirmation.php do not reference any linked stylesheet or inline styles.

  • [/LIST]

    -jim
    Copy linkTweet thisAlerts:
    @beylahauthorJan 06.2010 — Jim, thanks for your help but i am getting an error

    Parse error: parse error, unexpected $end in C:WebClientsvhostsfasken.comsubdomainseventshttpdocscompensationsignup.php on line 32
    Copy linkTweet thisAlerts:
    @SrWebDeveloperJan 06.2010 — I only changed one line in signup.php and the new code does not produce that error, so please look in your code carefully before and including line 32 to see if you left off a terminating semi-colon or closing parenthesis around a command or something like that. If unsure post lines 1-33 here.
    Copy linkTweet thisAlerts:
    @NogDogJan 06.2010 — Jim, thanks for your help but i am getting an error

    Parse error: parse error, unexpected $end in C:WebClientsvhostsfasken.comsubdomainseventshttpdocscompensationsignup.php on line 32[/QUOTE]


    Make sure your curly braces balance out (i.e. that there is a "{" for every "}", and vice versa). This is not the only possible source of such an error, but is the most common.
    Copy linkTweet thisAlerts:
    @beylahauthorJan 06.2010 — Thank you very much it now works. I have a few questions if I may to understand what you did. Also how do I turn off my email from showing?

    This part here I dont understand:
    [code=php]$userid=(isset($_GET['userid'])) ? intval(trim($_GET['userid'])) : -1;[/code]

    the part after the "?" [code=php]intval(trim($_GET['userid'])) : -1;[/code]

    could you explain it - thanks
    Copy linkTweet thisAlerts:
    @SrWebDeveloperJan 06.2010 — I meant you included your email in the code you copy/pasted here! Now it's on the forum for the world to see. Next time edit your post before submitting and change the email to [email][email protected][/email] or whatever. :p

    The ? thingy is a cool way to set a variable in PHP based on true or false response to a condition.

    [B]Syntax: [/B]$variable = (condition) ? value if true : value if false;

    The code I used sets $userid to the $GET global variable (trimmed and converted to an integer) if it is set, otherwise set it to -1 so your query doesn't crash if -1 is used. I use this syntax out of habit, I never "assume" a variable is set before referencing it, it's basic security, especially global variables like $_POST and $_GET.

    It's a more concise code than, say, doing the same this way:

    [code=php]if (isset($_GET['userid'])) {
    $userid=intval(trim($_GET['userid']));
    }
    else {
    $userid=-1;
    }
    [/code]


    Have fun!

    ?

    -jim
    ×

    Success!

    Help @beylah spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 4.29,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...