{"id":38,"date":"2015-07-31T00:00:00","date_gmt":"2015-07-31T00:00:00","guid":{"rendered":"https:\/\/blog.jkanework.com\/post.php?idpost=38"},"modified":"2015-07-31T00:00:00","modified_gmt":"2015-07-31T00:00:00","slug":"aprender-phpmysql-facil-episodio-2","status":"publish","type":"post","link":"https:\/\/blog.jkanetwork.com\/?p=38","title":{"rendered":"Aprender PHP+mysql f\u00e1cil &#8211; Episodio 2"},"content":{"rendered":"<p>Pod&eacute;is ver mi anterior entrega de tutorial <a href=\"verart.php?idart=20\">aqu&iacute;<\/a><\/p>\n<p>En esta segunda entrega de tutoriales de php y mysql f&aacute;cil, vamos a aprender m&aacute;s sobre las variables, hacer formularios (Aqu&iacute; entra a parte un concepto de html <a href=\"http:\/\/www.w3schools.com\/html\/html_forms.asp\">http:\/\/www.w3schools.com\/html\/html_forms.asp<\/a>), y la sentencia if<\/p>\n<p>&nbsp;<\/p>\n<p>Para hacerlo mejor y m&aacute;s r&aacute;pido, nos familiarizaremos con las variables dentro del propio formulario<\/p>\n<p>Aqu&iacute; vemos un ejemplo b&aacute;sico de formulario en html<\/p>\n<div class=\"example_code notranslate htmlHigh\"><span style=\"color: #800000;\"><span class=\"highLT\">&lt;<\/span><span class=\"highELE\">form<\/span> <span class=\"highATT\">action=<\/span><span class=\"highVAL\">\u00abusarform.php\u00bb method=\u00bbpost\u00bb<\/span><span class=\"highGT\">&gt;<\/span><\/span><br \/><span style=\"color: #800000;\">Nombre:<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span style=\"color: #800000;\"><span class=\"highLT\">&lt;<\/span><span class=\"highELE\">input<\/span> <span class=\"highATT\">type=<\/span><span class=\"highVAL\">\u00abtext\u00bb<\/span> <span class=\"highATT\">name=<\/span><span class=\"highVAL\">\u00abnombre\u00bb<\/span>&nbsp;<span class=\"highGT\">&gt;<\/span><\/span><br \/><span style=\"color: #800000;\"><span class=\"highLT\">&lt;<\/span><span class=\"highELE\">br<\/span><span class=\"highGT\">&gt;<\/span><\/span><br \/><span style=\"color: #800000;\">Edad:<\/span><br \/><span style=\"color: #800000;\"><span class=\"highLT\">&lt;<\/span><span class=\"highELE\">input<\/span> <span class=\"highATT\">type=<\/span><span class=\"highVAL\">\u00abtext\u00bb<\/span> <span class=\"highATT\">name=<\/span><span class=\"highVAL\">\u00abedad\u00bb<\/span><span class=\"highGT\">&gt;<\/span><\/span><br \/><span style=\"color: #800000;\"> <span class=\"highLT\">&lt;<\/span><span class=\"highELE\">br<\/span><span class=\"highGT\">&gt;<\/span><\/span><br \/><span style=\"color: #800000;\"><span class=\"highLT\">&lt;<\/span><span class=\"highELE\">input<\/span> <span class=\"highATT\">type=<\/span><span class=\"highVAL\">\u00absubmit\u00bb<\/span> <span class=\"highATT\">value=<\/span><span class=\"highVAL\">\u00abEnviar\u00bb<\/span><span class=\"highGT\">&gt;<\/span><\/span><br \/><span style=\"color: #800000;\"><span class=\"highLT\">&lt;<\/span><span class=\"highELE\">\/form<\/span><span class=\"highGT\">&gt;<\/span><\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\">&nbsp;<\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Se rellenan dos campos, con nombres nombre y edad y usamos el method post (M&aacute;s seguro, pero tambi&eacute;n se puede usar \u00abget\u00bb)<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Al dar al boton de enviar, esas dos variables pasan a \u00abusarform.php\u00bb , en forma de $_POST[&#8216;nombre&#8217;] y $_POST[&#8216;edad&#8217;]<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Son variables especiales, observad su principio \u00ab$_\u00bb , y son POST porque elegimos post, sino ser&iacute;an \u00ab$_GET[]\u00bb<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\">&nbsp;<\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Esas variables se pueden usar para decir por ejemplo..<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\" style=\"color: #800000;\">print \u00abEres \u00bb . $_POST[&#8216;nombre&#8217;] . \u00bb y tienes \u00bb . $_POST[&#8216;edad&#8217;] . \u00bb a&ntilde;os\u00bb;<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Que podr&iacute;a quedar como \u00abEres perico y tienes 24 a&ntilde;os\u00bb<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Normalmente, estas variables se pasan a otras para ser modificadas al gusto, y mas f&aacute;ciles<br \/><span style=\"color: #800000;\">$nombre = $_POST[&#8216;nombre&#8217;];<\/span><\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\">&nbsp;<\/div>\n<div class=\"example_code notranslate htmlHigh\">&nbsp;<\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Al procesado de el formulario le vamos a a&ntilde;adir lo que se llama un \u00abif\u00bb , que es una pregunta al formulario<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Por ejemplo, queremos que diga que eres joven si pones hasta 25 a&ntilde;os,y adulto si pones m&aacute;s de 25<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">En php, un if funciona as&iacute;<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\" style=\"color: #800000;\">if (Comprobacion) {<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\" style=\"color: #800000;\">}<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\" style=\"color: #800000;\">Para el caso de j&oacute;ven ser&iacute;a as&iacute;:<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\" style=\"color: #800000;\">if ($_POST[&#8216;edad&#8217;] &lt;= 25){<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\" style=\"color: #800000;\">print \u00abEres j&oacute;ven\u00bb;<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\" style=\"color: #800000;\">}<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Algo similar para adulto<\/span><span class=\"highGT\">Codigo funcionando <a href=\"tutoriales\/tuto-php\/ep2-1.html\" target=\"_blank\">aqu&iacute;<\/a><\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Estos formularios se usan normalmente para poder meter o ver datos de una base de datos, que en este caso ser&aacute; mysql, y empezaremos a verlo en el siguiente episodio<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\">&nbsp;<\/div>\n<div class=\"example_code notranslate htmlHigh\">&nbsp;<\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Tambi&eacute;n,para que no os sea corto el tutorial, os a&ntilde;ado un \u00abextra\u00bb, la sentencia for, que significa, mientras X este entre una y otra cosa, repetir lo que hay dentro. Es algo que puede ser muy util<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Funciona as&iacute;<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\">&nbsp;<\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\" style=\"color: #800000;\">for (El principio;El final;Esto se ejecuta por cada vez){<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\" style=\"color: #800000;\">print \u00abEstoy repitiendo esto\u00bb;<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\" style=\"color: #800000;\">}<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span style=\"color: #800000;\">&nbsp;<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\" style=\"color: #800000;\">Por ejemplo, quer&eacute;is sacar en pantalla los n&uacute;meros del 1 al 20 impares<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\" style=\"color: #800000;\">for ($x = 1;$x &lt;= 20; $x++){<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\" style=\"color: #800000;\">&nbsp;&nbsp;&nbsp;&nbsp; print $x . \u00ab<br \/>\u00ab;<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\" style=\"color: #800000;\">}<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Eso mostrar&iacute;a:<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">1<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">3<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">5<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">7<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">&#8230;<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Cuando a una variable se le ponen \u00ab++\u00bb , lo que hace es sumar uno a la variable<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Si $numero es 21 y ponemos $numero++ , ser&aacute; 22 desde entonces<\/span><\/div>\n<div class=\"example_code notranslate htmlHigh\">&nbsp;<\/div>\n<div class=\"example_code notranslate htmlHigh\"><span class=\"highGT\">Cualquier duda y sugerencia, en los comentarios \ud83d\ude09<\/span><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pod&eacute;is ver mi anterior entrega de tutorial aqu&iacute; En esta segunda entrega de tutoriales de php y mysql f&aacute;cil, vamos a aprender m&aacute;s sobre las variables, hacer formularios (Aqu&iacute; entra a parte un concepto de html http:\/\/www.w3schools.com\/html\/html_forms.asp), y la sentencia if &nbsp; Para hacerlo mejor y m&aacute;s r&aacute;pido, nos familiarizaremos con las variables dentro del [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-38","post","type-post","status-publish","format-standard","hentry","category-tutoriales"],"_links":{"self":[{"href":"https:\/\/blog.jkanetwork.com\/index.php?rest_route=\/wp\/v2\/posts\/38","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jkanetwork.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jkanetwork.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jkanetwork.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jkanetwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=38"}],"version-history":[{"count":0,"href":"https:\/\/blog.jkanetwork.com\/index.php?rest_route=\/wp\/v2\/posts\/38\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jkanetwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=38"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jkanetwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=38"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jkanetwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=38"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}