• Hi. I created a new .php file in the eGamer/includes that makes a conection to the db and returns a value. The problem is that i cannot connect to database when i call this file. Which should be the header of this file for making sure i can use at least all functions relating a db connection? this file is called from a javascript function using ajax, like this…

    conexion1=crearXMLHttpRequest();
    conexion1.onreadystatechange = procesarEventos;
    conexion1.open(“POST”, “http://localhost/Misite/wp-content/themes/eGamer/includes/Enviavoto.php”, true);

    conexion1.setRequestHeader(‘Content-Type’, ‘application/x-www-form-urlencoded; charset=ISO-8859-1’);

    hope i’ve been clear on my explanation. Many thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • you got it completely wrong!

    send your request from AJAX to php and use the WP build in wpdb to connect to the data base!

    Thread Starter hypnostate

    (@hypnostate)

    that’s the way i did… when i call Enviavoto.php in this line

    conexion1.open(“POST”, “http://localhost/Misite/wp-content/themes/eGamer/includes/Enviavoto.php”, true);

    then inside Enviavoto.php i create a new wpdb object but it doesn’t work properly this part of the file:

    <?php

    require(‘http://localhost/Misite/wp-blog-header.php&#8217;);
    require(“http://localhost/Misite/wp-config.php&#8221;);
    require_once(“functions.php”);
    require_once(“wp-db.php”);

    $puntuacion=$_POST[“Tuvoto”];
    $correo = $_POST[“Cogercorreo”];
    $activado=0;
    $video=70;

    if ( ! isset($wpdb) ) {
    $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
    }

    $wpdb->query( $wpdb->prepare( “INSERT INTO $wpdb->votos_pendientes (id, mail, activado, id_video, puntuacion) VALUES(%s, %s, %d, %d, %d)”,
    $ran,$correo, $activado,$video,$puntuacion) );

    i tried putting a simple sql string to see if it was a problem of the sql sentence, but it doesn’t work anyway. it must be a problem of the header, that needs to include the correct files or something… it always displays that can’t connect to database. and database is working correctly in my entire blog.

    thanks for concerning!

    Thread Starter hypnostate

    (@hypnostate)

    help please!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘add new php file for managing conecctions’ is closed to new replies.