How I can create function prev_id for example code using mysqli_fetch_array:
$idprev = prev_id();
$sql = "SELECT * FROM site WHERE id='$idprev' ";
This function not exist in php.
Fatal error: Uncaught Error: Call to undefined function prev_id()
you need to define function prev_id() first before using it.
<?php
function prev_id()
{
// your code lines
return $yourvariable;
}
?>
Related
I am new to OOP php and took some lessons and now Im trying to practice, I used login with discord method and If user Is logged in the system sould add the discord id to database if user is not already in database but Im facing quite the issue and I have no luck so far to fix It myself, I even asked few of my buddies If they can see the issue but they did not also know the real issue.
My error:
[22-Jul-2022 06:56:00 UTC] PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function
SignupContr::signupUser(), 0 passed in C:\wamp64\www\OOP-Test\inc\signup.inc.php on line 13
and exactly 1 expected in C:\wamp64\www\OOP-Test\classes\signup-contr.class.php:10
Stack trace:
#0 C:\wamp64\www\OOP-Test\inc\signup.inc.php(13): SignupContr->signupUser()
#1 C:\wamp64\www\OOP-Test\dashboard\index.php(12): include('C:\\wamp64\\www\\O...')
#2 {main}
thrown in C:\wamp64\www\OOP-Test\classes\signup-contr.class.php on line 10
My code looks like this right now:
signup.inc.php
{
$discord = $_GET['user'];
include "../classes/dbh.class.php";
include "../classes/signup.class.php";
include "../classes/signup-contr.class.php";
$signup = new SignupContr($discord);
$signup->signupUser();
//header('location: ../dashboard/index.php');
}
signup.class.php
class Signup extends Dbh {
protected function setUser($discord){
$stmt = $this->connect()->prepare("INSERT INTO `users` ('discord') VALUES (?);");
if(!$stmt->execute(array($discord))) {
// $stmt = null;
// header("location: ../dashboard/index.php?useraddfailed");
// exit();
}
$stmt->debugDumpParams();
$stmt = null;
}
}
signup-contr.class.php
class SignupContr extends Signup{
private $discord;
public function _construct($discord){
$this->discord = $discord;
}
public function signupUser(){
$this->setUser($this->discord);
var_dump($this->discord);
}
}
I have not done the check part If user Is allready In the database
I Finally found the issue. I was missing one underscore in construct.
signup.contr.class.php should be like this:
class SignupContr extends Signup{
private $discord;
public function __construct($discord){
$this->discord = $discord;
}
public function signupUser(){
$this->setUser($this->discord);
var_dump($this->discord);
}
}
Of course it was the simplest issue there Is but I really tought there suppost to be only one underscore. You always should check the simple things first, I did not because usally you don't use construct In procedural php
I booted up wamp today to check something for one of my website and ran across a php error
[30-Jan-2022 16:57:28 UTC] PHP Fatal error: Uncaught Error: Call to a member function prepare() on boolean in C:\wamp64\www\includes\class.database.php:130
Stack trace:
When checking the php file in question i have no idea how to fix this, anyone that can help?
// Allow for prepared arguments. Example:
// query("SELECT * FROM table WHERE id = :id", array('id' => $some_val));
$sth = $this->db->prepare($sql);
$debugSql = $sql;
$params = array();
if (is_array($args_to_prepare))
{
foreach ($args_to_prepare AS $name => $val)
{
$params[':' . $name] = $val;
$debugSql = preg_replace('/:'.$name.'/',"'".$val."'", $debugSql);
}
}
The best way to reuse functions is to put it inside of the include file, then include it at the top of each file you'll need it. So inside of your db_connection.php, create your function:
Click this
I am trying to update one of the sites I maintain to the latest PHP and during this, I have come across the following error:
Fatal error: Call to undefined function tep_session_name() in ... /includes/application_top.php on line 83
The code it is referring to is:
// set the session name and save path
tep_session_name('osCAdminID');
tep_session_save_path(SESSION_WRITE_DIRECTORY);
But I have looked at the sessions.php file are the function is defined in the below code:
function tep_session_name($name = '') {
if ($name != '') {
return session_name($name);
} else {
return session_name();
}
}
Any help in identifying the cause would be greatly appreciated.
Thanks, E.
I'm absolutely sure, that you call this function before you include file with function declaration
I have the code in question:
function get_installed_languages()
{
global $sql;
$languages = Array();
$sql->query("SELECT short_name FROM languages ORDER BY short_name");
if($sql->getNumRows()==1)
{
$languages[0] = "default";
return $languages;
}
else
{
for ($i=0; $i<$sql->getNumRows(); $i++)
{
$get = $sql->getRow($i);
if(trim($get['short_name'])=='')
$languages[$i]='default';
else
$languages[$i] = strtolower($get['short_name']);
}
return $languages;
}
}
It always returns:
Fatal error: Call to a member function query() on a non-object
The problematic line is:
(742): $sql->query("SELECT short_name FROM languages ORDER BY short_name");
Here is the complete file.
Thanks for your help. It turned out to be an invalid path in the DB.
I am really graceful for your efforts in trying to help me!
Otherwise, you can check the whole file (if still interested). A link to it has been posted at the end of my original comment.
Cheers!
I have this function:
public static function getOrdini($sort_order = 4)
{
$con = Propel::getConnection();
$sql = "select * from shop_orders LEFT JOIN shop_orders_total
ON
shop_orders.orders_id = shop_orders_total.orders_id
AND
shop_orders_total.sort_order = :sort_order";
$stmt = $con->prepare($sql);
$result = $stmt->execute(array(':sort_order' => $sort_order));
$ordini = self::populateObjects($stmt);
return $ordini;
}
When I call it I get this error:
( ! ) Catchable fatal error: Object of
class Criteria could not be converted
to string in
/home/javier/Aptana_Studio_Workspace/dev_repo/lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel/util/DebugPDOStatement.php
on line 99
but if write the function in this way below I don't get any error:
public static function getOrdini()
{
$sort_order = 4;
$con = Propel::getConnection();
...
Any idea?
Regards
Javi
No bug in the above code it is okay. I tried passing value in the static method and it is fine the error is being generated from the other part of your code checking in the class Criteria would help you here is nothing in the posted.
Ask to propel, symfony. here someone is facing the same problem
http://symfonyexperts.com/question/show/id/51