Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Php Slim Framework Search on msql

Hie,

I am trying to build a website in which i want to allow site visitor to search my localhost database. I have been using slim framework in building the site and i am kinda hit the brick wall on this one. can someone help me please.

Thank in advance.

Selestino

5 Answers

I have not made my site work enough to take the time to refactor to slim and twig, which I plan on doing in the future. But, you cannot have a live site link to your localhost database. You have to have the database live on the web.

I found this with a quick search. http://stackoverflow.com/questions/25016307/slim-php-framework-image-upload-put-database

Thanx Ted, its helpful.

I wrote countless sql statements which are conecting me to my sever which is the mySQL but the problem is i built the html search page which is in search.twig and does not know how to link my search.twig to my search code in index.php since i am did not built a search.php page.

I have tried to set my action as follows;

<form id="searchbox" method="GET" action="search.twig"> <input id="search" type="text" placeholder="Type here"> <input id="submit" type="submit" value="Search"> </form>

which is returning a page not found error

and i have tried

<form id="searchbox" method="GET" action="index.php"> <input id="search" type="text" placeholder="Type here"> <input id="submit" type="submit" value="Search"> </form>

which is redirecting me to my home page if i click the search button

my php code is like

$app->get('/search', function() use($app){ $app->render('search.twig'); // search code here// })->name('search');

Thanks for those who will try to help.

sorry for the HTML codes above the full codes are like

{% block content %}


<form id="searchbox" method="GET" action="index.php">
    <input id="search" type="text" placeholder="Type here">
    <input id="submit" type="submit" value="Search">
</form>



{% endblock content %}

and

{% block content %}


<form id="searchbox" method="GET" action="search.twig">
    <input id="search" type="text" placeholder="Type here">
    <input id="submit" type="submit" value="Search">
</form>



{% endblock content %}

Edited to format code. Please refer to what I did and the Markdown Cheatsheet for future reference.

for basic troubleshooting, I would create a usable form in plain html. Once it works there, then place it in your project. That way you know the form is proper. I am not sure your form is as posted above. This is the form from the contact page that was built in the Treehouse project with Slim and Twig.

{% extends 'main.twig' %}

{% block content %}
    <strong>Contact</strong>
    <h2>Ralph Waldo Emerson</h2>

    <p>Unfortately, Ralph Waldo Emerson has been deceased for over 100 years so he's not particularly expediant at replying to email but you can make an attempt below. However, if you require face to gravestone contact you can visit his remains at:</p>
    <address>
      <h4>Sleepy Hollow Cemetery</h4>
      <p>34 Bedford Street<br>
      Concord, MA 01742, United States<br>
    <a href="https://www.google.com/maps/place/Sleepy+Hollow+Cemetery/@42.464126,-71.343098,15z/data=!4m2!3m1!1s0x0:0x9c41d0f83df689a6?sa=X&ei=ZCgLVZb5Io_hoASc7oHwCQ&ved=0CH0Q_BIwCw">Google Map</a></p>
    </address>

    <form action="" method="post">
      <fieldset>
        <input name="name" type="text" placeholder="Full Name">
        <input name="email" type="email" placeholder="Email Address">
        <textarea name="msg" placeholder="Your message..."></textarea>
      </fieldset>
      <input type="submit" class="button">
    </form>
{% endblock content %}

Notice the difference between the form in my quote and your form.

Thanks Ted. That was so helpful.