PHP - Php Error Skipping Comment Lines
This is new. For some reason, the PHP errors are not counting my //commented lines.
Example:
<?php //my comment : ?>Parse error: syntax error, unexpected ':' in D:\www\myscript.php on line 2 The error is on line 3. If I add more comments, the error is the same: <?php //my comment //my comment //my comment //my comment //my comment : ?>Parse error: syntax error, unexpected ':' in D:\www\myscript.php on line 2 Where is this setting? Thanks. Similar TutorialsHey, So what im trying to do is put my database variables into a session array. So this is what im trying to accomplish... $_SESSION['Name_of_Row'] = $value This is the script I wrote: Code: [Select] Function setupSession(){ session_start(); $query = "SELECT * FROM users WHERE u_id ='{$this->u_id}'"; $result = mysql_query($query); $row = mysql_fetch_array($result); foreach($row as $key => $value){ if(!empty($value)){ $_SESSION[$key] = $value; } } } When that runs I get the following warning. Can anyone tell me what this means and how to fix it? Error: Notice: Unknown: Skipping numeric key 0 in Unknown on line 0 i get the following error in the comments in wordpress blog..: Warning: preg_replace() [function.preg-replace]: No ending delimiter '~' found in /home/doughhhh/public_html/wp-content/themes/upload/includes/theme-comments.php on line 75 the content of the file is: Code: [Select] <?php // Fist full of comments if (!function_exists("custom_comment")) { function custom_comment($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?> <li <?php comment_class(); ?>> <a name="comment-<?php comment_ID() ?>"></a> <div id="li-comment-<?php comment_ID() ?>" class="comment-container"> <div class="comment-head"> <?php if(get_comment_type() == "comment"){ ?> <div class="avatar"><?php the_commenter_avatar($args) ?></div> <?php } ?> <div class="reply"> <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?> </div><!-- /.reply --> </div><!-- /.comment-head --> <div class="comment-entry" id="comment-<?php comment_ID(); ?>"> <span class="arrow"></span> <div class="comment-info"> <div class="left"><span class="name"><?php the_commenter_link() ?></span></div> <div class="right"> <span class="date"><?php echo get_comment_date(get_option( 'date_format' )) ?> <?php _e('at', 'themejunkie'); ?> <?php echo get_comment_time(get_option( 'time_format' )); ?></span> <span class="perma"><a href="<?php echo get_comment_link(); ?>" title="<?php _e('Direct link to this comment', 'themejunkie'); ?>">#</a></span> <span class="edit"><?php edit_comment_link(__('Edit', 'themejunkie'), '', ''); ?></span> </div> <div class="clear"></div> </div> <?php comment_text() ?> <?php if ($comment->comment_approved == '0') { ?> <p class='unapproved'><?php _e('Your comment is awaiting moderation.', 'themejunkie'); ?></p> <?php } ?> </div><!-- /comment-entry --> </div><!-- /.comment-container --> <?php } } // PINGBACK / TRACKBACK OUTPUT if (!function_exists("list_pings")) { function list_pings($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?> <li id="comment-<?php comment_ID(); ?>"> <span class="author"><?php comment_author_link(); ?></span> - <span class="date"><?php echo get_comment_date(get_option( 'date_format' )) ?></span> <span class="pingcontent"><?php comment_text() ?></span> <?php } } if (!function_exists("the_commenter_link")) { function the_commenter_link() { $commenter = get_comment_author_link(); if ( preg_match( '~]* class=[^>]+>~', $commenter ) ) {$commenter = preg_replace( '~(]* class=[\'"]?)~', '\\1url ' , $commenter ); } else { $commenter = preg_replace( '~(<a )/', '\\1class="url "~' , $commenter );} echo $commenter ; } } if (!function_exists("the_commenter_avatar")) { function the_commenter_avatar($args) { $email = get_comment_author_email(); $avatar = str_replace( "class='avatar", "class='photo avatar", get_avatar( "$email", $args['avatar_size']) ); echo $avatar; } } ?> help! [attachment deleted by admin] CREATE TABLE posts ( postId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, title VARCHAR(255) NOT NULL, author VARCHAR(24) NOT NULL, description TEXT NOT NULL, createdAt TIMESTAMP, PRIMARY KEY (postId) ); CREATE TABLE comments( commentId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, comment TEXT NOT NULL, postId INT(11), userId INT(11), createdAt TIMESTAMP, PRIMARY KEY (commentId), FOREIGN KEY (userId) REFERENCES users(userId), FOREIGN KEY (postId) REFERENCES posts(postId) ); CREATE TABLE replies ( repId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, reply TEXT NOT NULL, userId INT(11), commentId INT(11), createdAt TIMESTAMP, PRIMARY KEY (repId), FOREIGN KEY (userId) REFERENCES users(userId), FOREIGN KEY (commentId) REFERENCES comments(commentId) ); CREATE TABLE users ( userId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, userName VARCHAR(100) NOT NULL,, email VARCHAR(100) NOT NULL, PRIMARY KEY (userId) ); how to retrive userName,comment, and createdAt from users and comments table while I have used userId as a Foreign key on the comment table if it isn't correct, correct me please im getting Undefined offset: 0 in many line what can be the issue? Code: [Select] <!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" /><!-- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> --> <title>Untitled Document</title> </head> <body> <?php if(isset($_POST['submit'])) { $userquery = $_POST['userquery']; $xml = simplexml_load_file("http://www.google.com/ig/api?weather='".$userquery."'"); $information = $xml->xpath("/xml_api_reply/weather/forecast_information"); $current = $xml->xpath("/xml_api_reply/weather/current_conditions"); $forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions"); echo "<h1>".$information[0]->city['data'].", ".$information[0]->forecast_date['data']."</h1>"; echo "<h2>Current Contition</h2>"; echo "<div class=\"weather\">"; echo "<table width='250' border='1'>"; echo "<tr>"; echo "<td><img src='http://www.google.com".$current[0]->icon['data']."' width='70' height='70' alt='weather'></td>"; echo "<td>"; echo $current[0]->condition['data']; echo "<br/>Min "; echo $current[0]->temp_c['data']."° C, <br/>"; echo $current[0]->temp_f['data']."° F, <br/>"; echo $current[0]->humidity['data'].", <br/>"; echo $current[0]->wind_condition['data']."."; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</span>"; echo "</div>"; echo "<h2>Forecast</h2>"; foreach ($forecast_list as $forecast) : echo "<div class=\"weather\">"; echo "<table width='250' border='1'>"; echo "<tr>"; echo "<td>"; echo "<img src='http://www.google.com".$forecast->icon['data']."' width='50' height='50'alt='weather'>"; echo "</td>"; echo "<td>"; echo "<div>".$forecast->day_of_week['data']."</div>"; echo "<span class=\"condition\">"; echo $forecast->low['data']."° F - ".$forecast->high['data']."° F,<br/>"; echo $forecast->condition['data']."."; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</span>"; echo "</div>"; endforeach; } ?> <form action="test.php" method="post"> <input name="userquery" type="text" value=""/> <input type="submit" name='submit' value="get"/> </form> </body> </html> here all errors and there are few more Notice: Undefined offset: 0 in C:\wamp\www\fiunc\test.php on line 16 Notice: Trying to get property of non-object in C:\wamp\www\fiunc\test.php on line 16 Notice: Undefined offset: 0 in C:\wamp\www\fiunc\test.php on line 16 Notice: Trying to get property of non-object in C:\wamp\www\fiunc\test.php on line 16 , it happens when i add if(isset($_POST['submit'])) { $userquery = $_POST['userquery']; and this in '".$userquery."' $xml = simplexml_load_file("http://www.google.com/ig/api?weather='".$userquery."'"); I am pretty new to PHP and am trying to create a simple (so I assumed) page to takes data from one html page(works fine) and updates a MYSQL Database. I am getting no error message, but the connect string down to the end of the body section is showing up as plain text in my browser window. I do not know how to correct this. I have tried using two different types of connect strings and have verified my names from the HTML page are the same as listed within the php page. Suggestions on what I need to look for to correct would be great. I have looked online, but so far all I am getting is how to connect, or how to create a comment, so I thought I would try here. Thank you for any assistance I may get!! - Amy - Code: [Select] <body><font color="006600"> <div style="background-color:#f9f9dd;"> <fieldset> <h1>Asset Entry Results</h1> <?php // create short variable names $tag=$_POST['tag']; $serial=$_POST['serial']; $category=$_POST['category']; $status=$_POST['status']; $branch=$_POST['branch']; $comments=$_POST['comments']; if (!$tag || !$serial || !$category || !$status || !$branch) { echo "You have not entered all the required details.<br />" ."Please go back and try again."; exit; } if (!get_magic_quotes_gpc()) { $tag = addslashes($tag); $serial = addslashes($serial); $category = addslashes($category); $status = addslashes($status); $branch = addslashes($branch); $comments = addslashes($comments); } //@ $db = new mysqli('localhost', 'id', 'pw', 'inventory'); $db = DBI->connect("dbi:mysql:inventory:localhost","id","pw") or die("couldnt connect to database"); $query = "insert into assets values ('".$serial."', '".$tag."', '".$branch."', '".$status."', '".$category."', '".$comments."')"; $result = $db->query($query); if ($result) { echo $db->affected_rows." asset inserted into Inventory."; } else { echo "An error has occurred. The item was not added."; } $db->close(); ?> </fieldset> </div> </body> So I wanted to create stickers on my forum where people type in say ":Blobby-Tired" and then instead of the comment showing ":Blobby-Tired" it shows an html image tag displaying a picture of Blobby in the comment box So I created the following page CommentUpload.php However my sql fails to insert it despite the fact when I "echo $new" it shows the image on the page correctly And it can't be my sql insert code as if I change $new variable for "$BodyText" int he SQL query it it inserts ":Blobby-Tired" OK?
<?php include 'dbconnect.php'; session_start(); if(isset($_POST["submit"]) && !empty($_POST["CommentText"])){ $id = intval($_SESSION['id']); echo $_SESSION['id'] . '<p> </p>' ; $BodyText = $conn -> real_escape_string($_POST['CommentText']) ; $User = $_SESSION['username']; //Replace flairs with <img> tags /*not working currently) */ $new = str_replace(":Blobby-Tired","<img src='flairs/Blobby-Tired.jpg'> </img>","'$BodyText'"); echo "$new"; /************************/ $sql = "INSERT INTO Posts (User, CommentText, IdOfThread) VALUES ('$User','$new','$id')"; if (mysqli_query($conn, $sql)) { echo "New record has been added successfully !"; } else { echo "Error: " . $sql . ":-" . mysqli_error($conn); } mysqli_close($conn); } ?> Edited April 28 by Fishcakes This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=322815.0 Hey Guys, i have now managed to upload my site, products are listed from the database-great! However, when checkout is clicked you cannot update the cart with quantities and then click pay, it instead skips this and just empties the cart. Spent hours and getting nowhere! Can sum1 please help? My site: http://www.afebmunn.webhostingdeluxe.com/inkcrazy/index.php Hello, i have an array like: Code: [Select] Array ( [0] => http://www.google.com/asdasfsdafas [1] => http://www.google.com/join.html [2] => http://www.google.com/dfsgjkd [3] => http://www.google.com/join.html [4] => http://www.google.com/ddfgyyhujh [5] => http://www.google.com/join.html [6] => http://www.google.com/ghklkl )I'm trying to transform it like: Code: [Select] Array ( [0] => http://www.google.com/asdasfsdafas [1] => http://www.google.com/dfsgjkd [2] => http://www.google.com/ddfgyyhujh [3] => http://www.google.com/ghklkl )I used array_fliter but with no success any advise? Thanks I have a foreach loop as foreach ($xml->channel->item as $value){ $title = $value->title; $text = $value->text; echo "$title <br /> $text"; } I want to skip any entry in which the title contains a character like ":" I have three records in this table, yet the script below only displays two records, skipping the first item. I have tried it in other fields also, and it is always skipping the first record? Code: [Select] $result = mysql_query("SELECT * FROM `content_type_ads`"); $row = mysql_fetch_array( $result ); while($row = mysql_fetch_array($result)){ echo $row['nid']. " - ". $row['field_item_id_value']; echo "<br />"; } I have this code: Code: [Select] $data = array_combine($data4, $addfinal); foreach( $data as $key => $value){ ?> <tr> <td><?php echo $key;?></td><td><?php echo $value; ?></td><td></td><td>Safeco</td><td><a href="ajax/map.php?address=<?php echo urlencode($value);?>">Map It</a></td> </tr> <?php } That uses an array that looks like this (but longer): Code: [Select] Array ( [Business Name 1] => Business Address 1 [Business Name 2] => Business Address 2 [Business Name 3] => Business Address 3) But it skips every other array entry? Any ideas? So its displaying Business Name 1, Business Name 3, etc. I have a script that uploads and images, creates 2 versions of it, re-sizes the images and inserts all the info into a DB. The odd thing is that if I don't have an image to upload, it will still run the script but it will completely skip over the description. If I upload an image, it works fine. Not too sure what the issue is. Is it because my variable of $desc causing a conflict? Here's my code: Code: [Select] <?php ini_set("display_errors",1); include 'dbconn.php'; $change=""; $abc=""; define ("MAX_SIZE"," 10000"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if($_SERVER["REQUEST_METHOD"] == "POST") { $image =$_FILES["file"]["name"]; $uploadedfile = $_FILES['file']['tmp_name']; if ($image) { $filename = stripslashes($_FILES['file']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { $change='<div class="msgdiv">Unknown Image extension </div> '; $errors=1; } else { $size=filesize($_FILES['file']['tmp_name']); if ($size > MAX_SIZE*1024) { $change='<div class="msgdiv">You have exceeded the size limit!</div> '; $errors=1; } if($extension=="jpg" || $extension=="jpeg" ) { $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefromjpeg($uploadedfile); } else if($extension=="png") { $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefrompng($uploadedfile); } else { $src = imagecreatefromgif($uploadedfile); } echo $scr; list($width,$height)=getimagesize($uploadedfile); $newwidth=150; $newheight=($height/$width)*$newwidth; $tmp=imagecreatetruecolor($newwidth,$newheight); $newwidth1=50; $newheight1=($height/$width)*$newwidth1; $tmp1=imagecreatetruecolor($newwidth1,$newheight1); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height); $famname = $_POST['famname']; $desc = $_POST['description']; $petname = $_POST['petname']; $letter = $_POST['letter']; $filename = "images/". $_FILES['file']['name']; $filename1 = "images/small". $_FILES['file']['name']; imagejpeg($tmp,$filename,100); imagejpeg($tmp1,$filename1,100); imagedestroy($src); imagedestroy($tmp); imagedestroy($tmp1); }} } //If no errors registred, print the success message if(isset($_POST['Submit']) && !$errors) { $insert="insert ignore into tbl_tribue (petname,familyname,letter,description,imgpath,thumbpath) values ('$petname','$famname','$letter','$desc','$filename','$filename1')"; mysql_query($insert); //mysql_query("update gallery set imgpath='$filename'"); $change=' <div class="msgdiv">Pet Added Successfully!</div>'; print $insert; } ?> I had turned on the error and the print to see the output. Anyone have any ideas? Thanks! My foreach loop is skipping an element?
How is this possible?
echo '<p>-- Begining of Vardump --</p> '; var_dump($EventTotals); echo ' <p>-- End of Vardump --</p> <p>-- Begining of Just echo --</p> <p>'.$EventTotals[1]['TITLE'].'</p> <p>'.$EventTotals[2]['TITLE'].'</p> <p>-- End of Just echo --</p> <p>-- Begining of Foreach --</p> '; foreach ($EventTotals as $DATA); { echo '<p>'.$DATA['TITLE']."</p>\n"; } echo '<p>-- End of Foreach --</p> ';Gives me this output: <p>-- Begining of Vardump --</p> array(2) { [2]=> array(3) { ["TITLE"]=> string(9) "Book Sale" ["TARGETHOURS"]=> string(4) "0.00" ["HOURS"]=> float(4) } [1]=> array(3) { ["TITLE"]=> string(15) "Spring Jogathon" ["TARGETHOURS"]=> string(5) "10.00" ["HOURS"]=> float(7) } } <p>-- End of Vardump --</p> <p>-- Begining of Just echo --</p> <p>Spring Jogathon</p> <p>Book Sale</p> <p>-- End of Just echo --</p> <p>-- Begining of Foreach --</p> <p>Spring Jogathon</p> <p>-- End of Foreach --</p>Why does the foreach skip one of the elements of the array? Bug or am I missing something obvious? Edited by Firemankurt, 04 October 2014 - 04:36 PM. Hey guy's, have been stuck at this hurdle for a little whole now and I can't seem to find the right solution and would very much appreciate anyones help on this. Ok, so I have a table of votes and each time a user votes, they're added to this table. Now, I have a 'pool' table which will display certain items. What I'm trying to do is display the 'pool' items, but if this specific user has already voted on this particular item, then I want it to skip the item in the 'pool' and go to the next item, until the argument of has that user voted is false. The current code I'm pasting will obviously not work, it isn't even in the right position, but I've separated it so that you can hopefully understand what I'm trying to do in order to help. Below is the code I use to check if a user has already voted on a particular photo: <?php $result=mysql_query("SELECT * FROM votes WHERE vVoter='$_SESSION[userID]' AND vPhoto='$_SESSION[currentphoto]'"); $rowCheck = mysql_num_rows($result); $alreadyv = 0; if($rowCheck > 0){ $alreadyv = 1; //user has already voted on this photo, need to use this info to be able to skip it in the 'pool' } else { //do nothing } ?> totalVoted is basically how many times a user has voted, so that people who vote more, get more votes: <?php $result=mysql_query("SELECT * FROM pool ORDER BY totalVoted DESC LIMIT 1"); $rowCheck = mysql_num_rows($result); if($rowCheck > 0){ while($row = mysql_fetch_array($result)){ $photoid = $row['photoInPool']; $result2=mysql_query("SELECT * FROM photos WHERE pID='$photoid'"); $rowCheck2 = mysql_num_rows($result2); if($rowCheck2 > 0){ while($row2 = mysql_fetch_array($result2)){ if($alreadyv == 1) { //I NEED THIS TO SHOW THE NEXT PHOTO IN THE ARRAY, HOWEVER, IF THEY HAVE ALREADY VOTED ON THE NEXT PHOTO, IT WILL STILL DISPLAY IT, THIS IS MY PROBLEM I NEED HELP WITH PLEASE } elseif ($alreadyv != 1) { $fname = $row2['pFileName']; } } } $_SESSION[currentphoto] = $row['photoInPool']; echo "<center><img src='user_images/$fname'></center>"; } } ?> I hope I've explained this well enough and hope somebody can help. Many thanks in advance I have a simple foreach loop. The array has four rows in it. Really simple. I have confirmed the data in the array with var_dump. For some reason I cannot fathom, the loop is only processing rows 0 and 2 and is not processing 1 and 3.
Here's the code snippet:
<?php foreach ($postCals as $key=>$cal){ var_dump($postCals, $cal, $key); echo '<td style="text-align:right;>' . $cal . "</td>"; } ?>$postCals has precisely 4 values. Here's the output from this part of the code (in terms of the var_dumps). array (size=4) 0 => string '2.00000' (length=7) 1 => string '2.00000' (length=7) 2 => string '3.20000' (length=7) 3 => string '4.00000' (length=7) string '2.00000' (length=7) int 0 array (size=4) 0 => string '2.00000' (length=7) 1 => string '2.00000' (length=7) 2 => string '3.20000' (length=7) 3 => string '4.00000' (length=7) string '3.20000' (length=7) int 2 That's it. I two other foreach loops identical to this and they run fine! Any ideas? (misc info: php: 5.4.7 running on XAMPP/Windows ) We have a php application that is just a form, that takes in data to a mysql database and then displays that data in queue(php web page) for the client. It has been working for the past 5 or more years. Six weeks ago, the client noticed that the numbering started skipping a number each time a request was entered. It then seemed to stop, now it has started again. See attached image. Some detail he after user has completed web form and hits submit, three fields are populated in the mysql "REQUEST" table, then the actually data from the submitted web form is sent to the ANSWER table. The REQUEST table is in sync and is always populated, and numbering is in sequence but upon submit, the actual data from the request does NOT always go to the ANSWER table hence the "skipping of numbers." What do I even begin looking at/for to determine what happened? Reminder: this is a 5+ year old app that worked fine until maybe 6 weeks ago. No changes have been made to the database or the code base since 2008. The code that adds the data to the ANSWER table [the one that appears to skip] is below. The applicate is in php 4.3.1, mysql 5, linux server. Code: [Select] <form name="commentbox" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <textarea name="comment" cols="20" rows="2" onclick="document.commentbox.comment.value='';" onfocus="this.style.borderColor='yellow';" onblur="this.style.borderColor='blue';" />Comment...</textarea> </td></tr> $commentcheck = $_POST['comment']; if ($commentcheck == "Comment...") { die(' <META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=index.php\"> '); }else why does this not refresh if i comment "Comment..." it just dies and doesnt echo anything |