-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
Merging data from two multidimensional arrays
Ch0cu3r replied to StevenTompkins's topic in PHP Coding Help
Shouldn't you know that? Its your code is int it? You did not mentioned you tried using that function. The only other function you could try is array_merge_recursive -
Merging data from two multidimensional arrays
Ch0cu3r replied to StevenTompkins's topic in PHP Coding Help
As you have not posted any code I can only direct you to the documentation for array_merge. -
Try removing or die(mysql_error()) as part of the while loop condition! That should not be there. In fact what is more than likely happening is PHP is getting to the last row and killing the script. This happens becuase mysqli_fetch_array() will return false when there are no more rows to fetch from the resultset and so the or die statement will trigger and this will kill the script. Also please wrap your code in or click the <> button in the editor when posting code. EDIT Why are using mysql_error()? The mysql functions and mysqli functions are not compatible with each other. You should not be using the old mysql_* functions as they are deprecated meaning they are no longer supported. You should stick to just using the mysqli functions.
-
Help With 'include' statement - Can't Get Mine To Work
Ch0cu3r replied to Major_Que's topic in PHP Coding Help
I Agree with tryingtolearn. The include statements are working fine as you can see the html output of articles.php in the (HTML) source code for all your pages (right click > view source). There is most likely an issue with your HTML or CSS for why the the sidebar div does not show on the other pages. EDIT. I think I have found the course. In your other pages you have different negative margins applied to the #sidebar selector. Removing the negative margins and the sider appears fine on all the other pages. You may find it easier to use floats instead playing about with margins. -
So what have you tried?
-
No not at all. You will need to come up with your own way of parsing the data into the necessary variables. Is the data you posted from the output of another command?
-
Wheres the date? I guess you mean to say you want to sort the files in the order they where created?
-
Your code will not do anything unless a variable called $_POST['submitted'] exists. Try naming your submit button as submitted <input type="submit" name="submitted" />
-
So you want to get the raw and usable disk space returned by the command into variables. To do that you need to parse the string. Example code // using regex capture the raw and usable free diskspace values from the last line preg_match('~(\d+)\s+(\d+)$~', $data, $matches); // remove first item from $matches array array_shift($matches); // convert the remaining values into variables list($raw, $usable) = $matches; // output values echo "Raw: $raw<br />Used: $usable";
-
There is nothing wrong with the code you posted. Do you mean you want to save the output to the $photo_form variable instead of outputting it straight away? You can change lines 13 - 18 to $photo_form .= $options; Then define the options into the $options variable when you process your query results. Example $sql = "SELECT DISTINCT gallery FROM photos WHERE user='$u'"; $query = mysqli_query($db_conx, $sql); $options = ''; // process query. Define options into variable while($option = $query->fetch_object()) { $options .= '<option>' . $option->gallery . '</option>'; } . Or just replace lines 13 to 18 with the following // concatenate each option to $photo_form while($option = $query->fetch_object()) { $photo_form .= '<option>' . $option->gallery . '</option>'; }
-
You are seeing the result in one line because web browsers ignore whitespace characters. I bet if you right click > view source you'll see the output to be in multiple lines. To have your output display in multiple lines either pass $data to nl2br or wrap $data in <pre></pre> tags. All you do is define your sql query in a string. You'd use those variables as the values. You then execute the query. Basic example // connect to mysql $mysqli = new mysqli('localhost', 'user', 'pass', 'database'); // values $var1 = 'foobar'; $var2 = 'phpfreaks'; // define query $sql = "INSERT INTO table SET column1='$var1, column2='$var2'"; // execute query $mysqli->query($sql);
-
What is the array structure for $categories_array? You may need to use array_multisort instead of ksort
-
Then you need to connect to your database and run an sql query to fetch the data you require Do you know how to do that?
-
All you need is a form with a text input field so the user can enter a number You can generate a random number using the rand function. When the form has been submitted you can receive the number the user entered from the $_POST superglobal variable (provided your forms submit method is set to post - Otherwise use $_GET) To compare values you need to use an if statement with the == comparison operator To display an image use a the <img> tag Have ago yourself. If you get stuck then post what you have tried.
-
Yes that you need to do. But you will not need the password condition in your query. Example code if(isset($_POST['login'])) { // return the hashed password where the email address matches $stmt = $pdo->prepare("SELECT password FROM hash_test WHERE email=:email"); $stmt->execute(array( ':email' => $_POST['email'], )); if ($stmt->rowCount() ==1) { $password = $_POST['password']; list($password_hash) = $stmt->fetch(PDO::FETCH_NUM); // get the hashes password from the results set // has the correct password been given for this password hash? if (password_verify($password, $password_hash)) { /* Valid */ echo "Right"; } else { /* Invalid */ echo "wrong"; } } }
-
The parenthesises are optional.
-
Concatenate the answer echo "$x+$y = " . ($x+$y); // Output
-
The hashed password needs to be stored in the database. You will run a query to return the hashed password for the username provided. You use password_verify to confirm the user has entered the correct password.
-
It will redirect urls such as www.website.com/microsite or website.com/microsite to http://subdomain.website.com/microsite permanently (thats what the R=301 stands for)
-
There are quite a few issues with your code. You are using out dated coding techniques as your code relies on a setting called register_globals to be enabled in order for it to function. This setting has since been disabled ~10 years ago and most recently been removed completely. You should be using superglobal variables for receiving user input in your script. The only code that should be in there is your database credentials and the necessary code to connect to mysql. There should not be code in there for setting up your tables as this will happen each times the page is loaded. Also why are using mysql and and mysqli within the check_tables function? You have already connected to mysql yet your create a new connection using mysqli to perform a SHOW TABLES LIKE query. This is not needed just use a CREATE TABLE IF NOT EXISTS query to create your tables. Also you should stick to executing each query separately and not run multiple queries at once. If your are going to be inserting multiple values into the same table then wrap each set of values in parenthesizes and separate them with a comma. EG INSERT INTO table_name (... SET OF VALUES 1 ...), (... SET OF VALUES 2 ...), ... etc Why are connecting to mysql for the second and third time (lines 6 and ? You have already included login.php which has already connected to mysql! After this there are quite a few syntax errors. There is no closing curly brace for the rock_paper_scissors_lizard_spock function. On line 119 you have left off the semi-colon. On line 157 you have an incomplete echo statement, you start a string but dont finish it. On line 162 is a nother malformed echo statement this because you have ". in the middle of the string. That about the main issues with the script. There are still many more issues with the code. IMHO it is a complete over kill to use a database to for this simple game. Using sessions or cookies will be more suitable. Not sure why that is needed? PHP cannot do that.
-
Last time I checked nl2br does not remove the newline characters! It only adds <br /> after them. I have no issues with the following to remove newlines from a string $string = str_replace(["\r\n", "\r", "\n"], '', $string);
-
So you want to remove newlines characters such as \r\n? Then use str_replace nl2br converts newline characers to a html line break tag <br />. This function should be used when you are displaying text to the user. I do not recommend you using it when saving data to the database.
-
What are you validating a url or an email address? If it is an email address then dont bother with your own regex instead use filter_var with the FILTER_VALIDATE_EMAIL flag. Or use the FILTER_VALIDATE_URL flag for urls.