-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
Sounds to me you need to alternate the background color for each message. To do this you'll need to initiate a counter, for this we'll use the variable $i. And we'll define the two background colors $i = 0; // init counter // define background colors $bg_color1 = '#999'; $bg_color2 = '#666'; Now when displaying each messsage you'd do have this $bg_color = (++$i % 2 == 0) ? $bg_color1 : $bg_color2; // alternavte background color echo '<div style="background-color: $bg_color">$message</div>'; // set the background color for the message
-
Can you post the html?
-
You need to pass the url to file_get_contents first. $contents = file_get_contents($url); // load the html into the variable libxml_use_internal_errors( true); $doc = new DOMDocument; $doc->loadHTML($content); // pass in the html ...
-
Warning: mysqli_query() expects parameter 1 to be mysqli
Ch0cu3r replied to lauren_etherington's topic in PHP Coding Help
Your arguments for mysqli_query are in the wrong order. The argument order is connection, query. Not query, connection Also you don't use mysqli_query when using mysqli_prepare before hand. If you are using prepared statements you need to use mysqli_stmt_execute Correct code for a prepared statement // procedural $query = $conn->prepare ("INSERT INTO newsitem (author,title,shortdesc,article,newsdate,status) VALUES (?, ?, ?, ?, CURDATE(), ?)"); mysqli_stmt_bind_param($query, 'sssss', $auth, $tit, $shrt, $art, $stat); mysqli_stmt_execute($query);. // OR as OOP $query = $conn->prepare ("INSERT INTO newsitem (author,title,shortdesc,article,newsdate,status) VALUES (?, ?, ?, ?, CURDATE(), ?)"); $query->bind_param('sssss', $auth,$tit,$shrt,$art,$stat); $query->execute(); -
Or use explode list($l68,$l58,$l59,$l60) = explode("|", $l67, 4);
-
Because on line 30 you are calling mysql_fetch_assoc, which will pull the first result from the query. Then on line 38 for the while loop condition you are calling dbFetchAssoc(), which is a user defined defined function and is probabcalling mysql_fetch_assoc internally, which will then loop over the remaining results from the query. Now each time mysql_fetch_assoc is called it increments the internal row counter by 1. When this happens the next row is returned from the result the next time mysql_fetch_assoc is called. This is why your code is always displaying one result less than what was returned from the query, One fix would be to reset the internal row counter before the while loop using mysql_data_seek(0); Or echo the product name and description within the while loop when $i is zero. So remove lines 29 to 33 and add if($i === 0) { echo '<h1>'.$row['cat_name'].'</h1>'.$row['cat_description']; } After the while loop construct - while ($row = dbFetchAssoc($result)) {
-
I think you have misunderstood my reply. The following code does exactly that echo "... <img src='../ratings/{$band['rating']}star.png'/> ..."; Your if/elseif condition only outputs one image for any case. And you are statically defining the image path for each case 0 through to 5. My code dynamically defines the image using one line of code. it is concatenating the rating into the image path. So if $band['rating'] has the value of 3 then it return /ratings/3start.png, if its 0 it'll return /ratings/0star.png below is your fixed code from your first post
-
The PHP code you posted works fine, it will find all div tags that have a name attribute set to "changeable_text" and return the nodes text value. To get all anchor tags on the page, you'd use //a as the xpath query. If you only to get the category links then you need to specify the container they belong to, eg $categories = '<div id="categories"> <a href="architecture.html">ARCHITECTURE</a><br /> <a href="art.html">ART</a><br /> <a href="avantgarde.html">AVANTGARDE</a><br /> </div>'; libxml_use_internal_errors( true); $doc = new DOMDocument; $doc->loadHTML( $categories); $xpath = new DOMXpath( $doc); // find all anchor tags within the <div id="categories"> tag $categorylinks = $xpath->query('//div[@id="categories"]/a'); // loop through the links and echo the link text foreach($categorylinks as $link) { echo $link->textContent .'<br />'; }
-
You could store the generated image in a session var instead. You'd then only save the image in the database once the user is happy with the image. Yes you can use a form for allowing the user to choose the text and color. Are you not using a form currently?
-
I assume your preview.php script uses GD Image library to generate the image. Basically you need to save the image to the filesystem first and then save the image path to the database. Once that is done you can output the generated image. Something like .... your current code for generating the image here .... // ----- THIS IS WHAT YOU WILL NEED TO DO NEXT ----- // before outputting the image you need to, // 1. generate a random name // 2. save image to filesystem and then // 3. save filepath in the database // where on the server to save the image $image_dir = 'images/'; // generate a random name for the image // function taken from php.net/manual/en/function.mt-rand.php#112889 function mt_rand_str ($l, $c = 'abcdefghijklmnopqrstuvwxyz1234567890') { for ($s = '', $cl = strlen($c)-1, $i = 0; $i < $l; $s .= $c[mt_rand(0, $cl)], ++$i); return $s; } $image_name = mt_rand_str(10) . '.jpg'; // the full image file path $image_path = $image_dir. $image_name; // save the image to filesystem imagejpeg($image, $image_path); // save image to database mysql_query("INSERT INTO image_table SET image = '$image_path'"); // now output the generated image imagejpeg($image);
-
php sessions not working on Apple iPad and iPhone
Ch0cu3r replied to AndieB's topic in PHP Coding Help
You have narrowed it down to mobile devices, but have you checked to make sure the mobile browser they are using is accepting cookies. PHP passes the session id number (by default called PHPSESSID) via cookies. This is how PHP identifies you and manages to remember the data stored in the session. If PHP cannot recieve the session id then the data stored will not be retrievable and so this could be why you are getting empty records in your database. To work out weather it is a cookie issue, try passing the PHPSESSID within the url. -
You're not ending/starting the echo before/after the if/elseif condition, speaking of which that could be coded as one line echo "<tr><td><div align=\"left\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"CCCCCC\" size=\"2\">This Review Is About:</font></br><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"FF6633\" size=\"4\"><b>{$band['Name']}</b></font></br><img src=\"http://www.inthisreview.com/Misc/tablespacersm01.png\"></br><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"CCCCCC\" size=\"2\">Review Posted:</br></font><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"FFFFFF\" size=\"2\"> ".date("F j, Y g:i a", strtotime($band["timestamp"]))."</font> </br><img src=\"http://www.inthisreview.com/Misc/tablespacersm01.png\"></br> <font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"FF0000\" size=\"2\">ITR Rating:</font> <img src='../ratings/{$band['rating']}star.png'/> </td>";
-
There is nothing wrong here with the XML syntax $ToXML .= '<row no="' . $UpdateCount . '">'; $ToXML .= '<FL val="Id">' . $ToID . '</FL>'; $ToXML .= '<FL val="' . $ToField . '">' . $this->FixID($FromData) . '</FL>'; $ToXML .= "</row>"; Where is $ToXML passed to next? The next process could be screwing with the XML structure.
-
What problems are you having? From what I see you extract the contents of the download and upload that to your site. To integrate it in your website you use one of the examples provided in the example directory. Edit. Just found out that yShout uses short open tags (<? ?>). You need to make sure PHP short open tags is enabled in order for yShout to function. This is a bad programming choice by the developers. You maybe able to enable short open tags by adding the following within a .htaccess file in the root of the yShout folder php_value short_open_tag 1 Otherwise you will need to convert all <? to <?php in all the .php files
-
Your code is finding the tld within the string, such as .com .gov etc and then wrapping the whole string within an achor tag. You need to first find the domain name within the string and then warp an anchor tag around it. I'd use a regex pattern form this $string = 'I went to google.com and search for "PHP Help" and found phpfreaks.com'; // the link $replacement = '<a href="http://$1" onmousedown="return false;" target="_new">$1</a>'; // find a domain and wrap in an anchor tag $string = preg_replace('~([a-z0-9_-]+\.(com|net|org|info|gov|biz|mz|lt))~i', $replacement, $string); echo nl2br($string);
-
Looking at the joomla docs you access admin control panel via sitename.com/administrator. If you do not know the username and password then you need to reset it. You will probably need to use method 2 here.
-
If you already you Joomla installed then login to the admin control panel? Did your boss not give you the username/password for it?
-
No. Never used Joomla so cant comment on how to use it, but I do know Joomla is free to use even for commercial use. Maybe you are referring to how much your company is paying for hosting? Joomla is a Content Management System. All data will most probably be stored in the database, not in indiviual html/php files.To change a pages content I assume you can log into the admin control panel and have an option to change the page contents from there. Maybe have a read of the documentation to learn your way around it, http://docs.joomla.org/
-
Your code only defines some queries but never executes them. What are you expecting to see? Your do not seem be sending any output.
-
Yes, mysql_* is now deprecated and could be removed from future versions of PHP.
-
Or leave the html as it is and use CSS to assign an image it it input.myButtonClass { background: url('path/to/image.jpg') no-repeat; width: 150px; # the width of the image in pixels height: 50px; # the height of the image in pixels }
-
You can use the RecursiveDirectoryIterator class. Working example http://www.codedevelopr.com/articles/recursively-scan-a-directory-using-php-spl-directoryiterator/
-
Is this code being ran when the form has been submitted? If its is then you don't need to create a hidden input field. Also using raw $_POST data in queries is not recommended you should atleast sanitize it. $sql=sprintf("INSERT INTO databasename (name1, age2, pic) VALUES ('%s','%s','%s')", mysql_real_escape_string($_POST['name1']) // sanitize name, protoct from SQL injection , intval($_POST['age2']) // sanitize age to integer , $pic[0]);
-
Shouldn't $pic be pic here $sql="INSERT INTO database (name1, age2, $pic) That is fine, however that will only store a maximum of 10 characters, if the filename is bigger than 10 characters it will be clipped.
-
$_POST[$pic[$0] ??? Save $pic[0] to a hidden input filed echo '<input type="hidden" value="'.$pic[0].'" name="pic" />'; Then use $_POST['pic'] to get the picture name.