Form on Page:
<div>
<?php echo form_open('add/player');
echo form_label('First Name','playerFirstName');
echo form_input('playerFirstName','test');
echo "<br />";
echo form_label('Last Name','playerLastName');
echo form_input('playerLastName','test');
echo "<br />";
echo form_submit('addPlayer','Add Player');
echo form_close(); ?>
</div>
Called Controller:
class Add extends CI_Controller
{
public function index()
{
$this->load->view('header');
$this->load->view('add');
$this->load->view('footer');
}
public function Player()
{
if(strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')
{
if(basename($_SERVER['HTTP_REFERER']) == basename($_SERVER['PHP_SELF']))
{
$this->load->model('players');
$returnMessage = $this->players->add_player($this->input->post('playerFirstName'), $this->input-post('playerLastName'));
}
}
$this->load->view('header');
$this->load->view('addplayer');
$this->load->view('footer');
}
}
I'm a very green novice when it comes to PHP, CodeIgniter and MySQL (or web coding in general), so if you see any suggestions, please don't hesitate to make them (though the credit will be given to the one who answers my question, not makes my code work the best). However, as to my question, is there a way to see if a string is within another string? My $returnMessage
, if successful will have the word successfully
in it. What I want to do is if the player is not added, I want to reload the values from the form and put them back. Here's where it gets tricky.
The names are saved in table people_names
. In the players
table, I save the nameid
that is associated with that name in the people_names
table. In my add_player
function, I check to see if the names are in the table, if they aren't I add them, then I add the player to the players
table with the appropriate ids. Because of this, I'm not sure form_validation
would be able to be used or not. If it were, please let me know.
So what I want to do is check the $returnMessage
and if it doesn't contain successfully
, then I want to add the values back to the fields. However, I'm not finding a function where I can see if a string is inside of another string. I see string compares and substring functions, but no string contains. Any ideas? Thanks.