PHP - Invalid Record! Key Is Null
Dont understand why...my database is displayed correctly but cant seem to add edit delete etc, I just get the error above. Any clues please
Similar TutorialsI am trying to update the database with isset to set the value of the variable to either null or the value entered by the user. Currently, if no value has been entered null is being set as a string causing the date field to populate with zeros. How do I code it so that it populates or sets the value as null and not as string null?
Here's my code: (yes I know sql injections it's still in development )
<?php How can I prevent someone from making an ivalid selection in a form? Lets say I had a select dropdown box and someone saved the HTML source from the browser, changed an item in the list, and changed the action to point back to my server eg. action="testsite.com/index.php". Then they open the file and try to submit the form.
Code: [Select] function conectar_bd($nombre_bd=$reg->getConf("Nombre bd"), $host=$reg->getConf("Host bd"), $usuario=$reg->getConf("Usuario bd") ) { Whats wrong with this code? it dont work. I have a class (P3TElement) that extends the DOMElement class in PHP. In there i have a public variable "attributes" which is an array, and an method named add_attribute($attr), the argument is a different class (P3TAttribute). However I am getting an error when trying to use it. The exact error is: Warning: P3TElement::add_attribute() [p3telement.add-attribute]: Invalid State Error in D:\www\p3textract\extract.php on line 110 Please see the code: http://pastebin.com/CbsM9V5W This class is supposed to extract .p3t (ps3 themes) files, and is a direct port of the python equivalent found at http://p3textractor.googlecode.com/svn/trunk/p3textractor.py Could you please help me fix this? thanks in advance, Hosh putenv('GDFONTPATH=C:\Windows\Fonts') ; Hi I have a couple of phpbb forums on my web space. One is randomly throwing people off and it is getting far worse. I have traced down the issue to the IP address. Phpbb stores the IP address and session id and checks that they match. If not it throws the user out. The session ids seem to be there OK, but the IP addresses aren't. When it causes a problem the IP address seems to be returned as "::" (yes, 2 colons). I have used the following routine to try and obtain a relevant IP address and it to returns "::" Code: [Select] function getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; } Any ideas? All the best Keith Hi, I've been looking at this for a couple of hours and it's killing me a little inside. I've butchered a few pieces of code from various sources together and come up with this. I understand how it's supposed to work (or i'm pretty sure i do) but the foreach statement is giving me the following error: Warning: Invalid argument supplied for foreach() /document/etc/etc on line 80 Obviously the offending statement is this one: Code: [Select] <?php // Check if button name "Submit" is active, do this if($_SERVER['REQUEST_METHOD'] == "POST") { foreach($_POST['id'] as $id) { $update="UPDATE users SET firstname='" . $_POST["firstname".$id] . "', lastname='" . $_POST["lastname".$id] . "', email='" . $_POST["email".$id] . "', password='" . $_POST["password".$id] . "', adminid='" . $_POST["adminid".$id] . "' WHERE id='" . $id . "'"; $result = mysql_query($update); echo "Updated"; } } ?> Not a clue what the problem is atm. If someone could either tell me or point me in the right direction i'd appreciate it/ Reece When I call load_new_flows.php with Ajax to update the content, I got "Warning: Invalid argument supplied for foreach() in load_new_flows.php on line 4", but with the load_flows.php everything is ok. index.php Code: [Select] <?php error_reporting(0); include 'includes/db.php'; include 'includes/functions.php'; include 'includes/tolink.php'; include 'includes/time_stamp.php'; include 'includes/facebook/fbmain.php'; $brainflow = new brainflow(); // TEST // ------------------------------------ $level = 1; //overflowing = 3, flowing = 2, fresh = 1 // ------------------------------------ $flowsarray = $brainflow -> get_flows($level); $newflowsarray = $brainflow -> get_new_flows($level); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type = "text/javascript" src = "js/brainflow.js"></script> <title>test</title> </head> <body> <br /><br /> <div id="new"></div> <br /><br /> <div id ="flows"> <?php // LOAD FLOWS // ------------------------------------ include 'load_flows.php'; // ------------------------------------ ?> </div> </body> </html> load_new_flows.php Code: [Select] <?php foreach($newflowsarray as $data) { $new_flow_id = $data['flow_id']; $new_owner_id = $data['user_id_fk']; $new_owner_facebook_id = $data['facebook_id']; $new_flow = tolink(htmlentities($data['flow'])); $new_time = $data['time']; $new_owner_name = $data['name']; //$commentsarray = $brainflow -> get_comments($flow_id); ?> <div class="flow" id="<?php echo $new_flow_id; ?>"> <img src="images/pictures/<?php echo $new_owner_facebook_id; ?>.png"> <?php echo $new_owner_name; ?> <?php echo $new_flow; ?> <?php echo time_stamp($new_time); ?> </div> <?php } ?> load_flows.php Code: [Select] <?php foreach($flowsarray as $data) { $flow_id = $data['flow_id']; $owner_id = $data['user_id_fk']; $owner_facebook_id = $data['facebook_id']; $flow = tolink(htmlentities($data['flow'])); $time = $data['time']; $owner_name = $data['name']; //$commentsarray = $brainflow -> get_comments($flow_id); ?> <div class="flow" id="<?php echo $flow_id; ?>"> <img src="images/pictures/<?php echo $owner_facebook_id; ?>.png"> <?php echo $owner_name; ?> <?php echo $flow; ?> <?php echo time_stamp($time); ?> </div> <?php } ?> includes/functions.php Code: [Select] <?php class brainflow { // GET FLOWS public function get_flows($level) { $query = mysql_query("SELECT F.flow_id, F.user_id_fk, F.flow, F.time, U.name, U.facebook_id FROM flows F, users U WHERE F.user_id_fk = U.user_id AND F.level = '$level' ORDER BY F.flow_id DESC ") or die(mysql_error()); while($row = mysql_fetch_array($query)) $data[] = $row; return $data; } // GET NEW FLOWS public function get_new_flows($level) { $last_flow_id = $_POST['id']; $query = mysql_query("SELECT F.flow_id, F.user_id_fk, F.flow, F.time, U.name, U.facebook_id FROM flows F, users U WHERE F.user_id_fk = U.user_id AND F.flow_id > '$last_flow_id' AND F.level = '$level' ORDER BY F.flow_id DESC ") or die(mysql_error()); while($row = mysql_fetch_array($query)) $data1[] = $row; return $data; } } js Code: [Select] $(document).ready(function() { $("#new").click(function() { var id = $(".flow:first").attr("id"); datastring = 'id=' + id; $.ajax({ type: "POST", url: "load_new_flows.php", data: datastring, cache: false, success: function(html){ $("#flows").prepend(html); } }); }); }); Hi, I've inherited some html/php code (lucky me) and it's been years since i've played with it so I'm quite rusty. Anyway, I have a fairly bog standard login process and wish to simply display some text on the login page if the login detail is invalid and possibly log the error to a log file too. here's the index.php file...the login stuff is at the bottom Code: [Select] <?php $dir = dirname(__FILE__); require_once "$dir/ot/ot.php"; ot::include_view('header', array('account' => null)) ?> <html> <head> <title>Welcome to ....</title> </head> <body style="font-size: 14pt; font-family=verdana;"> <div><img src="OTLogo1.bmp"/><h1> Welcome to ...</h1> </div> <?php if (!empty($account)): ?> <div style="border-bottom: 1px dotted #AAA; padding-bottom: 2px; margin-bottom: 10px;"> <div style="float: left"> <?php $mtime = (int)@file_get_contents(otDB_DIR."/updated"); $date = date("d/m/Y", $mtime); $time = date("G:i", $mtime); if ($mtime > 0) { echo "Last Updated $date at $time"; } ?> </div> <div style="float: right">Welcome, <?php echo $account->email;?> - <a href="?page=home">Home</a> - <?php ot::include_view('logout_link')?></div> <div style="clear: both"></div> </div> <?php if (ot::is_admin()) { ot::include_view('admin_page'); } else { ot::include_view('user_page'); } ?> <?php else: ?> <p>Please login below.</p> <?php ot::include_view('login_form')?> <?php endif; ?> </body> </html> here's login_form.php Code: [Select] <form action='<?php echo $_SERVER['REQUEST_URI']?>' method='post' > <fieldset> <legend>Login</legend> <p>Email:<br/><input type='text' name='email' /></p> <p>Password:<br/><input type='password' name='pwd' /></p> <!-- <p><input type='submit' name='do_login' value='Login' /> <input type='submit' name='do_reset_password' value='Reset Password' /></p> --> <p><input type='submit' name='do_login' value='Login'/> </p> </fieldset> </form> and here's the function do_login (contained in ot.php..a php function file) Code: [Select] public static function do_login(&$err="") { $adb = ot::db('account'); $e = self::post('email'); $p = self::post('pwd', '', false); if (self::post('do_login') && $e && $p) { $ao = self::account_from('email', $e); if ($ao) { if (self::validate_login($e, $p, $ao)) { $_SESSION['id'] = $ao->id; return $ao; } } $err = "Invalid email or password"; return false; } } I'm unclear if the do_login fails as to how that ($err) is fed back to the web pages. Any assistance would be greatly appreciated. I want to allow Alphabetical strings, Numeric strings, and Alphanumeric strings. For example "Bob", "1234", "bob1234" are all valid. I want to check if the string has invalid characters, return true if it does (or false, which ever method works). How can I do it? Hi guys, I have a problem with the print out method. I have got a warning implode, I have tried to get passed with the invalid arguments, but I keep getting this in nowhere I can find any situations. however I am still getting this: Warning: implode() [function.implode]: Invalid arguments passed in /home/mysite/public_html/mysite.com/members.php on line 82 Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where username='test' and passwd='test'' at line 1 here's line 82: if ($names = implode(',',$insert)) { And here's the update code: <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myuser'); define('DB_PASSWORD', 'mypass'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $firstname = clean($_GET['firstname']); //variable in the url you posted was firstname, not value. $lastname = clean($_GET['lastname']); $email = clean($_GET['email_address']); if($username == '') { $errmsg_arr[] = 'username ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD ID missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $query = "SELECT firstname, lastname, email_address FROM members WHERE username='$username' AND passwd='$password'"; $result=mysql_query($query) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result)) { echo "<p id='myfirstname'>"; echo $row['firstname'] . "</p>"; echo "<p id='mylastname'>"; echo $row['lastname'] . "</p>"; echo "<p id='email_address'>"; echo $row['email_address'] . "</p>"; } $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password' AND firstname='$firstname' AND lastname='$lastname'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result) > 0) { $row = mysql_fetch_row($result); // echo "The information have already been updated in the database"; } else { if(isset($_GET['firstname'])) { $insert[] = 'firstname = \'' . clean($_GET['firstname']) .'\''; } if(isset($_GET['lastname'])) { $insert[] = 'lastname = \'' . clean($_GET['lastname']) . '\''; } if(isset($_GET['email_address'])) { $insert[] = 'email_address = \'' . clean($_GET['email_address']) . '\''; } if ($names = implode(',',$insert)) { // $names = implode(',',$insert); } else { $sql="UPDATE members SET {$names} where username='{$username}' and passwd='{$password}'"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo "The information have been updated"; } } } ?> Can someone help me how to ignore the warning implode when I did not included the $name method?? hello, whats wrong with this loop ? Code: [Select] <?PHP require_once("../includes/initialize.php"); $pName == "adminHome"; $currentPage = Pages::find_by_pageName($pName); $topNavs = NavL1::find_all(); ?> <div id="navWrapper"> <div id="ddtabs3" class="solidblockmenu"> <ul> <?PHP foreach ($topNavs as $topNav){ $L1nav_id = $topNav->id; $L1navPages_id = $topNav->pages_id; $L1navTitle = $topNav->title; foreach ($currentPage as $currentPages){ $L1page_id = $currentPages->id; $L1pageName = $currentPages->pageName; } if($L1navPages_id == $L1page_id){ $L1nav_selected='class="selected"'; }else{ $L1nav_selected=''; } echo '<li><a '.$L1nav_selected.' href="'.$L1pageName.'.php" id="'.$L1nav_id.'">'.$L1navTitle.'</a></li>'; } ?> </ul> </div> </div> ?> i get this error for each of the tabs Code: [Select] Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/djsonrotation/admin/templates/template1/includes/topCont.php on line 21 I am having problem with my edit.php page, Keep on getting Invalid argument supplied for foreach() My edit.php is suppose to get the drop down list from the first page. and replace the string [Replace] with whats in the list box But it has to Use the first thing in the list box 2 times, and ect. Code: [Select] <form method="post" action="edit.php" > <select name="drop1"> <?php echo $dropdownOptions; ?> </select> <input type="submit" value="drop1" /> </form> Edit.php Code: [Select] <? $file = file_get_contents('myfile.txt'); foreach($_POST['drop1'] as $replace) { $file = preg_replace('#\[Replace\]#', $replace, $file, 2); } ?> hi, is there a way that i can insert into a mysql text box even if there is unsupported characters in the field. for instance, if i want to insert: When I arrived onsite, the cable for usb to ps/2 wasn't with the pc anymore. I need to get a usb to ps/2 cable, as well as a dvi to vga adapter. I will return tomorrow to finish. and i want to keep the invalid characters like the /, and i also want to keep it on 3 seperate lines. can this be done? Hello All,
I have searched these forums and the net but haven't found an exact answer. I have a "path" (could be paths) that is/are causing warnings as it/they is/are poorly formed. This is bloating our logs, therefore I need to alleviate the issue. There are thousands of paths in the database so I do not know which are causing issues. I know I can add the "@" to the call to quiet the warning. First question: does that keep the warning from going into the logs?
I would prefer not to use the method above as it bypasses the real issue. Looking at the SimpleXMLElement documentation along with DOMDocument and DOMXPAth, I can't find a way to validate the actual path. All of the below throw a warning or notice: $xpath->evaluate($path); $xpath->query($path); $node->xpath($path); Final question: Is there a "simple" way to validate the $path prior to actually making the call to one of the methods of the various XML PHP classes?
Thank you for your time and assistance. Edited November 5, 2020 by oachHi sorry for the trouble guys but i'm really stuck on this one, and i've tried everything i can. (I've been using php only for sometime now) I'm stuck at this code and can't figure out why this is failing. Objective of the script : To try and include BOTH files or throw and exception if even one fails. I tried : Including just one at a time. Its fine, so i know the path is correct. I tried a if (! (expr1 && expr2) ) statement to check if the syntax is correct to create a everything or nothing logic. $offlineLibraryPath = '/var/www/common/lib'; // Attempt to include the files try { if(! ( require_once($offlineLibraryPath.'/variables/all.php') && require_once($offlineLibraryPath.'/functions/all.php') ) ) { throw new Exception ('Including all the common library files failed.'); } } catch (Exception $e) { echo '<b>Error</b> :'.$e->getMessage(); } I get this error : Warning: require_once(1): failed to open stream: No such file or directory in /var/www/common/lib/startupIncludes.php on line 18 Fatal error: require_once(): Failed opening required '1' (include_path='/var/www/common/lib/: /var/www/culturesque/lib/: /var/www/mine/lib/') in /var/www/common/lib/startupIncludes.php on line 18 Thanks in advance for the help! I have a piece of code that works on one domain but not on another. On the domain running php 5.1 all is ok. On the domain running php 4.4 I get this error: SMTP server response: 501 5.5.4 Invalid Address Hosting service keeps telling me there must be an error in the code. If that's the case why would it work on version 5.1? Here is the code, I don't know what could be wrong. Any help will be greatly appreciated. <?php // set flag to indicate whether mail has been sent $mailSent = false; $sent = false; if (array_key_exists('sendComments', $_POST)) { // mail processing script // remove escape characters from POST array if (get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } $_POST = array_map('stripslashes_deep', $_POST); } // validate the input, beginning with name $name = trim($_POST['name']); if (empty($name)) { $error['name'] = 'Please enter your name'; } $phone = trim($_POST['phone']); $email = $_POST['email']; // check for valid email address $pattern = '/^[^@]+@[^\s\r\n\'";,@%]+$/'; if (!preg_match($pattern, trim($email))) { $error['email'] = 'Please enter a valid email address'; } // check the content of the text area $messageBody = trim($_POST['message']); if (empty($messageBody)) { $error['message'] = 'Please enter your message'; } // initalize variables $to = 'jim@independent-micro.com'; $subject = 'Feedback from PCI-Controls web site'; // build the message $message = "From: $name\n\n"; $message .= "Email: $email\n\n"; $message .= "Phone Number: $phone\n\n"; $message .= "Comments: $messageBody"; // build additional headers $additionalHeaders = "From: PCI Controls Web Site<$email>\r\n"; $additionalHeaders .= "Reply-To: $email"; // send the mail if ther are no errors if (!isset($error)) { $mailSent = mail($to, $subject, $message, $additionalHeaders); // check to see if sent successfully if (!$mailSent) { $error['notSent'] = 'Sorry there is a problem sending your message. Please try later.'; } else { $sent = true; } } } ?> I have the following code: if ( !empty($_GET['quantity']) ) { foreach ( $_GET['quantity'] as $order_code => $quantity ) { // line 13 $Cart->setItemQuantity($order_code, $quantity); } } and I'm getting the following error: Quote Warning: Invalid argument supplied for foreach() in shopping-cart/cart_action.php on line 13 $_GET['quantity']; has a value of '1' The code is working perfectly fine on localhost, but throws me that warning on my webserver(both have error reporting set to E_ALL) any help is greatly appreciated. Thanks. Hi all . In my scripts , there is a textbox that allow user to enter multiple phone number separate with "," , if all valid it will echo "ok!" else will echo "error" . How if I want to know which value is in wrong format? such as I entered "0112255666,445221122200" , then it will echo " 445221122200 is not a valid phone number" . And how to echo the total phone number inserted to the textarea ? Thanks for every reply . Code: [Select] <?php if (isset($_POST["Submit"])) { $arrLines = split(",",$_POST['cellphonenumber']); foreach($arrLines as $cells){ if(!preg_match('/^[0]{1}[1]{1}[0-9]{1}[0-9]{7}?$/', $cells)){ echo "error"; } else{ echo "ok!"; } } } ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" name="myform" method="post"> <textarea name="cellphonenumber" rows="20" cols="100"></textarea> <input type="submit" name="Submit" /> </form> |