If I remove the or die("MySQL ERROR: ".mysqli_error()); from the code below, it gives me no error. But it also doesn't write to the database.
What am I doing wrong?
ob_start();
session_start();
require ('openid.php');
function logoutbutton() {
echo "<form action=\"steamauth/logout.php\" method=\"post\"><input value=\"Logout\" type=\"submit\" /></form>"; //logout button
}
function steamlogin() {
try {
require("steamauth/settings.php");
$openid = new LightOpenID($steamauth['domainname']);
$button['small'] = "small";
$button['large_no'] = "large_noborder";
$button['large'] = "large_border";
$button = $button[$steamauth['buttonstyle']];
if(!$openid->mode) {
if(isset($_GET['login'])) {
$openid->identity = 'http://steamcommunity.com/openid';
header('Location: ' . $openid->authUrl());
}
//echo "<form action=\"?login\" method=\"post\"> <input type=\"image\" src=\"http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_".$button.".png\"></form>";
} elseif($openid->mode == 'cancel') {
echo 'User has canceled authentication!';
} else {
if($openid->validate()) {
$id = $openid->identity;
$ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
preg_match($ptn, $id, $matches);
$_SESSION['steamid'] = $matches[1];
include_once("set.php");
$query = mysqli_query("SELECT * FROM users WHERE steamid='".$_SESSION['steamid']."'");
if (mysqli_num_rows($query) == 0) {
mysqli_query("INSERT INTO users (steamid) VALUES ('".$_SESSION['steamid']."')") or die("MySQL ERROR: ".mysqli_error());
}
if (isset($steamauth['loginpage'])) {
header('Location: '.$steamauth['loginpage']);
}
} else {
echo "User is not logged in.\n";
}
}
} catch(ErrorException $e) {
echo $e->getMessage();
}
}
Here's a screen-shot of my database structure:
Related
I got this error:
Fatal error: Call to undefined function updateRows()
but I have defined updateRows(), so what is wrong?
Here is my code:
<?php
if ($this->num_rows > 0) {
$i = 0;
while ($row = $stmt->fetchObject()) {
$appleIDS[$i] = array(
$row->id,
$row->pass,
$row->en_b_y,
$row->en_b_m,
$row->en_b_d,
$row->sqa1,
$row->sqa2,
$row->sqa3
);
$i++;
}
updateRows($this->pre_head, $head);
killTheConnection();
return $appleIDS;
}
killTheConnection();
return $check;
}
function updateRows($pre_head, $head) // here is my function
{
$this->mysqli_connet();
try {
$sql = "UPDATE appleid " . "SET taken = 'yes'" . "," . "taken_time=now()" . "WHERE num>=$pre_head AND num<=$head;";
$stmt = $GLOBALS['$connection']->prepare($sql);
$stmt->execute();
echo $stmt->rowCount();
}
catch (PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
killTheConnection();
}
?>
Solved! Will post the working answer tonight. Might be helpfull to others.
I'm trying to run a script I made a few months back. The script was set up to be used with a directory filled with .json files (45 files containing 200 items each) and it runs through those files to fetch data and then store them with a query in the database.
Problem is I can't use $conn inside my laravel project so I'm at a loss how i can now connect to the database and store all my data. I can read the json no problem and I have a model inside my laravel project for the corresponding table with all fields set to fillable.
Here's my code:
<?php
namespace App\Http\Controllers;
use DB;
use App\Http\Controllers\Controller;
class JsonController extends Controller
{
public function importJson() {
$path = realpath('AllSetFiles/');
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $filename)
{
if ($filename->isDir()) continue;
// Include the JSON and put it inside $data.
$jsondata = file_get_contents($filename);
$data = json_decode($jsondata, true);
// Echo the variables to the screen or put them in the database. (y shows to screen)
$echo = "n";
// foreach card in cards in the JSON file put all values in their named variables.
foreach($data['cards'] as $cards => $values) {
if(isset($values['multiverseid'])) {
$multiverseid = $values['multiverseid'];
} else {
$multiverseid = "";
}
$name = $values['name'];
if (isset($values['manaCost'])) {
$manaCost_array = array();
$manaCost_array = array($values['manaCost']);
$manaCost = implode (", ", $manaCost_array);
} else {
$manaCost = "";
}
if (isset($values['cmc'])) {
$cmc = $values['cmc'];
} else {
$cmc = "";
}
if (isset($values['colors'])) {
$colors_array = array();
$colors_array = $values['colors'];
$colors = implode (", ", $colors_array);
} else {
$colors = "";
}
if (isset($values['type'])) {
$type = $values['type'];
} else {
$type = "";
}
if (isset($values['supertypes'])){
$supertypes_array = array();
$supertypes_array = $values['supertypes'];
$supertypes = implode (", ", $supertypes_array);
} else {
$supertypes = "";
}
if (isset($values['types'])){
$types_array = array();
$types_array = $values['types'];
$types = implode (", ", $types_array);
} else {
$types = "";
}
if (isset($values['subtypes'])){
$subtypes_array = array();
$subtypes_array = $values['subtypes'];
$subtypes = implode (", ", $subtypes_array);
} else {
$subtypes = "";
}
if (isset($values['rarity'])) {
$rarity = $values['rarity'];
} else {
$rarity = "";
}
if (isset($data['code'])) {
$serie = $data['code'];
} else {
$serie = "";
}
if (isset($values['text'])) {
$text = $values['text'];
} else {
$text = "";
}
if (isset($values['flavor'])) {
$flavor = $values['flavor'];
} else {
$flavor = "";
}
if (isset($values['artist'])) {
$artist = $values['artist'];
} else {
$artist = "";
}
if (isset($values['number'])) {
$number = $values['number'];
} else {
$number = "";
}
if (isset($values['power'])) {
$power = $values['power'];
} else {
$power = "";
}
if (isset($values['toughness'])) {
$toughness = $values['toughness'];
} else {
$toughness = "";
}
if (isset($values['layout'])) {
$layout = $values['layout'];
} else {
$layout = "";
}
if (isset($values['imageName'])) {
$imageName = $values['imageName'];
} else {
$imageName = "";
}
if ($echo == "y"){
echo 'multiverseid: <b>' . $multiverseid . '</b></br>';
echo 'name: <b>' . $name . '</b><br/>';
echo 'serie: ' . $serie . '<br/>';
echo 'manaCost:' . $manaCost . '<br/>';
echo 'cmc: ' . $cmc . '<br/>';
echo 'colors: ' . $colors . '<br/>';
echo 'type: ' . $type . '<br/>';
echo 'supertypes:' . $supertypes . '<br/>';
echo 'types: ' . $types . '<br/>';
echo 'subtypes: ' . $subtypes . '<br/>';
echo 'rarity: ' . $rarity . '<br/>';
echo 'text: ' . $text . '<br/>';
echo 'flavor: ' . $flavor . '<br/>';
echo 'artist: ' . $artist . '<br/>';
echo 'number: ' . $number . '<br/>';
echo 'power: ' . $power . '<br/>';
echo 'toughness: ' . $toughness . '<br/>';
echo 'layout: ' . $layout . '<br/>';
echo 'imageName: ' . $imageName . '<br/>';
echo 'src="http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=' . $multiverseid . '&type=card"<br/>';
echo '<br/><hr><br>';
} else {
// Put all variables in a query and send it to the database.
DB::table('cards')->insert(
[
'multiverseid' => $multiverseid,
'name' => $name,
'serie' => $serie,
'manaCost' => $manaCost,
'cmc' => $cmc,
'colors' => $colors,
'type' => $type,
'supertypes' => $supertypes,
'types' => $types,
'subtypes' => $subtypes,
'rarity' => $rarity,
'text' => $text,
'flavor' => $flavor,
'artist' => $artist,
'number' => $number,
'power' => $power,
'toughness' => $toughness,
'layout' => $layout,
'imageName' => $imageName
]
);
} // end if show or query loop
} // end foreach loop
} // end foreach recursiveIterator
} // end of function importJson
} // end of class
?>
And in my routes.php:
// JSON
Route::get('importjson', 'JsonController#importJson');
going to myapp.com/importjson gives me the following error:
Class 'App\Http\Controllers\RecursiveIteratorIterator' not found
I have around 700 product list in my Databse table.
I am using bootstrap's tokenfield for auotcomplete, i have to use auto complete in search textbox.
I am getting syntax error :
SyntaxError: missing ] after element list
...B','Lino Perros Men's Leather Wallet - Pink','Lenovo A269i','Lenovo S660 - Tita**
in console.
<?php $t = $this->general_model->auto_complete_sug(); ?>
$( document ).ready(function() {
$('#tokenfield-2').tokenfield({
autocomplete: {
source: <?=$t?>,
delay : 100
},
limit: 1,
minLength: 1,
showAutocompleteOnFocus: true
});
});
<input type="text" class="span2" name="search" id="tokenfield-2" placeholder="Search...">
In my model: I have created this functions:
public function auto_complete_sug()
{
$data = $this->auto_complete_token_fun();
$data1 = explode(',', $data);
$data1 = array_unique($data1);
foreach ($data1 as $value1) {
$temparr[] = $value1;
}
$str = '[';
$c = count($temparr);
$counter = 0;
foreach ($temparr as $val) {
$counter++;
$str .= "'".$val."'";
if($counter < $c){
$str .= ",";
}
}
$str .= ']';
return $str;
}
public function auto_complete_token_fun()
{
// $this->db->query("SET GLOBAL group_concat_max_len = 10000000");
$q = $this->db->query("SELECT GROUP_CONCAT( sub_category_name ) AS scname
FROM `tbl_subcategory` WHERE status = 'Active' ");
if($q->num_rows() > 0)
{
$d = $q->row_array();
return $d['scname'];
}
else
{
return '';
}
}
Please help!!
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
The code I am trying to use is below, Ive double checked it and everything and it keeps saying this error: Fatal error: Call to undefined function Votifier() , I dont know what the problem is here. This is my last resort to ask here, Ive been googling for 2 hours.. Thanks in advance.
<?php
if (isset($_COOKIE['votfed']) && $_COOKIE['vofted'] == 'true') {
exit();
} else {
mysql_connect("", "", "")or die("cannot connect");
mysql_select_db("")or die("cannot select DB");
$result = mysql_query('SELECT * FROM servers WHERE id = "' . $_GET["server"] . '"');
while ($row = mysql_fetch_array($result)) {
$public_key = $row['votifier_key'];
$server_ip = $row['ip'];
$server_port = $row['votifier_port'];
$username = 'USERNAME';
}
$username = preg_replace("/[^A-Za-z0-9_]+/", '', $username);
if (Votifier($public_key, $server_ip, $server_port, $username)) {
echo 'Success!';
} else {
echo 'Error!';
}
ini_set('error_reporting', E_ALL);
function Votifier($public_key, $server_ip, $server_port, $username) {
$public_key = wordwrap($public_key, 65, "\n", true);
$public_key = <<<EOF
-----BEGIN PUBLIC KEY-----
$public_key
-----END PUBLIC KEY-----
EOF;
$address = $_SERVER['REMOTE_ADDR'];
$timestamp = time();
$string = "VOTE\MC-ServerLists.com\n$username\n$address\n$timeStamp\n";
$leftover = (256 - strlen($string)) / 2;
while ($leftover > 0) {
$string .= "\x0";
$leftover--;
}
openssl_public_encrypt($string, $crypted, $public_key);
$socket = fsockopen($server_ip, $server_port, $errno, $errstr, 3);
if ($socket) {
fwrite($socket, $crypted);
return true;
} else
return false;
}
mysql_connect("", "", "")or die("cannot connect");
mysql_select_db("")or die("cannot select DB");
mysql_query('insert into voters (server_id, ipaddress) VALUES ("' . $_GET["server"] . '", "' . $_SERVER['REMOTE_ADDR'] . '")');
}
If you formatted your code correctly, you'd see that the function is conditionally defined, and because of this, its definition must occur before you call the function:
<?php
if (isset($_COOKIE['votfed']) && $_COOKIE['vofted'] == 'true') {
// ...
} else {
// ...
$username = preg_replace("/[^A-Za-z0-9_]+/", '', $username);
if (Votifier($public_key, $server_ip, $server_port, $username)) {
echo 'Success!';
} else {
echo 'Error!';
}
function Votifier($public_key, $server_ip, $server_port, $username)
{
// ...
}
// ...
}
?>
Essentially, you are executing this code:
<?php
if( false) {
} else {
if( foo()) {
echo 'Foo!';
}
function foo() {
return true;
}
}
Which should show you that foo() is not defined until after the else executes, but you call foo() at the beginning of the else block (before it's defined).
Your function should be outside of the if statement, like this:
<?php
function Votifier($public_key, $server_ip, $server_port, $username)
{
// ...
}
if (isset($_COOKIE['votfed']) && $_COOKIE['vofted'] == 'true') {
// ...
} else {
// ...
$username = preg_replace("/[^A-Za-z0-9_]+/", '', $username);
if (Votifier($public_key, $server_ip, $server_port, $username)) {
echo 'Success!';
} else {
echo 'Error!';
}
// ...
}
Alternatively, you can place it at the beginning of the else block, but I wouldn't recommend it from a readability standpoint.
I have a problem while processing the register
Here is the code for the function:
<?php
include $_SERVER['DOCUMENT_ROOT']. "/config/config.php";
$conn = new PDO('mysql:host=' . $ip . ';dbname=' . $database, $username, $password);
function registerUser($username, $password, $passwordagain, $email, $mcname)
{
$validusername= "/^[a-z0-9]+$/";
$validpassword= "/^[A-Za-z0-9]+$/";
$validemail= "/^([a-zA-Z0-9_\.\-])+\#(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/";
$validmcname= "/^[A-Za-z0-9]+$/";
$error = 0;
if(strlen($username)<4 || strlen($username)>24)
{
$error = 1;
}
if(strlen($password)<6 || strlen($password)>24)
{
$error = 1;
}
if(strlen($mcname)<4 || strlen($mcname)>24)
{
$error = 1;
}
if(!preg_match($validusername, $username))
{
$error = 1;
}
if(!preg_match($validpassword, $password))
{
$error = 1;
}
if(!preg_match($validemail, $email))
{
$error = 1;
}
if(!preg_match($validmcname, $mcname))
{
$error = 1;
}
if($password != $passwordagain)
{
$error = 1;
}
$userexistquery = $conn->query('SELECT * FROM users WHERE username=' . $username);
$userexist = $userexistquery->fetch();
if(count($userexist) != 0)
{
$error=1;
echo "<div class='erroralert'>Username already exists!</div>";
}
$emailexistquery = $conn->query('SELECT * FROM users WHERE email=' . $email);
$emailexist = $emailexistquery->fetch();
if($emailexist != 0)
{
$error=1;
echo "<div class='erroralert'>E-mail already exists!</div>";
}
if($error != 1)
{
$encryptedpassword = hash('sha512', $password);
$registeruser = $conn->query("INSERT INTO users(username, password, email, mcname) VALUES ('$username', '$encryptedpassword', '$email', '$mcname')");
echo "<div class='successalert'>Succesfully registred</div>";
}
else
{
echo "<div class='erroralert'>An error occured during registration.</div>";
}
}
?>
The error that gives me is:
Notice: Undefined variable: conn in C:\xampp\htdocs\functions\functions.php on line 45
Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\functions\functions.php on line 45
You instantiate your variable $conn outside of the function. You have to pass it as an argument in order to use it inside.