• Content count

  • Joined

  • Last visited

  • Days Won


Gabrielphp last won the day on April 28

Gabrielphp had the most liked content!

Community Reputation

1 Neutral

About Gabrielphp

  • Rank

Previous Fields

  • Languages
    PHP, Javascript, jQuery, HTML, CSS, MySQL

Profile Information

  • Gender
  • Interests
    Web development
  1. I need to know what column do you have in your DB where the value is 1 and where you set the $_SESSION['id'] variable after login, after that i can help you further.
  2. I am not sure, this code won't run as normal php, it might be using some kinda of a framework that uses those operators, but as i said i'm not sure. It's also the possible way that this code was put into some kinda of a software maybe to highlight the syntaxes or something. As @Ingolme said.
  3. Have you tried it? It works just like that, it counts the rows.
  4. Lemme edit it a bit. try { $sql = "SELECT * FROM database WHERE email = :email"; $stmt = $conn->prepare($sql); $stmt->bindParam(":email", $email); $stmt->execute(); $numRows = $stmt->rowCount(); if($numRows > 0) { while($row = $stmt->fetch()) { $id = $row['id']; $name = $row['name']; $age = $row['age']; } } } catch (PDOException $e) { echo "Error: " . $e->getMessage(); } I have corrected a bit of mistyped methods that you used there. This should be secure enough.
  5. First stop using this query as it is not protected. Use prepared statements in order to protect your data from possible attacks. CODE: try { $sql = "UPDATE `user` SET merged = `no` WHERE email IN (:emailuser, :togethelp)"; $unsetmerge = $flash->prepare($sql); $unsetmerge->bindParam(":emailuser", $emailuser); $unsetmerge->bindParam(":togethelp", $togethelp); $unsetmerge->execute(); } catch (PDOException $e) { echo "Error: " . $e->getMessage(); } Using the catch function you can catch the error is being throw by the sql if there is any. This should do your job.
  6. Glad i could help.
  7. Why use success and error ajax functions when you can use .done and .fail? .done and then you do all the checks in the php script even the return so that way you don't need to do that much of a javascript code in order to display an message. For example my way i use to display messages with jquery is very simple. For example index.php <div id="return_php" style="display: none;"></div> <form id="test"> <input type="text" name="something" placeholder="Insert something ..."> <input type="submit"> </form> <script> $('#test').submit(function(e){ e.preventDefault(); $.ajax({ url: 'path/to/something.php', data: $(this).serialize(), dataType: 'html', type: 'POST' }) .done(function(data){ $('#return_php').fadeIn(400).html(data).delay(5000).fadeOut(400); }) .fail(function(){ $('#return_php').fadeIn(400).html('Something went wrong with the ajax script !').delay(5000).fadeOut(400); }) }); </script> This way you just call the php page in which you do the checks and whatever stuff and then you echo an alert which will then be displayed into the return_php div. The .delay(5000) acts as a delay for the fadeOut function, after 5 seconds the message will fade away. something.php $something = $_POST['something']; if(empty($something)) { echo "Something needs to be filled in !"; //This message will be then returned into the div return_php on the index.php page } else { //Example of database try { $sql = "SELECT something FROM something WHERE something = :something"; $stmt = $db->prepare($sql); //$db is from a config file you have to include $stmt->bindParam(":something", $something); $stmt->execute(); $rowCount = $stmt->rowCount(); //This works for every case, at least i use it this way and for me works just fine. if($rowCount > 0) //let us presume that the something has more rows { echo "Ok, there is something in that something !"; } else { echo "There is nothing in something with the something you typed !"; } } catch (PDOException $e) { echo "Error: " . $e->getMesage(); //This will be showed into the return div aswell as the echo is still a part of this page, and this page is called by ajax. } } Now, this is my way to do it time to time when i need live php script calling on my page without needing my page to refresh. Hope it helped at least for your issue with displaying messages. EDIT I've read again through your post and i think i figured out what is all about. When i try to use that ereg_replace() php function is always throwing me an Uncaught error as the function doesn't exist. This may be influencing how you are selecting the data by that variable. Instead of ereg_replace use preg_replace, It does the same thing. $email = $_POST['email']; $email = preg_replace('/\s+/, '', $email); NOTE! Some of the code i wrote may or may not fit your code if you copy paste it as it doesn't contain the same variables or functions that you wrote. You may need to adapt it to your use.
  8. First question, something like this should work: I made this with my own paths so you can understand what is the difference between $dir and $path_images. If you don't use the if condition then your scandir will show other files that will corrupt the img tag. $dir = '/xampp/htdocs/test/uploads'; $path_images = 'uploads/'; $files = scandir($dir); foreach($files as $key) { if(!preg_match('/.jpg|.jpeg/', $key)) continue; echo '<img src="' . $path_images . $key . '">'; } Second question As @Ingolme said you can use n2lbar() for that. Let's take this script as an example: //First we need to access data try { $sql = "SELECT user_comment FROM comments"; $stmt = $db->prepare($sql); $stmt->execute(); } catch (PDOException $e) { echo "Error: " . $e->getMessage(); } //Now fetch it and display it while ($row = $stmt->fetch()) { echo nl2br($row['user_comment']); //This will display row breaks } Third question I don't know to properly resize a picture with php, i think it's not that easy to do that, but, you can just add a if condition so that the user can upload only jpeg file about 200kb, this way will cut a lot of your work to code. And what do you mean by a specific directory? You want like an user to have it's own directory? Fourth question The user @Ingolme explained it pretty well with str_replace(); .