from clasic php file to MVC framework

Links for php scripts

Moderators: macek, egami, gesf

speedovic
New php-forum User
New php-forum User
Posts: 1
Joined: Sat Nov 10, 2012 11:46 am

from clasic php file to MVC framework

Postby speedovic » Sat Nov 10, 2012 11:52 am

I need some help to put this simple code into MVC any help would be appreciated. It is a simple form which retrieves data from an SQL DB.. it works fine as one file but I have problems to put it in MVC, especially with submit part.

=================== HTML ========
</head>
<p><body>
<h3>Search Contacts Details</h3>
<p>You may search either by first or last name</p>
<form method="post" action="search_start.php?go" id="searchform">
<input type="text" name="name">
<input type="submit" name="submit" value="Search">
</form>
</body>
</html>

================== PHP ============
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/[A-Z | a-z]+/", $_POST['name']))
{

$name=$_POST['name'];

//-query the database table
$sql="SELECT * FROM Contacts WHERE FirstName LIKE '%" . $name . "%' OR LastName LIKE '%" . $name ."%'";

//-run the query against the mysql query function
$result=mysql_query($sql);

//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){

$FirstName =$row['FirstName'];
$LastName=$row['LastName'];
$ID=$row['ID'];
$Email=$row['Email'];

//-display the result of the array
//echo "<ul>\n";
echo "<li>" . "<a href=\"search_start.php?id=$FirstName\">" .$FirstName . " " . $LastName . "</a></li>\n";

//echo "</ul>";
}
}
else{
echo "<p>Please enter a search query</p>";
}
}}

?>

Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest

cron