PHP - Unknown Reason For A Value In An Array
Hey
I have a script that builds an array but for some reason there is a loose integer in the variable which is confusing me and i think its the cause of my syntax errors in javascript. But i got no idea where it is coming from =/ Here is the function i use: Code: [Select] <?php function img($id) { $img = array(); $img['tiles'] = $this->db->getAll("SELECT DISTINCT t.id, CONCAT('data/tiles/',filename) AS f FROM `map_tiles` AS mt INNER JOIN `tiles` AS t ON (mt.tile=t.id) WHERE mt.map_id={$this->db->qstr($id)}"); echo print_r($img); die; //exit(json_encode($img)); // turned off for testing ?> The echo returns this: Code: [Select] Array ( [tiles] => Array ( [0] => Array ( [id] => 10 [f] => data/tiles/floor.png ) ) ) 1 <----- why does this appear? And could this cause a syntax error if sent back for JS processing? As you can see there is 1 showing at the end but i don't see why =/ Any ideas if thats suppose to happen ? 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 for the below code, what does the get_magic_quotes_gpc part mean?... in simple terms Code: [Select] $photoname = $_FILES['photo']['name']; if(!get_magic_quotes_gpc()) { $photoname = addslashes($photoname); } Here are the two if statements: if (!($start <= 0)){ $prev_button = "<a href='forum.php?category_id=$category_id&start=$prev'>Prev</a>"; } if (!($start >= $record_num - $per_page)){ $next_button = "<a href='forum.php?category_id=$category_id&start=$next'>Next</a>"; } But they are not properly working. This is part of a pagination script for the next and previous buttons. I have this code below in a while loop, that gets looped through about 10 times and is simply resizing a slightly larger image to fit within a 50px max square. There is other code on my page, but I've narrowed the slowness down to this specific bit of code (i.e. if I take this snippet out, the page loads instantly). With this snippet, the page takes between 5 and 10 seconds to load, which seems absurd for 10 images. FYI, the original images are no larger than 200 px on either side, so it's not like it's looping through large image files. Anyone know why this might be taking so long? Should I be doing it differently somehow? Code: [Select] list($width,$height) = getimagesize($myimage); if ($width > $height) { $datasofar .= "width=50 /></span>"; } elseif ($height > $width) { $datasofar .= "height=50 /></span>"; } else { //height and width must be equal so just set width = 50, but could just as easily set height to 50 $datasofar .= "width=50 /></span>"; } I normally don't have a problem with concenation, but for some reason I can't get it work in this case. I have two form variables: firstname_ord and lastname_ord. I have tried concenating them several ways, and get nothing afterwards. attempt 1: $lastname = "firstname_ord" . " " . "lastname_ord"; attempt 2: $firstname = "firstname_ord"; $lastname = "lastname_ord"; $fullname = $firstname . " " . $lastname; attempt 3: $fullname = "firstname_ord"; $fullname = $fullname. " " . "lastname_ord"; attempt 4: $fullname = "firstname_ord"; $fullname .="lastname_ord"; attempt 5: $fullname = (string)"firstname_ord"; $fullname .= " "; $fullname .=(string)"lastname_ord"; Used to be a good option, but don't know anymore as password_hash() is now available.
Agree?
I understand that I shouldn't ever manually salt and disable the functions salting. That being said, is there any reason to add a bit extra to the user's password (such as an internal ID and some random constant)?
I've noticed some people don't use { } when they right statements, when I first started learning PHP a couple years ago, I thought you HAD to put the curly brackets, but apparently not, how does this work and why don't some people use them in their scripts? I spent the last hour or so typing this code up, and for some reason I am getting a query error. I have reviewed & revised the code up and down for the past half hour and can't seem to figure out the problem. Can someone look after this for me and tell me what I could be doing wrong? Yes, I know my code is a bit sloppy and may use bad practice techniques, but it works for me. Its a survey that I coded so I could collect data and place it on CPA ad listings. So I need this so work at some point soon. My code: <?php $user = $_POST['user']; $email = $_POST['email']; $password = $_POST['pass']; $paypal = $_POST['paypal']; $q1 = $_POST['q1[favsite]']; $q2 = $_POST['q2[isp]']; $q21 = $_POST['q2.1[bill]']; $email_services = $_POST['email_services']; $ebay = $_POST['ebay']; $amazon = $_POST['amazon']; $q6 = $_POST['q6[purchase]']; $q7 = $_POST['q7[social]']; $q8 = $_POST['q8[bookmarks]']; $q9 = $_POST['q9[search]']; $q10 = $_POST['q10[homepage]']; $q11 = $_POST['q11[5topsites]']; $q12 = $_POST['q12[state]']; if ($_POST['fin'] == "complete") { $dbc = mysqli_connect('localhost', 'root', 'password', 'database') or die('Could not connect'); $query = "INSERT INTO user_data (id, user, email, password, paypal, q1[favsite], q2[isp], q21[bill], email_services, ebay, amazon, q6[purchase], q7[social], q8[bookmarks], q9[search], q10[homepage], q11[5topsites], q12[state]) VALUES ('$user', '$email', '$password', '$paypal', '$q1', '$q2', '$q21', '$email_services', '$ebay', '$amazon', '$q6', '$q7', '$q8', '$q9', '$q10', '$q11', '$q12')"; mysqli_query($dbc,$query) or die('Error querying database'); include_once("../phpmailer/class.phpmailer.php"); $mail = new PHPMailer; $mail->ClearAddresses(); $mail->AddAddress('', ''); $mail->From = ''; $mail->FromName = ''; $mail->Subject = 'Thanks for finishing the survey!'; $mail->Body = "Hello, $user. This is a reminder that you have finished the survey and your credit is currently being processed. Please login to your account at ../../ to view the status of your credit & cash out. "; if ($mail->Send()) { echo "<center>Mail Sent.</center>"; } else { echo $mail->ErrorInfo; } echo "<center><h2>Thanks for completing the survey! Please <a href='login.php'>login</a> to your account to view the status of your credit & cash out.</h2></center>"; } ?> It has nothing to do with PHPMailer, I of course edited the variables just now so all my info wouldnt be public, but everything is fine untill you press submit & I get the or die() error message "Error querying database". What the hell did I do wrong? Is it possible that I cant name variables in the format I used with most of them ($var1 = $_POST['var[desc]']; ? Hey, I've got a query in which a variable is interpreted as a column and I don't why this is caused. $upgrade_time_sql = "SELECT * FROM todo_upgrades WHERE profile_id = ".$profile_id." AND level = ".$profile_data['level2_'.$show.'']." AND type = ".$show.""; $upgrade_time_res = mysql_query($upgrade_time_sql) or die (mysql_error()); $show is filled with the content "storage" The mysql_error is "Unknown column 'storage' in 'where clause'" Thanks for helping. Hey im kind of new to PHP me and my mate was working on a script and we can not seem to get this working: Its connected through mysql. And it shows Quote Notice: Undefined index: username in C:\xampp\htdocs\stick_arena.php on line 21 Notice: Undefined index: userpass in C:\xampp\htdocs\stick_arena.php on line 22 Notice: Undefined index: action in C:\xampp\htdocs\stick_arena.php on line 23 Notice: Undefined index: usercol in C:\xampp\htdocs\stick_arena.php on line 24 Notice: Undefined index: stats in C:\xampp\htdocs\stick_arena.php on line 25 Here are the lines Quote // declare variables $username = sanitize($_POST['username']); $password = sanitize(md5($_POST['userpass'])); $action = sanitize($_POST['action']); $usercol = sanitize($_POST['usercol']); $stats = sanitize($_POST['stats']); Here is the full script for that page: Click here please help as soon as possible. Hello! I have a strange error on my PHP script and i dont how to fix it. If someone can help me, please help me then! Here is my error: Code: [Select] logout(); } else { $iq = mysql_query("SELECT * FROM users WHERE username='{$signin_username}' AND password='{$signin_password}' AND suspended='0' LIMIT 1;"); $ir = mysql_fetch_array($iq); $_SESSION['me'] = $ir; } } } } else { die("The configuration did not recieve appropriate variables to accept your request."); } if ($set['next_clearup'] < time ()) { $next_clearup = time () + 60 * 60 * 24; mysql_query ('' . 'UPDATE settings SET set_value=\'' . $next_clearup . '\' WHERE set_name=\'next_clearup\' LIMIT 1;'); mysql_query ('UPDATE users SET ads_clicked=\'\' WHERE ads_clicked!=\'\''); } } ?> Warning: include(THDIRindex.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\Upload\index.php on line 16 Warning: include() [function.include]: Failed opening 'THDIRindex.php' for inclusion (include_path='.;\xampp\php\PEAR') in C:\xampp\htdocs\Upload\index.php on line 16 And here is the PHP file the error is in: Code: [Select] <?php session_start(); include_once('lib/lib.php'); include_once('lib/configuration.php'); $ddir = THDIR.$do->get_file_url(); include($ddir); if(file_exists(HEADER)) { include_once(HEADER); } if($contents) { print $contents; } if(file_exists(FOOTER)) { include_once(FOOTER); } ?> Help ASAP if you can! I Am getting along with php better than I was previously. But this 68 year old brain still refuses to learn very fast! Here is the error I'm receiving when I'm trying to open the db: Parse error: syntax error, unexpected T_VARIABLE in /home/taft65/public_html/memProtest.php on line 197 <?php error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR); $host = "localhost"; $dbname="database;" Failing ------>$username = "user"; $password="drDedf#hj"; I understand you do not need to declare varibles in PHP, Correct? I checked the db to ensure that I'm calling the correct value. NuSpherePhpEd to validate the code. I also check it with DSV PHP Editor. Both come up with the same error. I'm also using MyPhpAdmin to create the database and tables. I know also to place this calling info in another folder and include it by calling it with a php include statement. I just have it within the code to quickly test it. Thank you for any assistance. Bob... im using 000webhost as a test site and when i run this code it redirects me to there err page but with no error message. the sql query works fine in phpmyadmin and i added the rest of the code to try the php side. i "think" the problem is the echo $rows"value's" as im unsure of what the $vars should be <?php include("config.php"); // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql = "SELECT make, COUNT(*) AS total, SUM(IF(comments = \'pass\', 1, 0)) AS withComments FROM dsgi_serval GROUP BY make ORDER BY COUNT(*) DESC"; $result=mysql_query($sql); echo "$sql"; echo "$result"; ?> <table><tr> <td colspan="4"><strong>List data from mysql </strong> </td> </tr> <tr> <td align="center"><strong>make</strong></td> <td align="center"><strong>Total</strong></td> <td align="center"><strong>Validated</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><?php echo $rows['make']; ?></td> <td><?php echo $rows['total']; ?></td> <td><?php echo $rows['withcomments']; ?></td> </tr> <?php } ?> </table> <?php mysql_close(); ?> So I've been working on this site for a few days now, and it's coming along slow but well. I'm trying to learn as much as possible about the coding I'm doing because it's a bit outside my skill range, so I'm taking my time. I'm using a switch statement to dictate navigation, and netsted switches inside as well. Everything was going great until I started continuing to add code to each case of the switch, then all of a sudden 2 of the cases show up blank, but nothing else is affected. I spend an hr last night and this morning, looking and redoing, to get the same result. Can someone take a look at this and advise please? <?php switch ($_GET['page']) { case 'news': switch ($_GET['id']) { case $_GET['id']: $id = $_GET['id']; $link = mysql_connect ($host, $user, $pass); mysql_select_db ($db, $link); $query = "SELECT * from news WHERE id = '$id'"; $result = mysql_db_query ($db, $query, $link); while ($row = mysql_fetch_array($result)){ echo ("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td colspan=\"2\" class=\"Main-Header\"><a href=\"index.php?page=news&id=".$row['id'] . "\">".$row['title'] . "</a></td> </tr> <tr> <td colspan=\"2\" class=\"Main-PostInfo\">Posted By: $row[author] on $row[date]</td> </tr> <tr> <td colspan=\"2\" class=\"Side-Content\">$row[content]</td> </tr> </table><br /> "); } break; default: $link = mysql_connect ($host, $user, $pass); mysql_select_db ($db, $link); $query = "SELECT * from news'"; $result = mysql_db_query ($db, $query, $link); while ($row = mysql_fetch_array($result)){ echo ("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td colspan=\"2\" class=\"Main-Header\"><a href=\"index.php?page=news&id=".$row['id'] . "\">".$row['title'] . "</a></td> </tr> <tr> <td colspan=\"2\" class=\"Main-PostInfo\">Posted By: $row[author] on $row[date]</td> </tr> <tr> <td colspan=\"2\" class=\"Side-Content\">$row[content]</td> </tr> </table><br /> "); } break; } break; case 'about'; $link = mysql_connect ($host, $user, $pass); mysql_select_db ($db, $link); $query = "SELECT * from aboutvow"; $result = mysql_db_query ($db, $query, $link); while ($row = mysql_fetch_array($result)){ echo ("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td class=\"Main-Header\">$row[title]</td> </tr> <tr> <td class=\"Side-Content\">$row[content]</td> </tr> </table><br /> "); } break; case 'roster': switch ($_GET['id']) { case $_GET['id']: $id = $_GET['id']; $link = mysql_connect ($host, $user, $pass); mysql_select_db ($db, $link); $query = "SELECT * from roster WHERE id = '$id'"; $result = mysql_db_query ($db, $query, $link); while ($row = mysql_fetch_array($result)){ echo ("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td width=\"30\" colspan=\"2\" class=\"Main-Header\">-VoW- $row[gamename]</td> </tr> <tr> <td colspan=\"2\" class=\"Main-PostInfo\">SECTION 1: PERSONAL INFORMATION</td> </tr> <tr> <td class=\"Side-Content-Left\">Name</td> <td class=\"Side-Content-Right\">$row[firstname] $row[lastname]</td> </tr> <tr> <td class=\"Side-Content-Left\">Location</td> <td class=\"Side-Content-Right\">$row[location]</td> </tr> <tr> <td class=\"Side-Content-Left\">Age</td> <td class=\"Side-Content-Right\">"); date_default_timezone_set('America/New_York'); function calculateAge($dob){ return floor((time() - strtotime($dob))/31556926); } $age = calculateAge("$row[dob]"); echo ("$age</td> </tr> <tr> <td class=\"Side-Content-Left\">Connection</td> <td class=\"Side-Content-Right\">$row[connection]</td> </tr> <tr> <td colspan=\"2\" class=\"Main-PostInfo\">SECTION 2: CONTACT INFORMATION</td> </tr> <tr> <td class=\"Side-Content-Left\">Email</td> <td class=\"Side-Content-Right\">$row[email]</td> </tr> <tr> <td class=\"Side-Content-Left\">Steam</td> <td class=\"Side-Content-Right\">$row[steamfriends] ($row[steamemail])</td> </tr> <tr> <td class=\"Side-Content-Left\">Xfire</td> <td class=\"Side-Content-Right\">$row[xfire]</td> </tr> <tr> <td colspan=\"2\" class=\"Main-PostInfo\">SECTION 3: DAY OF DEFEAT INFORMATION</td> </tr> <tr> <td class=\"Side-Content-Left\">DoD Experience</td> <td class=\"Side-Content-Right\">"); date_default_timezone_set('America/New_York'); function calculateExp($exp){ return floor((time() - strtotime($exp))/31556926 + 8); } $exp = calculateExp("$row[dodexp]"); echo ("$exp Years</td> </tr> <tr> <td class=\"Side-Content-Left\">Class</td> <td class=\"Side-Content-Right\">$row[class]</td> </tr> <tr> <td class=\"Side-Content-Left\">SteamID</td> <td class=\"Side-Content-Right\">$row[steamid]</td> </tr> <tr> <td colspan=\"2\" class=\"Main-PostInfo\">SECTION 4: MATCH INFORMATION</td> </tr> <tr> <td colspan=\"2\" class=\"Main-Content\">-VoW- $row[gamename] has no match history</td> </tr> </table><br /> "); } break; default: $link = mysql_connect ($host, $user, $pass); mysql_select_db ($db, $link); $query = "SELECT * from roster"; $result = mysql_db_query ($db, $query, $link); while ($row = mysql_fetch_array($result)){ echo ("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td colspan=\"5\" class=\"Main-Header\">Roster</td> </tr> <tr> <td width=\"101\" class=\"Main-Roster-Left\">Name</td> <td width=\"124\" class=\"Main-Roster\">Status</td> <td width=\"241\" class=\"Main-Roster\">SteamID</td> <td width=\"175\" class=\"Main-Roster\">Class</td> <td width=\"452\" class=\"Main-Roster\">Recruitment Date</td> </tr> <tr> <td class=\"Main-Roster-Content-Left\"><a href=\"index.php?page=roster&id=".$row['id'] . "\">".$row['gamename'] . "</a></td> <td class=\"Main-Content-Roster\">$row[status]</td> <td class=\"Main-Content-Roster\">$row[steamid]</td> <td class=\"Main-Content-Roster\">$row[class]</td> <td class=\"Main-Content-Roster\">$row[admin_recdate]</td> </tr> </table>"); } break; } break; case 'servers': switch ($_GET['id']) { case 1: echo "ID is 1"; break; case 2: echo 'ID is 2'; break; default: echo 'No ID - display main servers'; break; } break; case 'forum'; echo ("FORUM HERE"); break; default: $link = mysql_connect ($host, $user, $pass); mysql_select_db ($db, $link); $query = "SELECT * from news ORDER BY date DESC LIMIT 5"; $result = mysql_db_query ($db, $query, $link); while ($row = mysql_fetch_array($result)){ echo ("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td colspan=\"2\" class=\"Main-Header\"><a href=\"index.php?page=news&id=".$row['id'] . "\">".$row['title'] . "</a></td> </tr> <tr> <td colspan=\"2\" class=\"Main-PostInfo\">Posted By: $row[author] on $row[date]</td> </tr> <tr> <td colspan=\"2\" class=\"Side-Content\">$row[content]</td> </tr> </table><br /> "); } break; case 'recruitment': switch ($_GET['action']) { case 'apply': echo "APPLICATION HERE"; break; case 'submit': echo 'SUBMIT APPLICATION'; break; case 'status': echo 'APPLICATION STATUS'; break; default: echo 'No ACTION - display main recruitment'; break; } break; } ?> The problem I am having is getting the default news case and default roster case to print. Everything else shows up properly. Sorry for the messy code, I"m working on it! Hi there, I am NOT a PHP coder, but I have a site that is written in PHP and I am getting an error that keeps filling up my site cache and I just cannot figure it out - I know it has something to do with my images on the site, but none of them are out of the ordinary (GIFs and JPEGs, the only character apart from letters or numbers that i have used is the "_" and there are no spaces). I have looked around at the error I am getting - but I will be honest in that I dont really understand what the problem is or how to resolve it. Here is the error I get: PHP Warning: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: Unknown modifier 'C' in /home/smcclean/public_html/includes/modules/additional_images.php on line 48 This relates to the following line of code: if(preg_match("/" . $products_image_base . "/i", $file) == 1) { I would really appreciate a steer as to how I could resolve this. Many thanks I'm using the php mail function and sending to Gmail accounts it shows "Unknown Sender" This is my header: Code: [Select] $headers = "From: XXXXX\r\nReply-To: XXXX@XXXXX.com"; $headers .= "\r\nContent-Type: text/html; charset='iso-8859-1' Content-Transfer-Encoding: 7bit"; I read somewhere that removing the "\r" would work but no luck... any help would be awesome Hello again, Though this question is somewhat related to my prior note, I thought it was probably different enough to justify a separate topic... So, I have a link at site1.com/dir/admin/?param1=value¶m2=value, etc, which I want to redirect to site2.com with all the rest being the same. Thanks to your help, it's working with two specified parameters However, there is a relatively short list of potential parameters (maybe 5?) but not all of them are passed in all calls to the link. In other words, sometimes the link is called with param1 and param2, sometimes with 1 and 3, sometimes with 1,2, and 4, etc. What is the best way to do the redirect which would ensure that all the parameters which are sent to the initial link are then included in the redirect? Is there a way to search the incoming link and grab all parameters in it? Or do I put together the list of possible parameters and then grab the values with $_GET for all of them and then pass all of them even if the values are null (not sure whether the app will accept that or not...) I hope I'm stating the question clearly enough! Thanks in advance for your help! Hey all, I keep getting this 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 '' at line 2 When I use the script below. I'm finding it a bit confusing because everything about it continues to work, it's just it gives me an error. When the script runs, the outcome is "Success! Your dog now looks far more energetic! Looks like this food is all used up." Followed by the error, which cuts the remainder of the page off. Does anybody know why it's doing this? $dogyay = $_POST['dogid']; $checkenergy = "SELECT energy FROM dogs WHERE id=$dogyay"; $energylevel = mysql_query($checkenergy) or die(mysql_error()); $row = mysql_fetch_array($energylevel) or die(mysql_error()); if($row['energy'] >= 100) { echo "<b>Oops!</b> Looks like your dog is full right now...";} else{ echo "<b>Success! Your dog now looks far more energetic!</b><br><br>"; $sql11="UPDATE dogs SET energy=energy + 50 WHERE id=$dogyay"; $result11=mysql_query($sql11); $sql12="UPDATE items SET uses = uses - 1 WHERE itemid=$id"; $result12=mysql_query($sql12); $checkuses = "SELECT uses FROM items WHERE itemid=$id"; $useslevel = mysql_query($checkuses) or die(mysql_error()); $row = mysql_fetch_array($useslevel) or die(mysql_error()); if($row['uses'] == 0) { echo "Looks like this food is all used up.<bR><br>"; mysql_query("DELETE FROM items WHERE itemid='$id'") or die(mysql_error());} Thanks ! I GET QuoteFatal error: TPL: [in line 0]: syntax error: file 'm/pg/_categories' does not exist in C:\WebServ\httpd\libs\tpl\class.template.php on line 943 unset($_templatelite_tpl_vars); else: $_templatelite_tpl_vars = $this->_vars; echo $this->_fetch_compile_include($this->_vars['TPLx'].'m/pg/_categories'.$this->_vars['HTML'], array()); $this->_vars = $_templatelite_tpl_vars; WITH FILES http://testynarkotykowe.j13x.pl/index.txt && http://testynarkotykowe.j13x.pl/indexpg.txt HOW TO FIX IT |