PHP - Getting Errors That No Array Exists ?
Code: [Select]
$result = mysql_query("SELECT field_item_id_value FROM `content_type_ads`"); while($row = mysql_fetch_array($result)){ echo $row['field_item_id_value']; echo "<br />"; echo $result; } I am trying to use an "array diff()" argument and I am getting errors with it stating the above is not an array. I have used $row and $result, and neither work. Is this not dumping into an array properly? Similar TutorialsMaybe I am over thinking this, but I would like to see if their is another value after the current value without moving the internal array pointer. What can I do? hello, have a question. im trying to do a select * where id exists in array $id8 here is my array Code: [Select] $result8 = mysql_query("SELECT * FROM customers WHERE whosclient = 'Lansoft'"); while($row8 = mysql_fetch_array($result8)) { $id8=$row8['id']; } here is my select code. it is only returning results for the highest number in the array Code: [Select] $result = mysql_query("SELECT * FROM timesheets WHERE status = 3 AND billable = 1 AND client = '$id8' ORDER BY date, starttime"); while($row = mysql_fetch_array($result)) { Thanks for any help! I am trying to compare an array containing required questions to an array holding survey responses. When a user submits a survey, I take the $_POST array and write the values to a new array called $surveyResponseArray. How can I determine if $surveyResponseArray exists?
Edited February 16 by SaranacLake Hey Guys, I need some assistance, hopefully there is just a simple command that I am not aware of or an easy answer to this. Suppose I have an array with x amount of values... $arr = array("111111" => 10, "222222" => 20); And i have a query.. mysql_query("SELECT * FROM table WHERE table.zip = "111111" "); Suppose I want to modify the query, so it can check if table.zip exists anywhere in $arr, regardless of length of array. And Select the value that the array location refers to. So I need it to check if "111111" is anywhere in the array, and then take the value 10. The example I am applying this to is that I have a database full of business addresses/zip codes and a database full of every zip code in country. So I have a script to get every zip within x miles, and the distance from it, but need to be able to apply it when I query my business addresses to see if it exists within x miles. Thanks! Greg Hi, I am a newbie in PHP (about week and a half). I'm writing a website for myself right now. I've got a problem that I cannot solve. The website is about buying files with website custom balance. What I want to do is disable buy button if user bought this file b4. The is a table user_files that stores user id and file id. And another table that stores files data, ID name who uploaded date time ect.... What I'm trying to do, is disabling buy button if the user has already the file. This is what I've done : while ($row = $rocket->fetch()) { ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['name']; ?></td> <td><?php echo $row['uploader']; ?></td> <td><?php echo $row['uploadtime']; ?></td> <td><button <?php // Echo "disabled" if $row['id'] id is present in row2['file_id'] <<<<<<< Need to do this in a while. ?> ><a href="download.php?id=<?php echo $row['id']; ?>"></a><?php echo $row['price'] . "D$" ?></button></td> </tr> <?php } ?> What I can't do is check if the file id ($row['id']) is present in ($row2['file_id']), if yes echo "disabled";
I'm a total noob trying to figure out how to get this function to work right. I want to echo for each Code: [Select] '<OPTION value="'.$SKUCAPS.$skunum.$size.'">'.$size.'</OPTION>' for each size in the $skus[$type][$skunum]['sizes'] array. and if no size exists echo Code: [Select] '<input value="'.$SKUCAPS.$skunum.'" type=hidden" name="item">' Code: [Select] <?php $BANDNAME="Band Name"; $BANDCAPS="BANDNAME"; $BANDLOWER="bandname"; $SKUCAPS="BND"; $SKULOWER="bnd"; $skus = array( 'shirts' => array( '165' => array( 'name' => 'World Khaos Tour <br> Limited Edition Tour Track Jacket.', 'price' => '70.00', 'sizes' => array('M', 'L', '1X' ) ), '139' => array( 'name' => 'KHAOS LEGIONS ALBUM COVER', 'price' => '15.95', 'sizes' => array('S', 'M', 'L', '1X' ) ), ), //end product type 'misc' => array( '603' => array( 'name' => 'Ring Button', 'price' => '3.00', 'sizes' => array('none') ), '602' => array( 'name' => 'Logo Button', 'price' => '3.00', 'sizes' => array('none') ) ) //end product type ); //end skus function makeProduct($type){ global $skus; foreach ( $skus[$type] as $skunum => $value) { $price = $skus[$type][$skunum]['price']; $name = $skus[$type][$skunum]['name']; echo ' <!-- PRODUCT BEGIN --> <li class="product" > <a href="images/'.$SKULOWER.$skunum.'lg.jpg" rel="lightbox"><img src="product_files/'.$SKULOWER.$skunum.'.png"></a><br> <strong>'.$name.'</strong><br>'.$SKUCAPS.$skunum.'<br>$'.$price.'<br> <form name="'.$SKUCAPS.$skunum.'" method="GET" target="_blank" action="http://www.jsrdirect.com/cgi-bin/Make-a-Store.cgi"> <input type="hidden" name="band" value="'.$BANDCAPS.'"> <input type="hidden" name="back" value="http://www.jsrdirect.com/bands/'.$BANDLOWER.'/index.html"> <strong>Qty:</strong> <input type="text" name="quantity" size="1" value="1" > <strong>Size:</strong> <SELECT name="item">'.makeSizes(). '</SELECT> <br><br> <input class="css3button" value="Add To Cart" type="image"> </form> </li> <!-- Product End -->'; } } ?> any help would be greatly appreciated Hi All, There is a very interesting solved topic here (http://www.phpfreaks.com/forums/index.php?topic=304966.0) about how to access elements in embedded _POST array. But before accessing an element, it might be appropriate to check whether the array it is supposed to be in exists. According to the solution given in the topic indicated above, Code: [Select] $_POST['matType'] is an example of embedded array . Is there a way to check if this array exists? Thanks in advance for your help. Okay heres the problem. I have a form which displays items that sit within a packet. (In this case its called Wireless Package 1). Each item has its own specific value, which can be any string, hench why there is an 'input type= text' in the value column in the table. Each of these values is stored in a table, with the primary key 'piid', (show as a hidden field within 3rd column). The problem is when im posting the array 'values[]' I cant distinguish between what value needs to be referenced againist a piid, how do i obtain these individual ID's and Values in a loop so they can turned into a MySql Strings????? I tried using an explode function but got no where, any help is very much apprieciated! This is the code for the form displayed. <table border="1" cellpadding="5" cellspacing="5"> <tr> <th>Item ID</th> <th>Item</th> <th>Value</th> <th>Remove</th> </tr> <form action="edit_packet.php" method="post"> <?php foreach($packages as $packet):?> <tr> <td> <?php echo $packet['piid'] ;?> </td> <td> <?php echo $packet['desc'] ;?> </td> <td> <input type="hidden" name="values[]" value="<?php echo $packet['piid'];?>,," /> <input type="text" name="values[]" value="<?php echo $packet['value']; ?>" /> <input type="hidden" name="values[]" value="///" /> </td> <td> <form action="delete.php" method="post"> <input type="hidden" name="pid" value="<?php echo $packet['piid'];?>"/> <input type="submit" value="Delete Packet"> </td> </tr> <?php endforeach; ?> </table> <input type="submit" value="Submit" /> </form> How do I display the actual errors in IIS 7.5? If I miss a semicolon, I get: "HTTP Error 500.0 - Internal Server Error" absolutely useless. In prior versions, I could see the line and get to the PHP error. How do I display PHP errors? I've added: set_ini('display_errors', '1'); but it doesn't help. Hi community,i creating a simple website and description i analyzed my code about 3days...2hours a day. if i get the point in my head.then its say Website url is in use..but not..ok maybe i give the code below. so if you can explain whats wrong.thanks Code: [Select] <?php include_once ('connect.php'); $url= mysql_real_escape_string($_POST['url']); $desc=mysql_real_escape_string($_POST['desc']); if ($id == "krauti") { if (empty($_POST['url']) && empty($_POST['desc'])) { die('<br><center>Both Empty!.<center/><br/>'); } if (empty($_POST['url'])) { die('<br><center>URL Empty!.<center/>'); } if (empty($_POST['desc'])) { die('<br><center>desc empty fill it!.<center/>'); } $url = htmlspecialchars( stripslashes( strip_tags($_POST['url'] ) ) ); $aprasymas = htmlspecialchars( trim($_POST['desc'] ) ); $query = mysql_query("SELECT * FROM linkai WHERE url = '$url' AND 'desc' = '$desc'"); if( mysql_num_rows( $query ) == 1 ) { "INSERT INTO linkai ". "(id, url, desc) ". "VALUES('','$_POST[url]','$_POST[desc]')"; echo "Yes!."; } else if (mysql_num_rows($query) == 0 ){ echo "No!!"; } } ?> Can someone explain why this code: if (mysql_result($data,0,$SQLLargeName) = " "){ $LargeImage = "#"; } else { $LargeImage = mysql_result($data,0,$SQLLargeName); } Gives me this error? Fatal error: Can't use function return value in write context in /home/worldw44/public_html/SQL.php on line 38 And ways round it? Thanks. Hi, I have a sign up form that generates a activation key and emails it to user and they cannot login until account has been activated etc. My problem is i am not sure how to in php generate a new activation key if the generated one has already been used. I know how to do the MySQL query to check if activation key already exists but not sure how to basically tell PHP that if the activation key already exists in DB then generate a new key until one is found that does not already exist. I gather i may need a loop but not sure. Could someone please help ? Like i say i know how to do the MySQL query just need some sample code to know how to do what i asked above. Thanks for anyhelp; Much Appreciated This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=328831.0 Hi all, I have the following mysql delete query that essentially deletes a row from two seperate tables "messages" and "messages2" where the id is equal to that in both of the tables. The problem I am getting (for obvious reasons) is that it will only delete from the table, if it indeed exists in both tables. Here is the query: Code: [Select] DELETE FROM messages,messages2 USING messages,messages2 WHERE messages.id = messages2.id AND messages.id = ?; How would I go about setting it so that the query always deletes from table "messages" and only deletes from "messages2" when a corresponding id exists? I think it would involve an IF EXISTS clause, but I am not sure on this, or indeed how to implement it. Thanks in advance guys Dan My error below returns (echos) that there is no data under the table sites to display. But, there is. Why is it doing this? class_l.php <?php class displaySites { function grabSites() { $query = mysql_query("SELECT title,description,votes,dates,comments,out,in FROM sites ORDER BY id DESC LIMIT 100"); if(mysql_num_rows($query) > 0) { while($fetch = mysql_fetch_assoc($query)) { echo " <div id='post-1' class='post'> <h2 class='title'><a href='#'>". $fetch['title'] ."</a></h2> <h3 class='date'>Submitted on ". $fetch['date'] ."</h3> <div class='entry'> <p>". nl2br(stripslashes($fetch['description'])) ."</p> </div> <p class='meta'><a href='#'>View</a></p> <div class='hr'> </div> </div> "; } } else { echo " <div id='post-1' class='post'> <h2 class='title'><a href='#'>Oh NOEZ!</a></h2> <h3 class='date'>". date("M-d-Y") ."</h3> <div class='entry'> <p>There are currently no sites to display!</p> </div> <p class='meta'>View</p> <div class='hr'> <hr /> </div> </div> "; } } } class register { function createAccount() { $username = mysql_real_escape_string($_POST['username']); $password = md5(sha1(sha1($_POST['password']))); $name = mysql_real_escape_string($_POST['title']); $description = mysql_real_escape_string($_POST['description']); if(isset($username) && isset($password) && isset($name) && isset($description)) { if(!$username || !$password || !$name || !$description) { echo '<table border="0"><form action="register.php" method="POST"> <tr><td>Username</td><td><input type="text" name="username" maxlength="20"></td></tr> <tr><td>Password</td><td><input type="text" name="password" maxlength="30"></td></tr> <tr><td>Site Name</td><td><input type="text" name="title" maxlength="25"></td></tr> <tr><td>Site Description</td><td><textarea cols="40" rows="18" name="description" maxlength="750"></textarea></td></tr> <tr><td>Finish!</td><td><input type="submit"></td></tr> </form></table>'; } else { $query = mysql_query("SELECT * FROM sites WHERE username = '$username' LIMIT 1"); if(mysql_num_rows($query) > 0) { echo "Sorry, an account with this username already exists."; } else { $date = date("M-d-Y"); $ip = $_SERVER['REMOTE_ADDR']; //create their account mysql_query("INSERT INTO sites VALUES (null, '$username', '$password', '$name', '$description', 0, 0, 0, '$date', '$ip', 0)"); echo "You have successfully registered your site on NovaTops! <a href='login.php'>Login</a>"; } } } else { echo "One or more of the variables are not set."; } } } class login { function verifyLogin() { $username = mysql_real_escape_string($_POST['username']); $password = md5(sha1(sha1($_POST['password']))); if(isset($username) && isset($password)) { if(!$username || !$password) { echo "<table><form action='login.php' method='POST'> <tr><td>Username</td><td><input type='text' name='username' maxlength='20'></td></tr> <tr><td>Password</td><td><input type='password' name='password' maxlength='30'></td></tr> <tr><td>Finished?</td><td><input type='submit'></td></tr> </form></table>"; } else { $query = mysql_query("SELECT * FROM sites WHERE username = '$username' AND password = '$password'LIMIT 1"); if(mysql_num_rows($query) > 0) { echo "Congratulations! You have successfully logged in! <a href='index.php'>Home</a>"; $_SESSION['user'] = $username; } else { echo "It seems you've typed in the wrong username and/or password. <a href='login.php'>Try Again</a>"; } } } else { echo "One or more of the variables aren't set."; } } } ?> index.php <?php include_once('includes/config.php'); include_once('class_l.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title><?php echo $title; ?></title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link href="styles.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="wrapper"> <div class="top_text"><h1><a href="#"><?php echo $site_name; ?></a></h1> <h2><a href="#"><?php echo $slogan; ?></a></h2></div> <div id="content"> <div id="blog"> <div id="post-1" class="post"> <h2 class="title"><a href="#">Welcome to NovaTops!</a></h2> <h3 class="date">Created on April 06, 2011</h3> <div class="entry"> <p>Hello there! If your viewing this message right now, your on the awesome site called NovaTops! NovaTops allows you to register your site in our database, and then the site's script automatically starts to rank your site. The higher your rank, the more likely your site's going to get a ton of views!</p> </div> <div class="hr"> <hr /> </div> </div> <!-- end #post-1 --> <?php $displaySites = new displaySites(); $displaySites->grabSites(); ?> </div> <!-- end #blog --> <?php include_once('includes/navigation.php'); ?> <!-- end #sidebar --> <div style="clear: both; height: 1px;"></div> </div> <!-- end #content --> <div id="footer"> <p>Copyright © 2011. Design by <a href="http://www.flashtemplatesdesign.com/" title="Free Flash Templates">Free Flash Templates</a></p> <p><a href="#">Privacy Policy</a> | <a href="#">Terms of Use</a> | <a href="http://validator.w3.org/check/referer" title="This page validates as XHTML 1.0 Transitional"><abbr title="eXtensible HyperText Markup Language">XHTML</abbr></a> | <a href="http://jigsaw.w3.org/css-validator/check/referer" title="This page validates as CSS"><abbr title="Cascading Style Sheets">CSS</abbr></a></p> </div> </div> <!-- end #wrapper --> </body> </html> I apologize in advance for any misuse of terminology. I find that I am rather ignorant in such things. I'm working on a WordPress theme. Specifically on the part that shows the "next: link-to-next-post" and "previous: link-to-prev-post" links. Here is the code that I have: Code: [Select] <?php $nextvar=next_post_link('%link'); $prevvar=previous_post_link('%link'); ?> <?php if (isset($nextvar)) { ?> <h3>Next</h3> <p><?php next_post_link('%link'); ?></p> <? } ?> <?php if (isset($prevvar)) { ?> <h3>Previous</h3> <p><?php previous_post_link('%link'); ?></p> <? } ?> The first part intends to check if the links exist. And this works fine. However, the only output I'm getting are the values of $nextvar and $prevvar. The headers are nonexistent. What's wrong? Any help is much appreciated, and I thank you in advance. <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function popUp(URL,URL2) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL,'" + id + "', 'toolbar=0,scrollbars=1,location=0,top=10,left=10,statusbar=0,menubar=0,resizable=0,width=408,height=400');"); day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL2,'" + id + "', 'toolbar=0,scrollbars=1,location=0,top=10,left=450,statusbar=0,menubar=0,resizable=0,width=408,height=400');"); } // End --> </script>I have a map which shows sales people by location and if more then one sales person exists then I would need 2 pop up windows. This works great other than the fact that the areas with one sales person are getting a blank 2nd popup as a second salesperson does not exist. Any help would be appreciated. Thanks In Advance Edited by phpbeginner, 27 June 2014 - 05:52 AM. Looking for the best method to conditionally strip leading zeros for the following situation: $a = array(01, 02, 03, ... 10, 11); $a < 10 ? $a = ? : ''; For the following result: 1, 2, 3, ... 10, 11 Is there a better method than explode? Hi, I am trying to update the status of the record. I don't want to insert the record if not exists. I just want to know the update is success or not. I tried using affected_rows but it returns 0 if the existing status is same as the new status or if no record exists. Please help. |