PHP - Undefined Error
What causes this error??
Quote Notice: Undefined index: firstname in /Users/user1/Documents/DEV/htdocs/index.php on line 2 TomTees Similar TutorialsHi, I am very new to PHP and I am trying to execute the below code but getting these errors : Notice: Undefined variable: mysql_query in C:\wamp\www\process.php on line 16 Fatal error: Function name must be a string in C:\wamp\www\process.php on line 16 Code: <html><body> <?php mysql_connect("localhost","root",""); mysql_select_db("encryption") or die(mysql_error()); $username = $_POST['username']; $password = $_POST['password']; $mysql_query("INSERT INTO login (username,password) VALUES ('$username','$password')") or die(mysql_error()); ?> </body></html> ` $_POST['username'] & $_POST['password'] come from a previous page. I have no problem with that. Please help.. Thanks in advance. Undefined error
Why I am getting this error?
What I am trying archive -
I want to get the client location and stored in the database
Please advise me.
Thank you.
<!DOCTYPE html> <html> <body> <script> function geoFindMe() { var output ; if (!navigator.geolocation){ output.innerHTML = "<p>Geolocation is not supported by your browser</p>"; return; } else { function success(position) { var latitude = position.coords.latitude; var longitude = position.coords.longitude; return(output.innerHTML = '<p>Latitude is ' + latitude + '° <br>Longitude is ' + longitude + '°</p>'); }; function error() { output.innerHTML = "Unable to retrieve your location"; }; navigator.geolocation.getCurrentPosition(success, error); } } var x = geoFindMe(); alert(x); </script> </body> </html> Edited by thilakan, 03 October 2014 - 08:06 AM. Hi, I am testing out some simple code while trying out PHP OOP to connect to the MySQL DB. I am getting an undefined variable error, but not sure why. the test code is: <?PHP error_reporting(E_ALL); include('includes/db.php'); $db = new db(); $db->query("SELECT title FROM blog_posts WHERE id = '7'"); if($sql) { while($r = mysql_fetch_array($sql)) { echo $r['title']; } } ?> and the code to connect to the DB is: <?PHP class db { private $hostname; private $username; private $password; private $database; private $connect; private $select_db; public function db() { $this->hostname = ""; $this->username = ""; $this->password = ""; $this->database = ""; } public function open_connection() { try { $this->connect = mysql_connect($this->hostname,$this->username,$this->password); $this->select_db = mysql_select_db($this->database); } catch(exception $e) { return $e; } } public function close_connection() { try { mysql_close($this->connect); } catch(exception $e) { return $e; } } public function query($sql) { try { $this->open_connection(); $sql = mysql_query($sql); } catch(exception $e) { return $e; } $this->close_connection(); return $sql; } } ?> the specific error is... Code: [Select] Undefined variable: sql in E:\DBTest.php on line 9 Still new to PHP, trying to get around an error! Scenario is pretty simple, i'm trying to do a sample form validation via php, this is the code, Code: [Select] <?php if($_POST){ $t_name=trim($_POST["name"]); $t_email=trim($_POST["email"]); if($t_name==""){ $n_err=1; } elseif($t_email==""){ $e_err=1; } } ?> then towards the form fields i do this, Code: [Select] <?php if($n_err)echo "Please enter correct name"."</br"; ?> <?php if($e_err)echo "Please enter correct email"."</br>"; ?> But this gives an error Quote Notice: Undefined variable: n_err in C:\wamp\www\php\form\index.php on line 30 As far i see you can use php vars defined in section on others, only var inside function are local in nature if they are not using "global" prefix. Please help me figure out why im getting this error, i know it might be something simple, so kindly help, thanks! Hi, I'm trying to create a cms and keep getting an undefined index:action error message. I tried to use isset but then it just threw out a different error. The section of code that is causing the errors is: if ( $_GET['action'] != "login" && $_GET['action'] != "logout" && !$_SESSION['username'] ){ //ITS SHOWING 2 ERRORS WITH ACTION ON THIS LINE login(); exit; } switch ( $_GET['action'] ) { //IT ALSO HAS AN ERROR FOR ACTION ON THIS LINE case 'login': login(); break; case 'logout': logout(); break; I would really appreciate the help as it's been annoying me and i'm having a mental blog. Thanks in advance. I have a really simple e-mail form that I made a while ago. I'm trying to make a simple modification, but I'm getting a a logical error somewhere. The problem is with the one optional variable ($wholesale) that gets sent to the PHP script. If the user has clicked the box on the form and the $wholesale variable has something in it, the message gets sent without an error. But if the user leaves the box blank, nothing is in the variable and PHP has a problem with that. It'll still send the e-mail, but I get a Notice: Undefined index: wholesale in /file/path/on our/sever.com/send_form_email.php on line 35 error. Here's a part of the code: // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['street_address']) || !isset($_POST['city']) || !isset($_POST['state']) || !isset($_POST['zip']) || !isset($_POST['phone'])) { died('We are sorry, but there appears to be a problem with the form your submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $street_address = $_POST['street_address']; // required $city = $_POST['city']; // required $state = $_POST['state']; // required $zip = $_POST['zip']; // required $phone = $_POST['phone']; // required $wholesale = $_POST['wholesale']; // not required // I don't see why this isn't solving the problem if ( $_POST['wholesale'] == null ) { $wholesale = "."; } ... then the code formats and sends the e-mail out. Any help would be awesome... this is such a simple thing that I honestly can't think of what else to try... I get an undefined offset error when i try and call the array i made i know very little so I'm stuck and i don't know what to do Code: [Select] <?php $file = fopen("playerstats.csv","r"); $data = array(); while (($csv_line = fgetcsv($file, 0, ";")) !== FALSE) { echo $csv_line; $number = $csv_line[0]; $name = $csv_line[1]; $half = $csv_line[2]; $goals = $csv_line[3]; $assists = $csv_line[4]; $SOG = $csv_line[5]; $shots = $csv_line[6]; $fouls = $csv_line[7]; $yellow = $csv_line[8]; $yellowred = $csv_line[9]; $red = $csv_line[10]; $CK = $csv_line[11]; $saves = $csv_line[12]; $data[] = array( 'name' => $name, 'half' => $half, 'goals' => $goals, 'assists' => $assists, 'sog' => $SOG, 'shots' => $shots, 'fouls' => $fouls, 'yellow' => $yellow, 'yellowred' => $yellowred, 'red' => $red, 'ck' => $CK, 'saves' => $saves ); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <table><tr><td>Number: </td><td><?php echo $data[0];?></td></tr></table> </body> </html> Hey Everyone. I've been using a piece of code several times before and its worked fine but now (after updating my php version) I get an error. Heres the code: Code: [Select] if(isset($_GET['id']) == TRUE){ if(is_numeric($_GET['id'])==FALSE) { $error = 1; } if($error == 1){ header("Location: " . $config_basedir); } else{ $validentry = $_GET['id']; } } else{ $validentry = 1; } The line with "if($error == 1){" gets flagged with an error saying: Notice: Undefined variable: error in C:\xampp\htdocs\sites\smd\index.php on line 8 I've used the code before with no problems and uploaded to my web server I also have no errors. What did I do wrong. I hope it isn't a seriously stupid error. Thanks in advance. Hi all, In my server at present php4 is running. upto now it is working fine.Suddenly it is showing lot of errors like Use of undefined constant or Undefined variable:. While trying in Google and all i came to know that the variable should be initialized and bounded by quotes.I checked in 1 file and it worked fine. But my coding is 99% completed and to change in every file is not an easy thing.Can anybody help regarding this Please? Here i'm having 1 more problem also which suffering me for a long time. I'm having one login form in this.That user session is working properly in Chrome but not in Mozilla.Even in Chrome once i try to logoff and relogin again it is behaving like in Mozilla. anybody please help me regarding these 2 issues.Thanks in advance. on line 53. Line 53 $ezdb->quick_insert('iid_ip', array('iid' => $_iid, 'ip' => $_ip)); The entire block of code /* Update table `iid_ip`. Between the dashed lines is the create statement used to create the image view count (iid_ip) table. ---------------------------------------- delimiter $$ CREATE TABLE `iid_ip` ( `iid` int(11) unsigned NOT NULL COMMENT 'Image id from where the count is the number of unique views.', `ip` varchar(15) NOT NULL COMMENT 'The ip of the visitor.', PRIMARY KEY (`iid`), KEY `ip` (`ip`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Table for view count of image using unique ip''s.'$$ ---------------------------------------- */// Escape variables that are used in the query. $_ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']); $_iid = mysql_real_escape_string($imageid); // Count is 0 if ip has NOT seen the images, else count is 1 $_count = $ezdb->get_var("SELECT COUNT(*) FROM `iid_ip` WHERE `iid`='$_iid' AND `ip`='$_ip'"); if (!$_count) { // Insert the unique combination of image id and visitor ip in `iid_ip`. $ezdb->quick_insert('iid_ip', array('iid' => $_iid, 'ip' => $_ip)); } // Get count of image views. $_views = $ezdb->get_var("SELECT COUNT(*) FROM `iid_ip` WHERE `iid`='$_iid'"); // And format, thousands seperator is a comma, no decimals. $_views = number_format($_views, 0, '', ','); ///////////////////////////// I am trying to delete some videos. The videos are echo'd out individually with their own 'delete' input. The input value takes the id of the video, I didn't know of any other work around for that. I'd like to delete the video that corresponds with the button pressed, if that makes sense. Anyways, I would like to delete the video where the video id is equal to the video id of the input or the value of the input pressed. I am positive the way I am carrying this out is not correct, as I am thrown an 'index undefined error'. Here is the disgusting code at hand. Recommendations are appreciated, but please try and keep answers in line with the relevant information given. Thank You.
<?php error_reporting(-1); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); require('dbcon/dbcon.php'); include('header.php'); include('user.php'); $channel_id = $_SESSION['channel_id']; $query = $pdo->prepare("SELECT * FROM videos001 WHERE uploader = :channel_id"); $query->bindValue('channel_id', $_SESSION['channel_id']); $query->execute(); while ($row = $query->fetch(PDO::FETCH_ASSOC)) { $title = $row['video_title']; $video_path = $row['video_path']; $video_id = $row['video_id']; /* - get videos of user - display videos out onto page */ ?> <html> <body> <div class="content"> <form method="post"> <h3><?php echo $title; ?></h3> <input type="button" name="delete" id="delete" value="<?php echo $video_id;?>" onclick="deleteVideo()"> </form> </div> </body> </html> <?php } function removeVideoFromFilesystem(PDO $pdo, $video_path, $video_id) { //chdir($video_path); //unlink($video_id . ".mp3"); $query = $pdo->prepare("DELETE from videos001 where video_id = :video_id"); $query->bindValue(':video_id', $_POST['delete']); $query->execute(); } if (isset($_POST['call_func'])) { removeVideoFromFileSystem($pdo, $video_path, $_POST['delete']); } ?> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> function deleteVideo() { $.ajax({ url: 'dashboard.php', type: 'post', data: {"call_func":"1"}, success: function(response) { console.log(response); } }); } </script> </head> <body><?php print_r($_POST['delete']); ?></body> </html>
Hi everyone... please help me with this. I have a gallery that I am working on. Part of that are two files upload.php and preupload.php which upload pics. And it does its job successfully BUT it shows an error 'Notice: Undefined offset: 9 in C:\wamp\www\upload.php on line 34' My line 34 is Code: [Select] if($photos_uploaded['size'][$counter] > 0). My whole code for the upload.php is <?php include("config.inc.php"); // initialization $result_final = ""; $counter = 0; // List of our known photo types $known_photo_types = array( 'image/pjpeg' => 'jpg', 'image/jpeg' => 'jpg', 'image/gif' => 'gif', 'image/bmp' => 'bmp', 'image/x-png' => 'png' ); // GD Function List $gd_function_suffix = array( 'image/pjpeg' => 'JPEG', 'image/jpeg' => 'JPEG', 'image/gif' => 'GIF', 'image/bmp' => 'WBMP', 'image/x-png' => 'PNG' ); // Fetch the photo array sent by preupload.php $photos_uploaded = $_FILES['photo_filename']; // Fetch the photo caption array $photo_caption = $_POST['photo_caption']; while( $counter <= count($_FILES['photo_filename']['tmp_name']) ) { if($photos_uploaded['size'][$counter] > 0) { if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types)) { $result_final .= "File ".($counter+1)." is not a photo<br />"; } else { mysql_query( "INSERT INTO gallery_photos( `photo_filename`, `photo_caption`, `photo_category` ) VALUES( '0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."')" ) or die(mysql_error() . 'Photo not uploaded'); $new_id = mysql_insert_id(); $filetype = $photos_uploaded['type'][$counter]; $extention = $known_photo_types[$filetype]; $filename = $new_id.".".$extention; mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" ); // Store the orignal file copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$filename); // Let's get the Thumbnail size $size = GetImageSize( $images_dir."/".$filename ); if($size[0] > $size[1]) { $thumbnail_width = 200; $thumbnail_height = (int)(200 * $size[1] / $size[0]); } else { $thumbnail_width = (int)(200 * $size[0] / $size[1]); $thumbnail_height = 200; } // Build Thumbnail with GD 1.x.x, you can use the other described methods too $function_suffix = $gd_function_suffix[$filetype]; $function_to_read = "ImageCreateFrom".$function_suffix; $function_to_write = "Image".$function_suffix; // Read the source file $source_handle = $function_to_read ( $images_dir."/".$filename ); if($source_handle) { // Let's create an blank image for the thumbnail $destination_handle = ImageCreateTrueColor ( $thumbnail_width, $thumbnail_height ); // Now we resize it ImageCopyResized( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1] ); } // Let's save the thumbnail $function_to_write( $destination_handle, $images_dir."/tb_".$filename, 99 ); ImageDestroy($destination_handle ); // $result_final .= "<img src='".$images_dir. "/tb_".$filename."' /> File ".($counter+1)." Added<br />"; } } $counter++; } // Print Result echo <<<__HTML_END <html> <head> <title>Photos uploaded</title> </head> <body> $result_final </body> </html> __HTML_END; ?> I get this error
Notice: Undefined index: loggedIn in C:\xampp\htdocs\Login\web_dir\index.php on line 6The code for line 6 is if($_SESSION['loggedIn'] !== 1) { I am trying to display some text "THIS IS A TEST" on the html page. I am getting this error: Notice: Undefined variable: text1 in /home/public_html/themes/videos/content.html on line 23
line 23 is this: <div class="test"><font color="#696969" font size="3" face="Arial">HELLO<?php echo $text1;?></font> The php file, related to the html page shows this (partially):
$text1 = "THIS IS A TEST"; $cateogry_id = ''; $videos = array(); if ($page == 'trending') { $title = $lang->trending; $db->where('privacy', 0); $videos = $db->where('time', time() - 172800, '>')->orderBy('views', 'DESC')->get(T_VIDEOS, $limit); } else if ($page == 'latest') { $title = $lang->latest_videos; echo "$text1"; $db->where('privacy', 0); $videos = $db->orderBy('id', 'DESC')->get(T_VIDEOS, $limit); } else if ($page == 'top') { $title = $lang->top_videos; $db->where('privacy', 0); $videos = $db->orderBy('views', 'DESC')->get(T_VIDEOS, $limit); } else if ($page == 'category') { if (!empty($_GET['id'])) { if (in_array($_GET['id'], array_keys($categories))) { $cateogry = PT_Secure($_GET['id']); $title = $categories[$cateogry]; $cateogry_id = "data-category='$cateogry'"; $db->where('privacy', 0); $videos = $db->where('category_id', $cateogry)->orderBy('id', 'DESC')->get(T_VIDEOS, $limit); } else { header("Location: " . PT_Link('404')); exit(); } } } what do I need to correct to remedy the error? Any help is appreciated. Everything seems to be working like it should iam getting Undegined variable Error : return in /Applications/MAMP/htdocs/modernCMS/_class/cms_class.php on line 37. cms_class.php file Code: [Select] <?php class modernCMS { var $host; var $username; var $password; var $db; function connect() { $con = mysql_connect($this->host, $this->username, $this->password) or die(mysql_error()); mysql_select_db($this->db, $con) or die(mysql_error()); } function get_content($id = '') { if($id != ""): $id = mysql_real_escape_string($id); $sql = "SELECT * FROM cms_content WHERE id = '$id'"; $return = '<p><a href="index.php">Go Back To Content</a></p>'; else: $sql = "SELECT * FROM cms_content ORDER BY id DESC"; endif; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) != 0): while($row = mysql_fetch_assoc($res)) { echo '<h1><a href="index.php?id=' . $row['id'] . '">' . $row['title'] . '</a></h1>'; echo '<p>' . $row['body'] . '</p>'; } else: echo '<p>Uh Oh!, this doesn\'t exist!</p>'; endif; echo $return; } } //Class ends here index.php ?> Code: [Select] <?php include '_class/cms_class.php'; $obj = new modernCMS(); $obj->host = 'localhost'; $obj->username = 'root'; $obj->password = 'root'; $obj->db = 'modernCMS'; $obj->connect(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <link rel="stylesheet" href="style.css" type="text/css" media="screen" title="no title" charset="utf-8"> </head> <body> <div id="page-wrap"> <?php if(isset($_GET['id'])): $obj->get_content($_GET['id']); else: $obj->get_content(); endif; ?> </div> </body> </html> if anyone could help would be great. thanks. How do I get my session to be unset? My form looks like this: foreach ($joined as $i => $qty){ echo "<form action='' method='get' name='yourForm'>"; echo "<button type='submit' name='remove_" . $i . "' value='remove_" . $i . "' class='deletebtn' >X</button>"; echo "</form>"; } My SESSION is defined like this: for($i=0; $i<=5; $i++){ if (isset($_REQUEST["element_id_$i"]) ) { $_SESSION["element_id_$i"] = $_REQUEST["element_id_$i"]; $id = $_SESSION["element_id_$i"]; array_push($_SESSION["element_id"],$id); } $id = $_SESSION["element_id"]; } and the form submits to: if (isset($_REQUEST["remove_$i"]) ){ unset($_SESSION["quantity[$i]"]); unset($_SESSION["element_id[$i]"]); var_dump($_SESSION["element_id"]); var_dump($_SESSION["quantity"]); echo "Received variable " . $_REQUEST["remove_$i"]; echo 'TARGET INDEX TO BE REMOVED: ' . $_SESSION["element_id[$i]"] . '<br><br>'; } The output is:
array(1) { [0]=> string(1) "1" } array(1) { [0]=> string(1) "1" } Received variable remove_1 After recent updates to a wordpress site (updated non-related plugins, changed theme), the php code snippets are shooting back an error at the end of the feeds -- which were previously working fine for years. no other changes were made.
Notice: Undefined variable: response in /nas/content/live/usafact/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(26) : eval()'d code on line 8
URL: PHP code: function do_post($url, $params) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $result = curl_exec($ch); curl_close($ch); return $response; } echo do_post("https://content.newbenefits.com/Feednocss.aspx", "hash=hDSJYjIb56KfGtxWE0I3OQ&Section=short_b2c"); The plugin developer said to replace $response with $result, but that did not work. Same error shows. Can someone please assist? Hi I am working on a php module and I am getting this "Notice: Undefined index:" Error. Now I know that I can change my php settings to not show the error but I would like to fix it properly. What am I doing wrong? <?php function _com_slider_image_styles() { $styles = &drupal_static(__FUNCTION__); // Grab from cache or build the array. if (!isset($styles)) { if ($cache = cache_get('image_styles', 'cache')) { $styles = $cache->data; } else { // Select all the user-defined styles. $user_styles = db_select('image_styles', NULL, array('fetch' => PDO::FETCH_ASSOC)) ->fields('image_styles') ->orderBy('name') ->execute() ->fetchAllAssoc('name', PDO::FETCH_ASSOC); } } $com_styles = null; foreach($styles as $key => $value){ $com_styles[$key] .= $key; // PROBLEM HERE! } return $com_styles; } ?> This is what I'm getting... Notice: Undefined variable: sitetitle in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: ADcode in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: email in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: url in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: charge in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: currency in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: price in /home/vehiclep/public_html/functions.php on line 121 this is functions.php Code: [Select] function sitesets() { $sql = "select * from settings limit 1"; $rs = mysql_query($sql); $row = @mysql_fetch_array($rs); extract($row); $sitesets = array("title"=>$sitetitle, "ADcode"=>$ADcode, "email" => $email, "url" => $url, "charge" => $charge, "currency" => $currency, "price" => $price); return $sitesets; } Ive tried going into phpMyadmin and creating a row and entering the info manualy but it doesnt work. I don't know much about coding so this may be a dumb question but it has me stumped. I hope somebody can tell me what I'm missing here. Hello i am new to this forum and coding. I am trying to fix a auto torrent downloading script which is php and curl. I have been stucked with Undefined offset error. Your help will be very appretiated, thanks. Starting download: Mp3-data1 Notice: Undefined variable: temp in /var/www/html/torrents/bgrahul2.php on line 338 Array ( => HTTP/1.1 200 OK Server: Transmission Content-Type: application/json; charset=UTF-8 Date: Wed, 21 Sep 2011 19:58:44 GMT Content-Length: 49 {"arguments":{"torrents":[]},"result":"success"} [1] => ) Marked those lines to bold Quote $result = callTransmission(array("filename" => "/var/www/html/donofwarez/xxx/torrents/$torrentfile", "download-dir" => "/home/Downloads/$title/"), "torrent-add", $arr[1]); callTransmission(array("seedRatioLimit" => 50, "seedRatioMode" => 1), "torrent-set", $arr[1]); /* echo "<pre>"; print_r($result); echo "</pre>"; */ if (preg_match('/"percentDone":[0-9.]+/i', $result[0], $matches)) $temp = str_replace('"id":', "", $matches[0]); // $temp="hlDr1wqu2ONtM3McVGHoVzfrkp2UgUcGwDt66IuxAe0LBkru"; $id[0] = $temp; //***OMG! We need the ids as integers! *** foreach ($id as $key => $value) { $id[$key] = (int) $value; } |