-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
Could you show the code for sidebar.php?
-
Variable names are case sensitive. Try using $companyname The same goes for the other variables.
-
please help me, need help with captcha
cyberRobot replied to afallingpanda's topic in PHP Coding Help
The form action could be set to the same page. Then in the if test where the CAPTCHA is correct, you could use a header redirect to send valid submissions to sent.php. More information about the header redirect can be found here: http://php.net/manual/en/function.header.php -
$_SERVER['DOCUMENT_ROOT'] should already hold the information regarding your root folder. You should only need to modify what comes after the closing curly bracket. More information about the $_SERVER variable can be found here: http://php.net/manual/en/reserved.variables.server.php
-
Side notes: Is there a reason you're using persistent connections? If you don't need them, you could just use mysql_connect(): http://us3.php.net/manual/en/function.mysql-connect.php Also note that the mysql_ function have been depreciated. It's time to start considering the alternatives: http://us3.php.net/manual/en/mysqlinfo.api.choosing.php
-
If all the form fields are required, you could loop through the POST array. <?php foreach($_POST as $fieldName=>$fieldValue) { if($fieldValue == '') { print "<div>$fieldName is blank</div>"; } } ?> Side note: you'll also want to look into protecting your queries from SQL injections. One way is to use mysqli_real_escape_string(): http://php.net/manual/en/mysqli.real-escape-string.php
-
Getting values from database based on check boxes
cyberRobot replied to Phanindra's topic in PHP Coding Help
If you want to use JavaScript, you could use PHP to populate a JavaScript array. Once PHP is done and the page is sent to the browser, JavaScript can then be used to reference the information. You could try the following search for some examples: https://www.google.com/search?q=populate+a+javascript+array+with+php Note that you could also look into using AJAX to grab information from the database. -
Have you tried displaying the $row value in the while loop to see if it contains what you expect? You could use the same code as used in Reply 12. Of course, you would replace the $categories variable with $row.
-
As I mentioned in Reply 9, it looks like you are overwriting the array. To avoid the new array from wiping out what's already in place, you could try something like this: while($row = mysql_fetch_assoc($result)) { if(!isset($categories[$row['sub_cat_id']])) { $categories[$row['sub_cat_id']] = array('name' => $row['sub_cat_name']); } $categories[$row['sub_cat_id']]['topics'][$row['sub_id']] = array('name' => $row['topic_title']); }
-
Just add the line after the closing curly bracket of the while loop and before the foreach loop.
-
Have you tried outputting the array to make sure it contains what you expect. You could try adding the following after your while loop which creates the $categories array. print '<pre>' . print_r($categories, true) . '</pre>';
-
Overwriting $row shouldn't be the issue. The foreach loop isn't being executed in the while loop. Is the following line supposed to maintain all the topic titles? $categories[$row['sub_cat_id']]['topics'][$row['sub_id']] = array('name' => $row['topic_title']); If so, the issue is probably caused by the following line: $categories[$row['sub_cat_id']] = array('name' => $row['sub_cat_name']); Every time $row['sub_cat_id'] is the same, it overwrites the old value with the new array.
-
You should also consider using the LIMIT clause so that MySQL doesn't keep looking through the database when a match is found. $query="SELECT `username` FROM `user` WHERE `username`='$username' LIMIT 1";
-
The Google links provide examples on how to accomplish what you're asking. If you try it out and it doesn't work, feel free to post again with the updated code. Otherwise, perhaps someone else is willing to write the code for you. I honestly don't have the time. You could also consider posting something in the Freelancing forum. http://forums.phpfreaks.com/forum/20-php-freelancing/
-
You can use CSS to change the color: https://www.google.com/search?q=html+input+value+color Of course, that will change the color of any text entered in the input filed. If you only want the placeholder text to be a certain color, you can change it dynamically with JavaScript: https://www.google.com/search?q=javascript+text+color+style
-
I'm sure there's a better way, but you could try something like this: <?php $start = str_split($_POST['start']); foreach($start as $currKey=>$currLetter) { $start[$currKey] = "username LIKE '" . $currLetter . "%'"; } $result = mysql_query("SELECT * FROM $demo WHERE " . implode(' OR ', $start)); ?>
-
That appears to be a feature of SQL and not MySQL.
-
Perhaps the COUNT() function in MySQL will help: http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_count
-
It would be easier to see what was going on if the code was indented properly. It looks like you're missing some closing-curly brackets. I would double check those.
-
Which browser do you use? In Chrome and Firefox, you can right-click the "Showing all 2 results" text and click "Inspect element". This shows the source code for the text. From there you can see that the text is in a <p> tag with a class of "woocommerce-result-count". Just add some margin/padding to that class in your stylesheet.
-
Created a registration page, validation gone wrong!
cyberRobot replied to Tuscanbot's topic in PHP Coding Help
Your regular expression only tests if the name contains lower-case letters (a-z) and hyphens. Add "\s" for the name to include spaces. Your code also has the error message appear when the pattern is valid (aka: when you have a valid name). You'll want to add "!" (not) before the preg_match(): $pattern1 = '/^[a-z-\s]+$/'; if(!preg_match($pattern1, $memberName)) { echo "<p>Member name must contain only letters, space and hypen</p>"; } else { echo '<p>Good name!</p>'; } Also, note that you can make the regular expression case insensitive by adding an "i" after the pattern delimiter: $pattern1 = '/^[a-z-\s]+$/i'; -
It looks like you already have the JavaScript in place. It could be modified as follows: <input type="text" name="keyword" id="sbi1" value="default value" onfocus="if(this.value=='default value') this.value='';"> You would just need to change both instances of "default value" to whatever you need the default value to be. To answer your other question, the input field can be widened with the "size" attribute. More information about the <input> tag and its attributes can be found here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input
-
Which browser are you using to view the form? Note that the placeholder attribute doesn't work in older browsers like IE9. More information can be found here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input