Skip to content

Instantly share code, notes, and snippets.

View michaelnagy's full-sized avatar

Michael Nagy michaelnagy

  • https://traact.com
  • Ribeirao Preto - Brazil
View GitHub Profile
@michaelnagy
michaelnagy / update.php
Last active December 16, 2015 13:18
Code snippet that displays a form and when the user submits an ID, it updates a specific colum in the database.
<?php
//receives the form data
$unome = $_POST["unome"];
//conects to the database
$conecta = mysql_connect("localhost","user","pass");
$db = mysql_select_db("database");
//updates the selected field
$sql = mysql_query("UPDATE table SET columm='value'
@michaelnagy
michaelnagy / countingvalues.php
Last active December 16, 2015 14:18
A simple PHP script to connect to a database and select a specific column only if is not null. This column can have only 4 different values. The script then check if the query returned not null information and counts how many of each 4 values is in the database.
<?php
//connecting to the database
$conecta = mysql_connect("localhost","user","pass");
$db = mysql_select_db("database");
//the query gets only rows where the column is null.
$sql = mysql_query("SELECT column FROM table WHERE column!=''");
//gets the rows quantity
$totalRows = $num_rows = mysql_num_rows($sql);
<?php
//declares the funcion
function insertUser($nome, $sobrenome, $usuario, $senha, $visita, $data, $valor, $idade, $peso, $telefone, $email, $indicacao, $clinica, $queixa, $medida1, $medida2, $medida3, $medida4, $medida5, $medida6, $medida7, $medida8) {
conecta();
if (!empty($nome)) { $nome_value = $nome.','; $nome_insert = 'nome,';}
if (!empty($sobrenome)) { $sobrenome_value = $sobrenome.','; $sobrenome_insert = 'sobrenome,';}
if (!empty($usuario)) { $usuario_value = $usuario.','; $usuario_insert = 'usuario,';}
if (!empty($senha)) { $senha_value = $senha.','; $senha_insert = 'senha,';}
if (!empty($visita)) { $visita_value = $visita.','; $visita_insert = 'visita,';}
if (!empty($data)) { $data_value = $data.','; $data_insert = 'data,';}
@michaelnagy
michaelnagy / random-posts.php
Created April 25, 2013 18:31
This PHP script gets de Wordpress post IDs from database and use them to generate some URLs. It's for my own use. Didn't commented to much.
<?php
//connects do wordpress database
$conecta = mysql_connect("localhost","user","pass");
$db = mysql_select_db("database");
$sql = mysql_query("select * from wp_posts ");
//fetch the array with the query above
while($linha = mysql_fetch_array($sql)){
$ID[$i] = $linha['ID'];
$i++;
@michaelnagy
michaelnagy / do-while-loop.php
Created April 25, 2013 19:57
Simple PHP do-while exercise to train simple logic concepts.
<?php
//write your do-while loop below
$f = 1;
do {
if ($f == 1){
echo "the loop is ru";
}
if else ($f > 1) {
echo "n";
} else {
@michaelnagy
michaelnagy / count.js
Last active December 16, 2015 16:29
It's a counter that displays the numbers in seconds untill it finishes, then it prints another
var cont = 20; // guardo os segundos na variavel cont
function contador(){ //inicio a function
document.getElementById('tempo').innerHTML=cont; // pego a div de id tempo e com o inner html coloco o valor da variavel cont dentro da div
if(cont == 0) { //se variavel cont que vale 20 for igual a 0 executo uma função
document.getElementById('link').style.display="block"; // quando a variavel cont chegar a zero mudo o style do link de none para block
document.getElementById('tempo').style.display="none"; // escondo o time dou display none para ele
}
if (cont != 0){ // se variavel cont que vale 20 for diferente de 0 executo uma função
cont = cont-1; //aqui acontece a magina enquanto cont for diferente de zero ele vai repetir e diminui 1
setTimeout("contador()", 1000); // aqui o tempo que diminui cada segundo no caso de 1 em 1 segundo
@michaelnagy
michaelnagy / visitorsip.php
Last active January 28, 2023 19:04
Simple PHP script to get the user IP and writes it to the file.
<?php
//get tht ip from the user
$ip=$_SERVER['REMOTE_ADDR'];
//open or create the file
$arquivo = fopen($filename, "a");
if ($arquivo == false) {
die('Error message creating or opening the file.');}
//write to the file the IP from the user
if (!fwrite($arquivo, $ip."\n")) die('Error updating the file.');{
echo 'Sucess.';
@michaelnagy
michaelnagy / send-mail.js
Created May 7, 2013 18:30
Jquery code used in my personal site to send mail...
$(function() {
var contactForm = $('#contact-form');
contactForm.submit(function()
{
if(contactForm.valid())
{
contactForm.find('.submit-area').addClass('loading');
var formValues = $(this).serialize();
@michaelnagy
michaelnagy / protetor.php
Last active December 15, 2019 03:39
Protetor de link com 2 propagandas diferentes, baseado em cookies.
<?php
$horas = '43200';
$tempo_anuncio = '20';
$tempo_n = '35';
$link_protetor = $_POST['link_final'];
if(isset($_POST['link_final']) and !empty($link_protetor)){
$display = "none";
$referer = $_SERVER['HTTP_REFERER'];
if($_COOKIE['protetor'] == '1'){
setcookie("protetor", "2");
@michaelnagy
michaelnagy / prettyPhoto-open-onpage-load
Created June 1, 2014 16:21
Populate an array with all <a href=""> that has attribute rel=prettyPhoto, then opens the prettyPhoto gallery when page loads using prettyPhoto API function.
jQuery(document).ready(function($) {
var hrefs = [];
$('[rel^=prettyPhoto]').each(function() {
hrefs.push(this.href);
});
$.prettyPhoto.open(hrefs);
});