javascript - Php error on ajax call script -


well start want tank

the script create table send empty info have try this: http://mediaads.eu/villageop/back/savepoints.php?user_id=abcdefghijklm

now script wen call give me error:

so have edit script code clean code is:

<?php header('access-control-allow-origin: *'); error_reporting(e_all); ini_set('display_errors',1);  $servername = "localhost"; $username = "publiadd_publix"; $password = "1a3g7893fsh";  try {     $conn = new pdo("mysql:host=$servername;dbname=publiadd_registervillageop", $username, $password);     // set pdo error mode exception     $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception);     echo "connected successfully";  } catch(pdoexception $e){     echo "connection failed: " . $e->getmessage(); }   if(isset($_get['user_id'])){      //$user_id = intval($_get['user_id']);      //lightly sanitize get's prevent sql injections , possible xss attacks      try {       $dbh = new pdo("mysql:host=$servername;dbname=publiadd_registervillageop", $username, $password);        $user_id = @$_get['user_id'];         $dbh->setattribute(pdo::attr_errmode, pdo::errmode_exception); // <== add line       $sql = "insert users (user_id) values ('".$_post["user_id"]."')";       if ($dbh->query($sql)) {          echo "<script type= 'text/javascript'>alert('new record inserted successfully');</script>";       }       else{          echo "<script type= 'text/javascript'>alert('data not inserted.');</script>";       }           $dbh = null;     }     catch(pdoexception $e){        echo $e->getmessage();     }  } ?>  $sql->execute(array($user_id));        if($sql){                    //the query returned true - whatever here.           echo 'your id saved. congrats!';                    }else{                    //the query returned false - might want put sort of error reporting here. logging error text file fine.           echo 'there problem saving points. please try again later.';                    }          }else{      echo 'your id wasnt passed in request.'; }  // close mysql connection  $conn = null; ?> <html> <head> </head> <body> <body bgcolor="#ffffff"> </body> </html> 

the method using in forms use $_get not $_post goes in if condition. replace $_post $_get , second error table name users table not publiadd_registervillageop sql query looks like,

$sql = "insert users (user_id) values ('".$_get["user_id"]."')"; 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -