-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
To clarify, I meant that you should be able to run preg_replace twice. The first would handle the "bus_it_requests" part. Then you would call preg_replace again to handle everything else.
-
You should be able to run the preg_replace for "bus_it_requests" first which would remove all the references. Then run the preg_replace for "bus".
-
Is your <form> tag set to GET or POST?
-
To clarify, $menuData isn't set until your while loop. Instead of using $menuData, you should look into mysql_num_rows() http://php.net/manual/en/function.mysql-num-rows.php You could change the if/else to say if(no rows found) { display message } else { run through while loop and display menus }
-
OK, I took a closer look at the code and there are a few other issues. The following code works for me: <form name="form1" method="post" action=""> <script type="text/javascript"> function showfield(activeDropDown) { var activeDropDown_selectedValue = activeDropDown.options[activeDropDown.selectedIndex].value; if(activeDropDown.name == 'size' && activeDropDown_selectedValue == 'Other') { document.getElementById('div1').innerHTML = 'Other: <input type="text" name="size_other" />'; } else if(activeDropDown.name == 'Color' && activeDropDown_selectedValue == 'Other') { document.getElementById('div2').innerHTML = 'Other: <input type="text" name="Color_other" />'; } } </script> <p>Size: <select name="size" id="size" onchange="showfield(this)"> <option selected="selected">Please select ...</option> <option value="1' H X 6" W">2' H X 1' 6" W</option> <option value="1' H X 2' W">1' H X 2' W</option> <option value="1' H X 1' 4" W">1' H X 1' 4" W</option> <option value="Other">Other</option> </select> <div id="div1"></div> <p>Color: <select name="Color" id="Color" onchange="showfield(this)"> <option selected="selected">Please select ...</option> <option value="Walnut Stain/Dark Brown">Walnut Stain/Dark Brown</option> <option value="Tan">Tan</option> <option value="Walnut">Walnut</option> <option value="Other">Other</option> </select> <div id="div2"></div> </p> Note the changs to the <select> and <div> tags. I've also made several changes to the JavaScript. The code is still a little crude, but it should get you rolling.
-
You could change it to something like: <?php function URLs($getURL = '') { $urlToReturn = ''; switch($getURL) { case 'yahoo': $urlToReturn="http://www.yahoo.com"; break; case 'google': $urlToReturn="http://www.google.com"; break; case 'phpfreaks': $urlToReturn="http://www.phpfreaks.com"; break; } return $urlToReturn; } echo URLs('google'); sleep(10000); ?> Note that the code is untested.
-
Utilize comments throughout your code. Comments can be very helpful when editing the code down the road. I don't know how many time I've come across code and thought "OK, what was I doing here?" Comments also make it easier for others to understand your code if the website gets turned over to someone else. Take care with naming your variables, database tables, filenames, etc. Let's say you wanted to name something class. If you every need to search for all mentions of "class", you'll likely get a lot of bad matches. Especially since the class attribute is commonly utilized if you're using CSS. Don't be afraid to ask for help. PHP Freaks is an excellent resource if you have any questions.
-
Are you using mysql_real_escape_string(); maybe that's one thing that check_input() does? http://php.net/manual/en/function.mysql-real-escape-string.php If not, it would be fairly easy to change someone's (or everyone's) password with a quick SQL injection.
-
You could streamline the code by doing something like (the code is untested): <?php ... //REMOVE EXTRA SPACE $country = trim($country); $state = trim($state); $city = trim($city); //PREPARE SQL QUERY $sql = "SELECT username, country, state, city FROM users WHERE"; $connector = ''; if($country != '') { $sql .= $connector . " users.country='$country'"; $connector = ' AND'; } if($state != '') { $sql .= $connector . " users.state='$state'"; $connector = ' AND'; } if($city != '') { $sql .= $connector . " users.city='$city'"; $connector = ' AND'; } //RUN THE QUERY $data = mysql_query($sql); while($info = mysql_fetch_array( $data )) { ... ?> Also note that the "users." part in the WHERE clause isn't needed if you don't plan to use a SQL Join. Note that you should look into alternatives to using $_SERVER['PHP_SELF']. There are security risks involving its use. http://www.google.com/search?q=php_self+security+issues I usually just type the page name instead. Some say you can leave action attribute blank, but I've heard leaving it blank also has some security risks. I haven't heard what those risks are though. I apologize for assisting in the slight takeover of the thread with all the SELECT * talk. I'm just very curious on the why.
-
Sorry, I'm not sure I understand. Let's say I have a database with 30 fields and I need them all for the page. How does typing them out less resource intensive then using SELECT *?
-
Out of curiosity, what's wrong with using SELECT *? Of course if you only need a couple fields from the database it's more efficient to list out the columns, but if you need all the columns shouldn't you use SELECT *?
-
One issue with the code is that you're using single quotes inside single quotes. <?php ... $sql = mysql_query("INSERT INTO messages(userid)values('$_SESSION['id']')"); ... ?> You could do something like: <?php ... $sql = mysql_query("INSERT INTO messages(userid)values('" . $_SESSION['id'] . "')"); ... ?>
-
If you're trying to make the block of code easier to understand for other people, you should look into adding comments. http://php.net/manual/en/language.basic-syntax.comments.php
-
Not exactly what you asked for, but you could explode the entire string based on the space character. Then test each piece with substr(). <?php ... if(substr($currPiece, 0, 11) == 'http://www.') { $urlFound = true; } elseif(substr($currPiece, 0, 4) == 'www.') { $urlFound = true; } else { $urlFound = false; } ... ?>
-
You could always try it out. I would imagine that it's not going to work; but I'm not positive on that. You may want to review the PHP manual for Variable Scope: http://php.net/manual/en/language.variables.scope.php
-
What about the e-mail? That's most likely not secure.
-
You could try out strpos() http://php.net/manual/en/function.strpos.php
-
It's probably a user-defined function which calls mail()
-
Variables won't work in single-quoted strings. You'll need to change it to: echo "<p onclick=\"popUp('$gmail')\">lkjlkjlkjlkjlkjlkj</p>";
-
In aanmelden.php, you could assign the type to a variable ($type for example). Then pass it to both functions. <?php ... $type = 'mysql'; connectdatabase($type, "[ledensysteem]"); ... query($type, "SELECT username FROM phpfreaks WHERE password = private"); ... ?> Of course you'll need to modify the query function to accept the second argument.
-
How to get value too use for later on?
cyberRobot replied to xwishmasterx's topic in PHP Coding Help
As Nightslyr suggested, if "id" is the primary key and/or only gives one record every time you don't need the while loop. -
How to get value too use for later on?
cyberRobot replied to xwishmasterx's topic in PHP Coding Help
You would use the $row variable created from the mysql_fetch_array() call. For example: $row['team_id'] -
As a side note, according to the mysql_query() function description the query string shouldn't end with a semicolon: http://php.net/manual/en/function.mysql-query.php <?php //OLD CODE $sql= "SELECT * FROM root123 ORDER BY ID;"; //CHANGE TO $sql= "SELECT * FROM root123 ORDER BY ID"; ?> With that said, PHP doesn't seem to throw any errors or warnings for the extra semicolon. I also don't see any errors with mysql_error().
-
Just to clarify, removing the first mysql_fetch_array() call should fix the issue. <?php ... $sql= "SELECT * FROM root123 ORDER BY ID;"; $result = mysql_query($sql, $con); $rij = mysql_fetch_array($result); //<--- REMOVE THIS ONE ... while ($rij = mysql_fetch_array($result)){ ... ?>