Jump to content

c++ coder having conceptual problems...


Derleek

Recommended Posts

Hi, i'm new to the world of coding for the web.  I have a good amount of C++ experience... but i'm having trouble conceptualizing how the best way to handle variables from one page to another.

 

For example, if i am creating a game and i want to validate the input.

 

Is there a way to handle the html form on that same page that they input it?

 

ok so basically can i take this basic form handling script....

 

Form:

 <form action="welcome.php" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>

 

welcome.php:

<html>
<body>

Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old.

</body>
</html>

 

and make it do something like this...

 

welcome.php:

<html>

<body>
<form action="randomFunction()" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
<?php
function randomFunction() {
//validate input 
}
?>
</body>
</html>

 

I'm really asking this for efficiency sake... I'm wondering if the best approach is to create a temporary MySQL table then validate using a separate php script, proceed to store the data permanently...

 

so if that doesn't make any sense, what is the best method to receive user input/validate and store using MySQL...

Link to comment
https://forums.phpfreaks.com/topic/104416-c-coder-having-conceptual-problems/
Share on other sites

Functions made in PHP must be called through PHP.

 

If you want to do what you're suggesting, set the action to the same page, name the submit button something and do:

<html>

<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" name="submit_1" />
</form>
<?php
if ($_POST['submit_1'])
{ // validate
}
?>
</body>
</html>

Id say do everything on the same page e.g.

<form action="post">
<input type="text" name="nametext">
<input type="submit" name="submitbtn">
</form>
<?
if (strip_tags($_POST['nametext']) && strip_tags($_POST['submitbtn'])){
//validation etc here

}
?>

 

This way the user doesnt have to go from page to page to page.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.