-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
Its not working because you only go to add the user when $_POST is not empty if(!empty($_POST)) In your form <form class="form-signin" role="form" action="convoy.php" method="post"> <button class="btn btn-lg btn-primary btn-block" type="submit">Sign up for this convoy</button> </form> There is nothing to submit, so no data will be in $_POST. This is why no user is being entered into your database. I recommend adding a name to your submit button, eg <button class="btn btn-lg btn-primary btn-block" name="addConvoyUser" type="submit">Sign up for this convoy</button> Then change if(!empty($_POST)) to if(isset($_POST['addConvoyUser'])) Also when using sessions make sure you have called session_start() at the top of your script
-
Only need to post the relavent code. I recommend posting three lines you are commenting out and the 10 lines before it If you are getting blank page then PHP has encountered an unrecoverable error. Those two lines should force PHP to show errors. If not then look at your servers error logs
-
I have gone a head and cleaned your code up (untested). There was a lot of unnecessary if statements/variables used. Have a look through the comments to see what going on <?php // Include Databse include "common.php"; // validation errors $error = array(); // Check if form has been submitted if (isset ($_POST['delete'])) { // get the filename. See php.net/basename for more info $filename = basename($_POST['filename']); // get file extension, see php.net/pathinfo for more info $ext = pathinfo($_POST['filename'], PATHINFO_EXTENSION); // allowed file extensions $allowedExtensions = array('jpeg','jpg','gif','png','bmp'); // Check ID is not empty if(empty($_POST['id'])) { $error[] = "Please enter a ID"; } // Check filename is not empty if(empty($filename)) { $error[] = "Please enter a Filename"; } // Check valid file extension used if(!in_array($ext, $allowedExtensions)) { $error[] = "Invalid file extension"; } // path to the image $file_to_delete = 'images/' . $filename; // delete file from database if there are no errors if (empty($error)) { // Checks the file exists and that is a valid image if(file_exists($file_to_delete) && getimagesize($file_to_delete)) { // Delete File From Directory unlink($file_to_delete); } else { $error = true; $error[] = "File not found please check Filename"; } try { // Run Query To Delete File Information From Database $query = "DELETE FROM `test` WHERE `id` = :id"; $stmt = $db->prepare($query); $stmt->execute(array('id' => intval($_POST['id']))); } catch(PDOException $ex) { die("Failed to run query: Please report issue to admin"); } $status = "File Deleted"; } } try { $query = "SELECT id,photo FROM test"; // Run Query To Show The Current Data In Database $stmt = $db->prepare($query); $stmt->execute(); } catch(PDOException $ex) { die("Failed to run query: Please report issue to admin"); } $rows = $stmt->fetchAll(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Delete Image</title> <style type="text/css"> .table { text-align: center; } .table { font-weight: bold; } </style> </head> <body> <form action="delete.php" method="post" enctype="multipart/form-data" class="table"> Please enter the Filename and ID of the image you wish to delete <table width="178" align="center"> <tr class="table"> <td width="144" class="table">Filename</td> <td width="30" class="table">ID </td> </tr> <tr> <?php // Show validation errros here if(!empty($error)): ?> <td>Error: <?php implode('<br />', $errors); ?></td> <?php endif; ?> <td><input name="filename" type="text" value="<?php echo $filename; ?>" /></td> <td><input name="id" type="text" id="id" value="<?php echo $id; ?>" size="3" maxlength="4" /></td> </tr> </table> <p><?php echo $status; ?><br /> <input type="submit" value="Delete Selected Image" name="delete" /> </p> <p>IMAGE DETAILS </p> <table width="400" align="center" class="table"> <tr> <th width="61">ID</th> <th width="185">Filename</th> <th width="138">Image</th> </tr> </table> <table width="400" align="center" class="table"> <?php foreach($rows as $row): ?> <tr> <td width="61"><?php echo $row['id']; ?></td> <td width="185"><?php echo $row['photo']; ?></td> <td width="138" height="138"> <img src="images/<?php echo $row['photo'] ; ?>" width="138" height="138" /> </td> </tr> <?php endforeach; ?> </table> </p> <p><br /> <br /> </p> </form> </body> </html>
-
what are the best ways to store a critical password ?
Ch0cu3r replied to dil_bert's topic in Miscellaneous
You just contradicted yourself there. You don't want to use the Firefox password manager but you are going to use a thrid party password manager, which stores the passwords as almost the same format as Firefox. All someone needs is your master key and they have access to your passwords. It does not matter how secure your password is. If there is a vulnerability on the website/service you are using there is nothing you can do about. -
$rows contains a multidimensional array of results from your query. Each row being a separate item in the array, forexample $row[0] will contain the data for the first row, $rows[1] will contain the data for the second row and so on. If the date is the same throughout the results then you would use $rows[0]['date'] in place of $rows['date']
-
Without seeing your code it is hard to tell you why it this is. I suspect you are using the wrong variable? Or you are changing the variables value after you send the email.
-
Does not matter if you use file_exists or getimagesize the problem remains as requinix mentioned earlier Either do the file check in the else statement where $file_to_delete is defined or check whether that variable is defined first.
-
Even if you could get the source code for agario it requires node.js which is not available at 000webhost.
-
I dont thing any of those githib repos provide the source code for the agario game. They are appear to be made up of browser extensions/node.js bots etc
-
Image upload and show on index.php | PHP & MySQL
Ch0cu3r replied to Echo1's topic in PHP Coding Help
I think Barands argument is why is the physical image being (its binary contents) being stored in the database? This adds a unnecessary layer of complication. Uploaded images should be stored on the servers file system. What gets added to the database should only be the images filename (or the file path for where the image is stored on the server) added to your database. That way all you need to do to show the image is output the filename (or filepath) in the <img /> tag src attribute. Eg $result = $mysqli->query('SELECT image FROM images'); while($row = $result->fetch_assoc()) { echo '<img src="' . $row['image'] . '" />'; // output image } With your current setup because the binary contents of the image is stored in the database, you have to pass the id of the image to an external php script, set the appropriate headers for the image, then query the database to get the binary contents of the image and finally echo the binary contents. I would suggest you alter your upload script to only store the image filename/path in the database. -
No. You are getting those error message because it cannot find the file. Make sure you have type the filename or file path correctly to the file you are trying to include.
-
No output displayed even though there's no error on my code
Ch0cu3r replied to Ricardo123's topic in PHP Coding Help
Add libxml_use_internal_errors (true); Before the use of loadHTML Also you need to add the semi-colon after color:#98293D otherwise it will not find the span tag. $nodes = $xpath->query('//span[@style="font-size:25px; color:#98293D;"]'); // semi-colon added after color:#98293D -
No output displayed even though there's no error on my code
Ch0cu3r replied to Ricardo123's topic in PHP Coding Help
loadHTML expects the HTML contents, not a url to a webpage. You need to first get the contents of the webpage (using file_get_contents) and then pass that to loadHTML $HTML = file_get_contents($Url); // get the html contents of the webpage $dom->loadHTML($HTML); // pass the webpage contents to loadHTML I managed to get the values of the three span element using this path query $nodes = $xpath->query('//span[@style="font-size:25px; color:#98293D;"]'); -
It sounds like you maybe loading your .php files directly into your web browser (ie the url address starts with file://C:/User/xxx....) This is the incorrect way for testing your php code. All your web site files needs to be saved in XAMPP's htdocs folder (eg C:\XAMPP\htdocs). You then proceed to http://localhost to to test your php code.
-
You dont use PHP tags within a echo statement, You need to use the concatenation operator when outputting multiple things within your string for ($i = 1; $i <= 64; $i++) { echo ' <div class="col-xs-3 team_box top-team-border">' . $results->get_team('64', $i, 'A', 'main') . '<span class="badge">' . $results->get_score('64', $i, 'A', 'main') . '</span> </div>'; } // Or assign the team and score to variables and use them in your string for ($i = 1; $i <= 64; $i++) { $team = $results->get_team('64', $i, 'A', 'main'); $score = $results->get_score('64', $i, 'A', 'main'); echo " <div class=\"col-xs-3 team_box top-team-border\"> $team <span class=\"badge\">$score</span> </div>"; }
-
It appears you are outputting multiple json responses. This is error is most likely the response from your client as it unable to parse the json output from your script. You need to change your code so one one json response is returned, preferably at the end of your script.
-
If PHPMailer suites your needs then why change? If you are looking for alternatives have a look at SwiftMailer
-
If those values are from the url then you should be using INPUT_GET not INPUT_POST for those values in filter_input
-
What specifically are you stuck with? When you get the data from the database you loop through results and generate a checkbox, assigning each value returned by the query to each checkbox as you go When submitting multiple checkboxes, make sure you append the name of the checkbox with square brackets []. When the form is submitted the values for the selected checkboxes will be submitted as an array. To insert these values into the database you loop over the values in the array.
-
Yes anything is possible with PHP. What have you tried?
-
unable to override php's default exception Messages
Ch0cu3r replied to ajoo's topic in PHP Coding Help
It appears throws an Exception and a PHP Warning if the hostname cannot be resolved. -
You want to use the concatenation assignment operator in the for loop not echo. $message = ''; // generate html for($z=0;$z<$h;$z++) { $message .= "<tr>"; $message .= '<td colspan="18">'.$_SESSION['transferproducts'.$z.''].'</td>'; $message .= '<td colspan="2">'.$_SESSION['transferprices'.$z.''].'</td>'; $message .= "</tr>"; } // output generated html echo $message;
-
Why are you still setting individual transferproducts1, transferproducts2 etc session variables? We have already suggested you not to do this. Maybe you need to look back at Barands code example posted in your previous thread http://forums.phpfreaks.com/topic/296583-auto-incremented-sessions/?p=1512996 Can you post what is stored in the session. Show the output of var_dump It would be helpful if you could you post all error messages you are getting in full.
-
Sessions? How to secure pages for only logged in users
Ch0cu3r replied to FatesCall's topic in PHP Coding Help
Yes, you can submit the form to a different file if you like. You still only want to to check the username/password when the form has been submitted, as per my code example.