-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
error need help,checkbox POST form cant work!
cyberRobot replied to wolvesbane's topic in PHP Coding Help
Once the script is being processed as PHP (see Ch0cu3r post above), you should get a parse error for the following line: echo "<input type='checkbox' name='office' value='on' checked onclick='this.form.submit();'";> Note the greater than symbol outside of the quotes. -
Are you referring to the function definition for states()? If so, it doesn't seem to be included in the posts above...
-
PHP - Security for html form dynamically adding rows to CSV
cyberRobot replied to mikecaba's topic in PHP Coding Help
PHP has a built-in function to validate email addresses. More information can be found here: http://php.net/manual/en/filter.examples.validation.php -
HTML select and option work with PHP database
cyberRobot replied to sigmahokies's topic in PHP Coding Help
How is the "birthdate" field stored in your database? If it is stored as a string and only contains the month, you would need to add quotes around the value from $select. $birthdate = "SELECT CONCAT(FirstName,' ',LastName) AS Birth FROM Members WHERE birthdate = '" . $select . "'"; Side note: you'll want to look into using prepared queries...or use mysqli_real_escape_string() to protect yourself from SQL injection attacks. -
For your form, where is $prospect_id defined? Also, have you set PHP to display all errors and warnings? Note that you can add the following to the top of your script(s) during the debugging process: <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?>
-
I would imagine that you're not going to get too many entries where you'll get a series of letters without spaces. With that said, you could try the word-wrap property in CSS: https://developer.mozilla.org/en-US/docs/Web/CSS/word-wrap
-
You could use an if construct to test $key in the foreach loop. Then just insert a line break when the 5th item is found. http://php.net/manual/en/control-structures.if.php
-
You could specify a key for the last element of the array. $fun = [ 'First Word' => 'Programming', 'Second Word' => 'in', 'Third Word' => 'PHP', 'Fourth Word' => 'is', 'Fifth Word' => 'fun!', 'Full Sentence' => 'Programming in PHP is fun!' ];
-
Creating a sub and sub-sub menu using category and sub-categories.
cyberRobot replied to thara's topic in PHP Coding Help
Have you tried modifying the code so that the sub-sub menu is within the <li> tag of the sub menu? So this <li><a href='products.php?product=22'>Computer Accessaries</a></li> <ul class='sub-menu'> <li><a href='products.php?product=24'>Network Cables</a></li> <li><a href='products.php?product=23'>USB Cables</a></li> </ul> Should be this <li><a href='products.php?product=22'>Computer Accessaries</a> <ul class='sub-menu'> <li><a href='products.php?product=24'>Network Cables</a></li> <li><a href='products.php?product=23'>USB Cables</a></li> </ul> </li> -
The IDs could also be passed with a delimiter. For example: <?php if(isset($_GET['myIDs'])) { $_GET['myIDs'] = explode('|', $_GET['myIDs']); echo '<pre>' . print_r($_GET['myIDs'], true) . '</pre>'; } ?> <a href="?myIDs=1|3|4">Test</a>
-
That sounds like a good start! Welcome!
-
Loop through html, grab all URLS, and replace hrefs/srcs
cyberRobot replied to noodlez's topic in PHP Coding Help
From what has been mentioned so far, DOMDocument seems like it would work. Of course, you would need to expand the example I mentioned earlier so that it can detect more than just links in <a> tags. -
Loop through html, grab all URLS, and replace hrefs/srcs
cyberRobot replied to noodlez's topic in PHP Coding Help
Have you tried using PHP's DOMDocument class? http://php.net/manual/en/class.domdocument.php Once the HTML code is loaded into DOMDocument, you could get all the <a> tags with getElementsByTagName(). Then you can use getAttribute() to get the href values and setAttribute() to modify them. -
Are you entering numbers into the "address" field? If so, that's not going to work with how the regular expression is set up. Is there a reason you're trying to validate the mailing address? I imagine it will be difficult to make sure every valid character is accounted for.
-
One thing that I noticed is that the email entered through the form is being saved to $email. $email = $_POST['email']; But the if test uses $email_from. if(!preg_match($email_exp,$email_from)) {
-
@klio909 - I added tags around the code in your original post. Unfortunately, your form code seems to have disappeared with the change. Would you mind posting the form code again? Sorry for the inconvenience!
-
Has the form worked before? Do you always get those errors no matter what is entered into the address and email address fields? It would also help to know what you are entering into those form fields. Side note: PHP has a built-in process for validating email addresses. More information can be found here: http://php.net/manual/en/filter.examples.validation.php
-
The topic has been moved.
-
Have you considered using a foreach loop to process the main array? Inside the loop, you could process each car individually. <?php $cars = array ( array("Volvo",22,18), array("BMW",15,13), array("Saab",5,2), array("Land Rover",17,15) ); foreach($cars as $currCar) { print '<pre>' . print_r($currCar, true) . '</pre>'; } ?> To be honest, I'm not sure what's going on in your code. So I'm not sure how much help this would be. But you could insert all the records in the database by doing something like this: <?php $cars = array ( array("Volvo",22,18), array("BMW",15,13), array("Saab",5,2), array("Land Rover",17,15) ); $carInformation = array(); foreach($cars as $currCar) { $carInformation[] = "('" . implode("', '", $currCar) . "')"; } $sql = "INSERT INTO yourDatabaseName (yourColumn1, yourColumn2, yourColumn3) VALUES " . implode(', ', $carInformation); print $sql; ?>
-
No problem; glad to help!
-
With that said, what happens when you get two people with the same first name? If you add "John Smith", for example, the information will be overwritten when you add "John Jones". Instead of using the first (or last) name as the array key, you'll want to use a value that's going to be unique. Basically, you could let PHP create the key for you which would be a number. First and last name would then be stored as a multi-dimensional array. $this->persons[] = array( 'firstName' => $first_name, 'lastName' => $last_name );
-
You mentioned that you tried sort() and usort() and scootstah was wondering what that code looked like. Since the first names are stored as the array keys, you would use ksort() to sort by first name. Sorting by last name would be done with sort() as others have suggested. Try doing something like the following: public function Sort() { if($_GET['alphabetical'] == 'ln_first') { //sorting by last name sort($this->persons); } else { //else...sorting by first name ksort($this->persons) } $str = "<table>\n"; foreach ($this->persons as $first_name => $last_name) { $str .= "<tr><td>$first_name</td><td>$last_name</td></tr>\n"; } $str .= "</table>\n"; return $str; }
-
Transferring columns from one table to another
cyberRobot replied to heartsblack's topic in MySQL Help
Are you just copying the table structure and data to a new table? If so, you could use the "Copy table to" feature under the Operations tab in phpMyAdmin.