So I'm working on app that involves leveraging user profile data from FB. But not all users maintain the same data, so I'm using functions to determine which data is missing and then request the appropriate data from the user. These requests come from a database. A basic example of the function looks like this:
function getEmploymentInfo () {
if (isset($this->employer) and (!isset($this->jobtitle))) {
$id = 1;
} elseif (!isset($this->employer)) {
$id = 2;
}
echo $this->get_profile($id);
}
And the get profile function looks like this:
function get_profile($id) {
$dsn = "mysql:host=localhost;dbname=software";
$username = "root"; // database username
$password = "*******"; // database password
try {
$enter = new PDO($dsn, $username, $password);
$sql = "SELECT response FROM getprofile WHERE response_id = ? ";
$new_item = $enter->prepare($sql);
$new_item->setFetchmode(PDO::FETCH_ASSOC);
$new_item->execute(array($id));
foreach($new_item as $nw) {
return $nw['response'];
}
} catch (Exception $e) {
echo $e->getMessage();
exit;
}
return "";
}
And $id=1 coming from the database looks like this:
<script type="text/javascript">
function getJobTitle(){
document.getElementById("JobTitle").hidden = true;
document.getElementById("two").hidden = false;
}
function getStartDate(){
document.getElementById("StartDate").hidden = true;
document.getElementById("three").hidden = false;
}
function getEndDate(){
document.getElementById("EndDate").hidden = true;
document.getElementById("four").hidden = false;
}
<?php
echo "$objUser->employer";
?>
<form action="newprofile.php" method="post">
<p><a id="JobTitle" href="#" onclick="getJobTitle()">Add Job Title</a><input type="text" name="jobtitle" id="two" hidden="true" value="Add Job Title"></input></p>
<p><a id="StartDate" href="#" onclick="getStartDate()">Add Start Date</a><input type="text" name="startdate" id="three" hidden="true" value="Add Start Date"></input></p>
<p><a id="EndDate" href="#" onclick="getEndDate()">Add End Date</a><input type="text" name="enddate" id="four" hidden="true" value="Add End Date"></input></p>
<input type="submit" value="submit"></form>
But when this code returns from the database to the page echo "$objUser->employer"; doesn't populate. Meanwhile if I write that code directly on the page it works. What gives?
Databases just store text, not actual instantiated objects. The returned value has no way of knowing what $objUser was when you stored all that text.
There's a lot of things wrong with the way you're trying to go about doing this, you shouldn't be storing all that code in the database for every row. But the most simple way to answer this and point you in the right direction, is that you need to serialize objects in order to store them in the database, and unserialize them after pulling the record out of the database, in order to use them again.
Related
I'm writing a website that allows for people to add movies into a database.
At the moment the user can either select from a director that is already within the database or create a new one.
<div class='dropdownrow' id='director_namerow'>
<div>
<label for='director_name'>Director:</label>
<select name='director_name'>
<option value='blank' selected>Select...</option>
<?php
$sql = "SELECT *
FROM director
ORDER BY director_name ASC";
$director = mysql_query($sql);
while ($directors=mysql_fetch_array($director)) {
?>
<option value="<?php echo $directors['director_id']; ?>"><?php echo $directors['director_name']; ?></option>
<?php
}
?>
</select>
<span style = 'color:red;'> *</span>
</div>
<div>
<label for='director_namenew'>Or new director:</label>
<input type='text' name='director_namenew' size='25' maxlength='128' />
</div>
</div>
So the problem is, how do I check that "director_namenew" isn't equal to "director_name" AND that director_namenew isn't already within the database.
Furthermore, is the "director_namenew" isn't within the database, I need to add them into the database too.
Controller Script
function validateDirector ($formdata) {
if(($formdata['director_name'] == "blank") && ($formdata['director_namenew'] == "")){
return false;
}
else if($formdata['hidden_director_name'] == $formdata['director_namenew']){
echo 'cannot have directors match';
return false;
}
else {
return true;
}
} // TO COMPLETE
Thanks guys,
pb.
Answer to my own question
if(($formdata['director_name'] == "blank") && ($formdata['director_namenew'] == "")){
print "<p>Please enter in director information - Use the back button on your browser to rectify this problem.</p>";
return false;
}
else if($formdata['director_namenew']) {
$doesntExist = true;
$db = getDBConnection();
$directors = $db->query("SELECT director_name FROM director");
//Check each one
foreach ($directors as $director){
//If the username is already in the DB stop looking
if($formdata['director_namenew'] == $director['director_name']){
$doesntExist = false;
print "<p>Director entered in new director already exists, please enter in new director or select from drop down menu - Use the back button on your browser to rectify this problem.</p>";
break;
}
}
//DB connection closed when PDO object isn't referenced
//ie setting $db to null closes the connection
$db = null;
return $doesntExist;
}
-- However, how would I check to see if both the drop down and input field have been filled?
I was thinking something like:
else if(($formdata['director_name']) && ($formdata['director_namenew'])) {
print "Please select either new director or director from drop down menu";
}
And checking on the submit to see if both $_POST variables have been submitted.
What do you think?
You can use Ajax to transfer the front-end requirement to back-end so that seperate the view and controller.
view.html (Some modification base on your original code):
<script src="checkRepeatName.js"></script>
<div>
<label for='director_namenew'>Or new director:</label>
<input type='text' name='director_namenew' size='25' maxlength='128' />
<span id="notation"></span>
</div>
checkRepeatName.js (Written with jQuery):
$("input[name='director_namenew']").change(function(){
$.get("backend.php?dnamenew=" + this.value,function(data,status){
$(".notation").text(data);
});
});
backend.php (I use Object Oriented Style of PHP code,and refer the recommendation of #Barmar):
<?php
if (isset($_GET['dnamenew'])) {
$director_namenew = $_GET['dnamenew'];
};
$dbconn = new mysqli(HOST, USERNAME, PASSWORD, DBNAME, PORT);
$sqlStat = sprintf('SELECT director_id FROM director WHERE director_name = "%s";', $director_namenew);
if ($sqlQuery = $dbconn->query($sqlStat)){
if ($sqlQuery->num_rows == 0){
echo 'This is validated database name';
} else {
echo 'Invalidated database name!';
}
}
$dbconn->close;
?>
-------- supplement something --------
It maybe something help in design dynamic dropdown menu with MVC design pattern
view.html:
<div class='dropdownrow' id='director_namerow'>
<div>
<label for='director_name'>Director:</label>
<select name='director_name'>
<option value='blank' selected>Select...</option>
</select>
<span style = 'color:red;'> *</span>
</div>
<div>
controllor.js:
$("select[name='director_name']").change(function(){
$.get("optionOutput.php", function(data,status){
$("select[name='director_name']").append(data); // append the call-back message from back-end file
});
});
optionOutput.php:
<?php
include 'dbmng/dbconfig.php';
$dbconn = new mysqli(HOST, USERNAME, PASSWORD, DBNAME, PORT);
$sqlStat = 'SELECT * FROM director ORDER BY director_name ASC;';
if ($sqlQue = $dbconn->query($sqlStat)){
while($sqlRes = $sqlQue->fetch_assoc()){
$output = sprintf('<option value = "%d">%s</option>', $sqlResult['director_id'], $sqlRes['director_name']);
echo $output;
}
}
$dbconn->close;
?>
I can't figure out why my php script always returns NULL. I'm developing an Android app that gets user data from a database via a PHP script that returns JSON data. The app parses the data, but I can't get the PHP script to return anything other than NULL. The app uses JSON data for both the data returned for the user, and the result, which is either 1 or 0. I'm still new to PHP, so I'm a bit confused.
Here's my PHP script:
<?php
define('HOST','localhost');
define('USER','user');
define('PASS','password');
define('DB','database');
if (!empty($_POST)){
if (empty($_POST['userID'])){
$response["success"] = 0;
$response["message"] = "Please enter a User ID";
die(json_encode($response));
}
$userID = mysql_escape_string($_POST['userID']);
$con = mysqli_connect(HOST,USER,PASS,DB);
$result = mysql_query("SELECT* FROM users WHERE id = $userID");
if ($result && mysql_num_rows($result) > 0){
$response["result"] = array();
while($row = mysql_fetch_array($result)){
$finduser = array();
$finduser["id"] = $row["id"];
$finduser["firstname"] = $row["firstname"];
$finduser["company"] = $row["company"];
$finduser["position"] = $row["position"];
array_push($response["result"], $finduser);
}
$response["success"] = 1;
}
echo json_encode($response);
} else {
?>
<h1>Search by User ID:</h1>
<form action="searchbyuserid.php" method="post">
Enter the UserID of the receipient:<br />
<input type="text" name="userID" placeholder="User ID" />
<br /><br />
<input type="submit" value="Submit" />
</form>
Register
<?php
}
?>
You're using improper if-else format and also should have a Fatal Error with your code:
}
echo json_encode($response); // don't put anything between the close of the if and the beginning of the next block
//the next closing brace (or the previous one) shouldn't be here
} else {
Even if the brace above is just an artifact here and not in your actual code, you can't have anything between the end of the if block {} and the start of the next else/elseif block {}. Check your PHP error log - you should have a fatal error.
Also, as other users have stated, you are mixing mysql() and mysqli() functions, which is a no-no.
I've got a PHP class, and I'd like to create instances I can update later from the data that I pull from the database. Here's what I've got so far:
<?php
$servername = "localhost";
$username = "super";
$password = "cala";
$database = "fraga";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$getTableQuery = "SELECT ani.Id, ani.Name, ani.Size, ani.Color, tbs.Name as Species, tbs.Description
FROM animals as ani INNER JOIN
animalTypes as tbs ON ani.Species = tbs.Id
ORDER BY ani.Id";
$table = $conn->query($getTableQuery);
$pageLoaded = false;
if(isset($_POST['btnInsert']) && ($_POST['txtName'] != "")){
$pageLoaded = true;
}
if ($table->num_rows > 0) {
echo "<table border='1'><tr><th>Name</th><th>Size</th><th>Color</th><th>Species</th></tr>";
// output data of each row
while($row = $table->fetch_assoc()) {
echo "<tr><td>".$row["Name"]."</td><td>".$row["Size"]."</td><td>".$row["Color"]."</td><td>".$row["Species"]."</td></tr>";
$fish[] = $row;
}
echo "</table>";
echo "</br>";
} else {
echo "0 results";
}
if(isset($_POST['btnInsert']) && ($_POST['btnInsert'] == "Insert") && $pageLoaded == true)
{
$Animal = new Animal($_POST['txtName'], $_POST['txtSize'], $_POST['txtColor'], $_POST['txtSpecies'], $_POST['txtDescription']);
$Animal->InsertAnimal($conn);
}else if(isset($_POST['btnSave']) && ($_POST['btnSave'] == "Save") && $pageLoaded == true){
$Animal->UpdateAnimal($Animal);
}
class Animal
{
private $name = "Animal Name";
private $size = 0;
private $color = "255:255:255";
private $speciesName = "Species Name";
private $speciesDescription = "Species Description";
public function Animal($name, $size, $color, $species, $description){
$this->name = $name;
$this->size = $size;
$this->color = $color;
$this->speciesName = $species;
$this->speciesDescription = $description;
}
private function ColorCheck($color){
if($color >= 256 || $color <= 0)
return false;
else
return true;
}
public function InsertAnimal($conn, $pageLoaded){
$this->speciesName = mysqli_real_escape_string($conn, $this->speciesName);
$this->speciesDescription = mysqli_real_escape_string($conn, $this->speciesName);
$this->name = mysqli_real_escape_string($conn, $this->name);
$this->size = mysqli_real_escape_string($conn, $this->size);
$this->color = mysqli_real_escape_string($conn, $this->color);
$speciesId = "SELECT Id from animalTypes WHERE Name = '$this->speciesDescription'";
$speciesInsert = "INSERT IGNORE INTO animalTypes (Name, Description)
VALUES ('$this->speciesName', '$this->speciesDescription')";
$result = mysqli_query($conn, $speciesInsert) or die("Query fail: " . mysqli_error($conn));
if($id = $conn->query($speciesId)){
$row = $id->fetch_assoc();
$intId = $row['Id'];
}
$AnimalInsert = "INSERT INTO animals (Name, Size, Color, Species)
VALUES ('$this->name', $this->size, '$this->color', $intId)";
$result2 = mysqli_query($conn, $AnimalInsert) or die("Query fail: " . mysqli_error($conn));
echo '<script type="text/javascript">window.location = window.location.href;</script>';
$_POST['txtName'] = "";
}
public function UpdateAnimal($animal, $conn){
$speciesCheck = "SELECT * FROM animalTypes WHERE Name = '$this->speciesName";
$speciesList = mysqli_query($conn, $speciesCheck) or die("Query fail: " . mysqli_error($conn));
$updateQuery = "UPDATE animals";
}
}
$conn->close();
?>
<body>
<form action="index.php" method="post">
Animal Name:<br />
<input name="txtName" type="text" /><br />
<br />
Size:<br />
<input name="txtSize" type="text" /><br />
<br />
Color:<br />
<input name="txtColor" type="text" /><br />
<br />
Species Name:<br />
<input name="txtSpecies" type="text" /><br />
<br />
Species Description:<br />
<input name="txtDescription" style="width: 419px; height: 125px" type="text" /><br />
<br />
<input name="btnInsert" type="submit" value="Insert" />
<input name="btnSave" type="submit" value="Save" />
</form>
</body>
Now, what I'd like to do is create instances of Animal from the data that loads when the page loads, and store them for update. Problem is, I'm not sure how to do it. I've googled a bit (but my fu is admittedly weak), and saw suggestion for creating an array of Animals and adding them during the while loop. Is that really the best way to do that? And then how could I load the instance back into the text boxes so that I could update them?
First of all you should learn to seperate the concerns in your code correctly.
If I started to explain how you should build your script up from scratch, this would take too long, so I will try to give you only a good direction to go. I think this will help you more in your learning process.
So, if I understand correctly, the code you posted is all set up in one file, I guess it's inside you index.php? (missing some information here)
If this is the case...
index.php
Use your index.php for displaying a list of your "Animals" from db, not more. Every list entry will have an edit and delete button/link next to it. On top of your list put a link that's called create.
Now all your index.php does is getting the animals from db and listing them.
Put this part of your code in another file, called dbconfig.php
$servername = "localhost";
$username = "super";
$password = "cala";
$database = "fraga";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
include it on top of your index.php, before you start scripting the index.php
include 'dbconfig.php'
now you can use your $conn variable inside you index.php. We put this into another file and included it, because we're going to reuse this part in the next steps.
I won't write your whole code here for index.php, I think you'll master that. Maybe you ask yourself what your create, edit, delete links should do.
The create link point to a create.php, a simple html link.
The edit link, you will have to render an html link to edit.php?id=IDOfYourAnimalInsideDB
The delete link looks like the edit one, put a link to delete.php?id=IDOfYourAnimalInsideDB.
So where I wrote "IDOfYourAnimalInsideDB" you have to output the actual id, this will be done in your while loop.
create.php
first of all, include the dbconfig.php again here, so you can use your $conn variable which has the db connection.
check if the request has some of your post variables, if true, build an instance of animal and write it to db.
outside the if you build your form. So it doesn't matter if it's post or not, you will show the create form.
delete.php
Again the dbconfig.php include first.
Then you want to check if $_GET['id'] is set and maybe if it's bigger than 0 and if its an integer value. If so, execute your delete sql to the db.
update.php
Again the dbconfig.php include first.
Then you want to check your GET Parameter again and build an sql request to get your specific database entry.
Output a form that already contains your values from db. If a post request comes, you create a new Animal instance, fill it with your data from $_POST and then use it for updating your db.
getters in Animal Class
add getter functions to you animal class, so you can access the private properties from outside. you should write you create, update, delete logic inside the create.php, update.php, delete.php or in another class which you use for database manipulation. There you want to get access to properties for example in order to build up your update sql.
So make a getter method for every property of your "Animal" model class
public function getName() {
return $this->name;
}
so from outside you can get your animals name like so
$animalName = $animal->getName();
more specific?
If you need something more specific, you should specify a little bit more your question. What I described is just a way that splits your script into parts you can understand and maintain better, because stucture and correct seperation of things is one of the most important things in programming.
What I described is far far away from a clean "CRUD" solution, but I think this is a little step for you that you can take now to come closer to a clean solution.
Kind regards
I have a PHP website to display products. I need to introduce a 'Search' feature whereby a keyword or phrase can be found among number of products.
I went through number of existing scripts and wrote/modified one for me which though able to connect to database, doesn't return any value. The debug mode throws a warning " mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given ". Seems I am not collecting the query value correctly. The PHP Manuals says that mysqli_query() returns FALSE on failure and for successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object and for other successful queries mysqli_query() will return TRUE ".
Any suggestions?
<form name="search" method="post" action="search.php">
<input type="text" name="searchterm" />
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="submit" value="Search" />
</form>
<?php
$searchterm=trim($_POST['searchterm']);
$searching = $_POST['searching'];
$search = $_POST['search'];
//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo 'Results';
//If they forget to enter a search term display an error
if (!$searchterm)
{
echo 'You forgot to enter a search term';
exit;
}
//Filter the user input
if (!get_magic_quotes_gpc())
$searchterm = addslashes($searchterm);
// Now connect to Database
# $db = mysqli_connect('localhost','username','password','database' );
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to the database. Please try again later.';
exit;
}
else {
echo "Database connection successful."; //Check to see whether we have connected to database at all!
}
//Query the database
$query = "SELECT * FROM wp_posts WHERE post_title LIKE '%$searchterm%' OR post_excerpt LIKE '%$searchterm%' OR post_content LIKE '%$searchterm%'";
$result = mysqli_query($db, $query);
if (!$result)
echo "No result found";
$num_results = mysqli_num_rows($result);
echo "<p>Number of match found: ".$num_results."</p>";
foreach ($result as $searchResult) {
print_r($searchResult);
}
echo "You searched for $searchterm";
$result->free();
$db->close();
}
To do your literal search as you have it, you would need to change the code '%{searchterm}%' to '%$searchterm%', since the brackets aren't needed and you were searching for the phrase "{searchterm}." Outside of that you might want to take a look at FULLTEXT search capabilities since you're doing a literal search in your current method.
To make the output look like Google's output you would simply code a wrapper for each search result and style them with CSS and HTML.
I think it should be something like '%$searchterm%', not '%{searchterm}%' in your query. You are not searching for your variable $searchterm in your example.
Google's display uses LIMIT in the query so it only displays a certain amount of results at a time (known as pagination).
This is tested and works. You will need to change 1) db connection info in the search engine class. 2) If you want it to be on separate pages, you will have to split it up. If not, copy this whole code to one page and it will work on that one page.
<?php
class DBEngine
{
protected $con;
// Create a default database element
public function __construct($host = '',$db = '',$user = '',$pass = '')
{
try {
$this->con = new PDO("mysql:host=$host;dbname=$db",$user,$pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
}
catch (Exception $e) {
return 0;
}
}
// Simple fetch and return method
public function Fetch($_sql)
{
$query = $this->con->prepare($_sql);
$query->execute();
if($query->rowCount() > 0) {
$rows = $query->fetchAll();
}
return (isset($rows) && $rows !== 0 && !empty($rows))? $rows: 0;
}
// Simple write to db method
public function Write($_sql)
{
$query = $this->con->prepare($_sql);
$query->execute();
}
}
class SearchEngine
{
protected $searchterm;
public function execute($searchword)
{
$this->searchterm = htmlentities(trim($searchword), ENT_QUOTES);
}
public function display()
{ ?>
<h1>Results</h1>
<?php
//If they forget to enter a search term display an error
if(empty($this->searchterm)) { ?>
<h3>Search Empty</h3>
<p>You must fill out search field.</p>
<?php }
else {
$con = new DBEngine('localhost','database','username','password');
$results = $con->Fetch( "SELECT * FROM wp_posts WHERE post_title LIKE '%".$this->searchterm."%' OR post_excerpt LIKE '%".$this->searchterm."%' OR post_content LIKE '%".$this->searchterm."%'");
if($results !== 0 && !empty($results)) { ?>
<p>Number of match found: <?php echo count($results); ?> on search:<br />
<?php echo strip_tags(html_entity_decode($this->searchterm)); ?></p>
<?php
foreach($results as $rows) {
echo '<pre>';
print_r($rows);
echo '</pre>';
}
}
else { ?>
<h3>No results found.</h3>
<?php
}
}
}
}
if(isset($_POST['submit'])) {
$searcher = new SearchEngine();
$searcher->execute($_POST['searchterm']);
$searcher->display();
} ?>
<form name="search" method="post" action="">
<input type="text" name="searchterm" />
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="submit" value="Search" />
</form>
I have this function on my php:
function getLastMatchs($nb) {
try
{
$db = new PDO(DBHOST, DBUSER, DBPASS);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
die('connexion failed: '.$e->getMessage());
}
$i=0;
$get5tmatchs = $db->query('SELECT wid, lid, date, cwid, clid FROM `match`');
while ($nb<$i)
{
$data5matchs = $get5tmatchs->fetch();
echo '<tr>
<td>'.$data5matchs['wid'].'</td>';
echo '<td>'.$data5matchs['lid'].'</td>';
echo '<td>'.$data5matchs['cwid'].'</td>';
echo '<td>'.$data5matchs['clid'].'</td>';
echo '<td>'.$data5matchs['date'].'</td>
<br>
</tr>';
$i++;
}
}
And my form is:
echo '<form action="index.php" method="post">
<h3>My question......</h3>
<p>
<input type="text" name="nbmatchs" />
<input type="submit" value="ok" />
</p>
</form>';
echo getLastMatchs('nbmatchs');
How can i do for show nbmatch time the guys want my table ?
When i do now, nothing happen.
Thanks for your help
PS: For exemple i tape 5, i can see 5 time the tabe i have put in my function.
What you indended to accomplish (as far I understood) to allow a visitor enter a numer and then submit it after what some "matches" data it shown. The number visitor entered acts as a limiter.
1. Where do you get your POST variables? You have placed a function below the form with an input value of string 'nbmatchs'. I guess you wanted to submit the form and get the 'nbmatches' value and then apply it to the SQL query for filtering. The way you have done it doesn't work. You have action attribute on your form element set to index.php. That's where we are going to submit the form data. So we need to have a way to get the submitted POST variables. We do it like this:
$nbmatchs = $_POST['nbmatchs'];
Never trust data client has given you. As we know that it must a number let's do a check on it:
$nbmatches = is_numeric(trim($_POST['nbmatchs'])) ? $_POST['nbmatchs'] : 1;
Above we checked if the data client has given really is a number. If it is we'll assign this nubmer to variable $nbmatches. If the data client has given is not a number (eg. some string) we assign number 1 to the variable. At this point we may end the script execution a let the visitor know he must enter a number but we just assign 1 to the variable if anything seems suspicious. After that we can submit this variable to the function getLastMatchs which takes the variable and assigns it to the SQL query as a results limiter. Assuming that all the code will be in one file 'index.php' you should have the following code:
<?php
function getLastMatchs($nbmatches) {
try{
$db = new PDO(DBHOST, DBUSER, DBPASS);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
die('connexion failed: '.$e->getMessage());
}
try {
$select = $db->prepare('SELECT wid, lid, date, cwid, clid FROM `match` LIMIT '.$nbmatches.';');
$select->execute();
$results = $select->fetchAll(PDO::FETCH_ASSOC);
} catch(PDOException $ex) {
echo "<span style='color:red'>".$ex->getMessage()."</span></p>";
}
echo '<table>';
foreach($results as $result){
$output = '<tr>';
$output .= '<td>'.$result['wid'].'</td>';
$output .= '<td>'.$result['lid'].'</td>';
$output .= '<td>'.$result['cwid'].'</td>';
$output .= '<td>'.$result['clid'].'</td>';
$output .= '<td>'.$result['date'].'</td>';
$output = '</tr>';
echo $output;
}
echo '</table>';
}
if(isset($_POST['nbmatchs'])){
$nbmatches = is_numeric(trim($_POST['nbmatchs'])) ? $_POST['nbmatchs'] : 1;
getLastMatchs($nbmatches);
}
?>
<form action="index.php" method="post">
<h3>My question......</h3>
<p>
<input type="text" name="nbmatchs" />
<input type="submit" value="ok" />
</p>
</form>
Let me know if this works the way you wanted.