-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
You can add JQuery accordion effect with a few changes to my example code <div class="content archive"> <h3><?php echo _("Archive"); ?></h3> <ul id="archiveList"> <!-- Give parent ul id --> <?php $startDate = strtotime('2011-10-01'); $endDate = strtotime(date('Y-m-d')); $startYear = date('Y', $startDate); $endYear = date('Y', $endDate); // loop through years for($year = $startYear; $year <= $endYear; $year++) { // calcuate start/end months $startMonth = ($year == $startYear) ? date('m', $startDate) : 1; $endMonth = ($year == $endYear) ? date('m', $endDate) : 12; $class = "archive$year"; $url = URL . "blog/archive/love/$year/"; // make new list item for year, enclose new list for months in year echo " <li><div>$year</div>\n <ul>\n"; // <-- wrap year with a div // loop through months for($month = $startMonth; $month <= $endMonth; $month++) { $_month = date('F', mktime(0, 0, 0, $month, 1, 0)); ?> <li class="archiveLink"> <p><a href="<?php echo URL . "blog/archive/love/$year/$month" ?>"><?php echo _($_month); ?><span>»</span></a></p> </li> <?php } // end enclosed month list echo " </ul>\n </li>\n"; } ?> </ul> </div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> // JQuery accordian $('#archiveList ul').slideUp(300); // on page load hide months (slides up) $("#archiveList > li > div").click(function(){ $(this).next().slideToggle(300); // clicking year slides months down }); $('#archiveList ul:eq(0)').show(); // make sure years stays visible </script>
-
Query failed only on IE browser
Ch0cu3r replied to LucasGala's topic in PHP Installation and Configuration
Add some more debug information to the ExecRequete function // Execution d'une requête SQL function ExecRequete($requete, $connexion){ $resultat = mssql_query($requete, $connexion) or echo('<p style="border:red 2px solid;padding:10px">DEBUG QUERY: <pre>' . $requete . '</pre></p>'); if($resultat){ return $resultat; } else{ echo "<b>Erreur dans l'execution de la requete '$requete' .</b>"; exit; } } // Fin de la fonction ExecRequete -
That is because you still have the form processing code in create.php. The form processing code in I am referring to are lines 192 to line 329. Cut and paste those lines into form_process.php replacing my example code. Once you have moved the code delete the following lines from form_process.php //Decide On What Path To Take SWITCH ($_GET['atgard']) { CASE "skapa": and break; DEFAULT: } Those lines are not needed.
-
You want to see if the query returned any results using the mysqli_num_rows not mysqli_fetch_array function login($username , $password) { GLOBAL $dbc; // <--- BAD PROGRAMMING $user_id = user_id_from_username($username); $username = sanatize($username); $password = md5($password); $query = mysqli_query($dbc, "SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"); // check query return any results (results are returned as rows) // if we have a result then the login credentials matched if(mysqli_num_rows($dbc) > 0) { return true; } // no results found so return false return false; } Please use code tags when posting code. Press the <> button before pasting code into the reply box.
-
You wont be able to turn the image into a link, as images requested with <img /> the browser is expecting an image to be returned not html. But what you can do is check if the request for the image is from your site, by checking the HTTP_REFERER header. If it doesn't match serve a different image which will say something like "See my webcam at http://yourdomain.com". This is called anti image hot linking. Search google for this term and there be some php examples of this.
-
Your code can be dramatically reduced, yes. Your doing a lot of code repetition. When you start to name variables like $var1, $var2, $var3 etc you should be using arrays. When you start to do repetitive code such as lines 26 to 113 you should be using loops. So if I want to list the numbers 1 to 1 million. Im not going to sit here and type all the numbers 1 to 1 million. I'm going to use a loop. for($i = 0; $i < 1000000; $i++) { echo "$i<br />"; } In 3 lines of code I have generated 1 million lines!
-
Form doesn't send any data if form-file is loaded into index.php
Ch0cu3r replied to bonaca's topic in PHP Coding Help
Does contact.php contain PHP code? .load() will only return the output from this script, no PHP source code is returned. For example if contact.php had in it $myVar = 'abc'; And then in index.php you had echo $myVar; the variable $myVar will be undefined. PHP code will not be passed back to index.php If contact.php contains no PHP code then you are fine to use .load. -
radio button choice needs to control dropdown menu content
Ch0cu3r replied to edfou's topic in PHP Coding Help
@Barand your code remembers the selected checkbox. I think edfou also wants the chosen team option to be remembered too. I have modified Barand's code with JQuery which remembers the chosen gender and the corresponding team option <?php // if no form has been submitted then populate selectedOption array with no value $selectedOptionArray = ''; if(isset($_POST['btnsubmit'])) { $gender = $_POST['gender']; $key = $_POST['option']; // populates the javascript selectedOption array with the posted values (line 40) $selectedOptionArray = "'$gender', '$key'"; } ?> <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> // when page has loaded change gender $(document).ready(function() { // list male/female team options here var teamOptions = { // male values and texts m: { 'm1' : 'aaa aaa', 'm2' : 'bbb', 'm3' : 'ccc' }, // female values and texts f: { 'f1' : 'xxx', 'f2' : 'yyy', 'f3' : 'zzz' } }; /* this will be populated by PHP. It'll used in changeOption to select the POST'd value selectedOptions[0] = the selected gender checkbox selectedOptions[1] = the selected option value */ var selectedOption = Array(<?php echo $selectedOptionArray; ?>); // function that populates the "option" select menu // selected gender is passed to this function function changeOption(gender) { // clear existing entries $('#option').html(''); // for each option for chosen gender $.each(teamOptions[gender], function(key, value) { // add option $('#option') .append($('<option>', { value : key }) .text(value)); }); // select the chosen option if( selectedOption.length > 0) { $('select[name="option"]').find('option[value="'+selectedOption[1]+'"]').attr("selected",true); } } // when page loads select the chosen option if(selectedOption.length > 0) changeOption(selectedOption[0]); // when the gender changes display new list $('input[name=gender]:radio').click(function() { changeOption(this.value); }); }); </script> </head> <body> <form action="" method="post"> <b>Gender</b><br /> <?php // builds checkboxes with php $genders = array( 'm' => 'Male', 'f' => 'Female'); foreach($genders as $value => $label): // check the checkbox that was checked when form was submitted // $checked is defined on line 6 $checked = (isset($gender) && $gender == $value) ? ' checked="checked"' : ''; ?> <input type="radio" name="gender" value="<?php echo $value ?>"<?php echo $checked; ?> /> <?php echo $label; ?><br> <?php endforeach ?> <br> <b>Team</b> <select name="option" id="option"> <option value="">- team options -</option> </select> <br><br> <input type="submit" name="btnsubmit" value="Submit"> </form> </body> </html> -
Form doesn't send any data if form-file is loaded into index.php
Ch0cu3r replied to bonaca's topic in PHP Coding Help
Can not use php to include contact.php? <?php include 'chapters/contact.php'; ?> Using PHP include will return the raw php source code of contact.php. The PHP code in contact.php will be parsed at the same time as index.php. If you use jquery $.load() function it'll only return the html source code of contact.php (the output). -
Someone please advise/help. Unexplainable behaviour
Ch0cu3r replied to codecreative's topic in PHP Coding Help
http://codex.wordpress.org/Category:WP-Cron_Functions -
Okay. Post create.php and form_process.php here I will check it out
-
Someone please advise/help. Unexplainable behaviour
Ch0cu3r replied to codecreative's topic in PHP Coding Help
Not sue if this article may help you http://tommcfarlin.com/wordpress-cron-jobs/ -
So why my heredoc statement is not accepted by php ?
Ch0cu3r replied to cyber_alchemist's topic in PHP Coding Help
There is a trailing space after ENDHTML on line 22. -
Hey guys, I need your help with this code, thanks in advance.
Ch0cu3r replied to pickamaterina's topic in PHP Coding Help
When you perform queries on database you need to make sure they execute ok. During development you need to to output as much debug information as possible when something your expect to happen doesn't happen, if that makes sense. You said earlier when you use mysql_query it didn't work. So I recommended you add echo mysql_error to see if the query returns an error. You can remove the debug code when everything is working. So does your query return any errors when your run your script? -
Hey guys, I need your help with this code, thanks in advance.
Ch0cu3r replied to pickamaterina's topic in PHP Coding Help
Well you need to check if mysql_query is returning any errors $sql = "INSERT INTO com (name, lastname, email, coment) VALUES('$name', '$lastname', '$email','$coment')"; if(mysql_query($sql)) { echo "<script type='text/javascript'>alert('Thanks.'); window.close();</script>"; } else { echo 'Error: ' . mysql_error(); // I have commented out the line below. //echo"<script type='text/javascript'>alert ('$error'); window.close(); </script>"; } -
Hey guys, I need your help with this code, thanks in advance.
Ch0cu3r replied to pickamaterina's topic in PHP Coding Help
Because you're not doing anything with the query $result = "INSERT INTO com (name, lastname, email, coment) VALUES('$name', '$lastname', '$email','$coment')"; You have just defined a query to $result. PHP doesn't see it as a query, it just sees it as a string. What do you expect that line to do? -
Need a little help with a couple of PhP issues
Ch0cu3r replied to grungeandgaze's topic in PHP Coding Help
No That is what makes the unix timestamp for the date you enter in the form by looks of things. -
Just trying to shred some more light on this $sql = 'SELECT distinct `field1`, ` field2` FROM `table1` partition (p1) Inner Join table2 On table1.id=table2.id Where table2.field1 = "something" And table2.field2 = " something_else"'; Is that a true representation of your query. with table names being substituted for fieldX and tableX Any reason for partition? As the alias p1 doesn't seem to be referenced anywhere in that query. Maybe posting the actual SQL query and dummy data will help further.
-
If you want the modal to appear without the page reloading when the submit button is pressed you'll need to use ajax. PHP is ran on the server. Javascript is ran in the browser which is executed way after PHP has finished processing the script. You cannot send data to and from the server without the page reloading, unless you use ajax. If you implement my ajax method (just the javascript code) in post#13 to your code in post #6 (which I assume is create.php. and give the form an id of mailSetupForm)). and set the ajax request to create.php it should run as you expect, but the page will duplicate!. You only want the modal returned from the ajax request. This is happening because you process the form data from lines ~160 to ~280. You output the modal on line ~298. Any html/text outputted before that line will be sent back to the ajax request and this why the page duplicates. Moving the PHP code on lines 160 - 280 in create.php to form_process.php will prevent this from happening,as that file is only returning the html for the modal when the user has been added to the database not the entire page of create.php! form_process.php can be named to any thing just like any other php file you create. You just reference that file in the ajax request, like you would with any file you link to. Hope I have made it clearer now what I'm trying to get your to implement. if you're not happy with this then please say.
-
Need a little help with a couple of PhP issues
Ch0cu3r replied to grungeandgaze's topic in PHP Coding Help
no, that is where it is getting the raw data from the database (the 1262329261 value) and is storing the data in xml format. Somewhere else is another php file which processes this xml data. The line of code you're looking for is in this format $albumreleasedate = ... something here...; it may look: $albumreleasedate = date('jS F Y', ...somthing here with AlbumReleaseDate in it...); -
Ok. Ignore the ajax and modal for now, by commenting out the javascript. First lets make sure form_process.php is processing the data correctly. Modify your form so it just submits to form_process.php. When your fill in the form does form_process.php give any errors and is it doing what you want it to do. It should be adding the user to database and only showing the HTML for the modal.
-
Need a little help with a couple of PhP issues
Ch0cu3r replied to grungeandgaze's topic in PHP Coding Help
Its will be much bettee if you changed the date format where $albumreleasedate is defined. If your want to change the format of the date latter on this solution may not work.