Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About baser-b

  • Rank
  1. baser-b

    Need help with an account update snippet

    $result = queryMysql("SELECT * FROM accounts WHERE user='$user'"); $row = $result->fetch_array(); $pass = $row['pass']; $fname = $row['fname']; $lname = $row['lname']; $email = $row['email']; $phone = $row['phone']; $title = $row['title']; $company = $row['company']; $website = $row['website']; $snailmail = $row['snailmail']; if (isset($_POST['save'])) { if (array_diff_assoc($_POST, $row)); { foreach (_$POST as $key => $value) { if ($key == $row[$key]) { queryMysql("UPDATE accounts SET " . $row[$key] . "='$value' WHERE user='$user'") } } } This is a different version I wrote that makes more sense. Though it returns: PHP Parse error: syntax error, unexpected '$POST' (T_VARIABLE)
  2. baser-b

    Need help with an account update snippet

    The code is supposed to check when a form is submitted that has the fields First Name, Last Name, Email, Phone, Title, Company, Website, Address, which fields have been changed, and update the fields in the database.
  3. baser-b

    Need help with an account update snippet

    Okay, so this is the code I came up with mac_gyvers suggestions. It should be remembered (though how could you forget?) that I am a moron and also very new to PHP but am trying my best to learn. if (isset($_POST['save'])) { foreach ($_POST as $key => $value) { foreach ($row as $rkey => $rvalue) { if (array_search($key, $rkey)) { if($rkey == "email") { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error = "Invalid email format."; } } if ($rkey == "website") { if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) { $error = "Invalid URL."; } } if ($rvalue != $value) { queryMysql("UPDATE accounts SET $rkey='$value' WHERE user='$user'"); $info = "$rkey updated."; } } } } }
  4. baser-b

    Need help with an account update snippet

    So I tried to do the thing of running through the values in the $_POST and comparing them to etc etc. Anyway, this is what I came up with, which doesn't work. if (isset($_POST['save'])) { foreach ($_POST as $key => $value) { foreach ($row as $rkey => $rvalue) { if (array_search($key, $rkey)) { if($rkey == "email") { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error = "Invalid email format."; } } if ($rkey == "website") { if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) { $error = "Invalid URL."; } } if ($rvalue != $value) { queryMysql("UPDATE accounts SET $rkey='$value' WHERE user='$user'"); $info = "$rkey updated."; } else { queryMysql("INSERT INTO accounts ($rkey) VALUE('$value') WHERE user='#user'"); $info = "$rkey updated."; } } } }
  5. Thanks for the edit, that wasn't my password though. Anyway, as an edit to my previous post: I am basically creating a part of a homepage script that will give me a vocabulary "word of the day" + definition as part of the overall setup. The point of the function I am trying to create is to serve 4 purposes: Read a random line from a text file containing a word and definition. Separate the two values. Print the two values as Word: $word and Definition: $definition. Store the values into an MySQL database that can be retrieved at another time. Delete the values from the text file without leaving a blank line I like learning new words and usually will put it in a textfile when I see it and get the definition later. Part of the purpose of the function is to specifically give me a word to meditate on each day and maybe also add a "memory game" or something on the page to help learn the word/definition rather than just accumulating words in a textfile.
  6. Well, I'm not necessarily trying to read ALL the entries from a file. My knowledge is limited. I know that file() turns a file into an array, but then I didn't know how to read a single line from the array produced, and now having thought it through, I figured that out, but it was a former experiment that had confused me when the $output[0] just returned a letter or something. But anyway this code does the same thing without getting the set of values I want from the array.... $file = "vocab.txt"; $source = file($file); $entry = explode("-", $source[0]); $word = $entry[0]; $definition = $entry[1];
  7. Well one about the why have a class for a single function, I am going to build upon the class that's just the one part I have a question about. A lot of the things in my code that don't make sense is because I am new at PHP and programming in general, and have not had more of an education than w3schools.com and reading other people's code and referencing it with php.net/manual/. I do have database functions defined but they are not directly relevant to the problem at hand, so I didn't include it. It is here: // Define MySQL variables define("SERVER", "localhost"); define("USERNAME", "admin"); define("PASSWORD", "??????"); define("DATABASE", "homepage"); // Connect to MySQL Database $connection = new mysqli(SERVER, USERNAME, PASSWORD, DATABASE); if ($connection->connect_error) { die($connection->connect_error); } function queryMysql($query) { global $connection; $result = $connection->query($query); if (!$result) die($connection->error); return $result; }
  8. So I am trying to write a script that reads a text file that contains words/definitions, prints the word/definition separately, sends those values to an MySQL database, then deletes those same values from the text file without leaving an empty line. I am having some trouble with getting it ALL to go down. I can get it to read/print the info I want, send it to the database, but deleting the values from the file isn't working. It just deletes the entire contents from the file. Here's the code: class Vocabulary { public $date; public $word; public $definition; private $file; private $list; private $output; function new() { $date = date("m/d/y"); $file = "vocab.txt"; $list = file($file); foreach ($list as $line) { $output = explode("-", $line, 2); $word = $output[0]; $definition = $output[1]; } queryMysql("INSERT INTO Vocabulary (word, definition, date) VALUES('$word', '$definition', '$date')"); echo "<br><strong>Word:</strong> " . $word; echo "<br><strong>Definition:</strong> " . $definition; $rewrite = fopen($file, "w+"); $delete = $output[0] . $output[1]; fwrite($rewrite, str_replace($delete, "", $list)); fclose($file); } } $vocab = new Vocabulary; echo $vocab->new(); I'm trying to figure out how I can send the values returned from the first "foreach", which would be the only result desired to be returned from the function, into a variable and "set" them. Because from what I believe is happening, its replacing the entire file with "" because its replacing $output[0] . $output[1] each time until there's no values left. So if I could set the values obtained from the first run of foreach loop then I could specifically delete those values from the file rather than $output[]. I dunno. I'm just beginning with PHP. Thanks.
  9. I really swear that the host I use is like screwing with me hard. Like literally will have something working one night, wake up the next day to my error log full and nothing working anymore. Or, like in this case, have the code working fine, perfectly in fact, to all of the sudden bring up all these errors and shit without changing anything I just can't figure it out. Point being, I am working on this portal, and on the account page, you can update your info. Which for one field... $result = queryMysql("SELECT * FROM accounts WHERE user='$user'"); $row = $result->fetch_assoc(); $set_comp = $row['company']; // Check if 'Company' value is set if (isset($_POST['company'])) { $company = sanitizeString($_POST['company']); if ($_POST['company'] != $set_comp) { queryMysql("UPDATE accounts SET company='$company' WHERE user='$user'"); } elseif ($set_company == "") { queryMysql("INSERT INTO accounts (company) VALUES('$company') WHERE user='$user'"); } elseif (empty($_POST['company'])) { $company = ""; } else { $company = stripslashes($row['company']); } } And the form... Now before it inexplicably stopped working, what it was doing and meant to do was display a form, that either had the information that was set, or displayed nothing because nothing was entered, and you could either put something there or change what was already there. Now it keeps telling me: [22-Oct-2018 06:29:37 UTC] PHP Notice: Undefined variable: company in /home/iqy0804tq6fq/public_html/portal/account.php on line 262 Also, sanitizeString and queryMysql are my own created functions, they work fine. I tried removing the elseif (empty($_POST['company'])), and just left the last else in, didn't work. It just displays empty columns now. Now also, when I try to update, it feeds me all these errors now my SQL syntax is wrong its LIKE HOW DID THIS CHANGE IN 10 SECONDS!!? I didn't DO anything for my syntax to be any different than when it worked perfectly! It's insanity.
  10. baser-b

    Need a quick fix on a box model please

    Thanks Requinix
  11. baser-b

    Need a quick fix on a box model please

    Basically I want the text to be spaced like this: User: $user Project ID: 0003 [BUTTON] [BUTTON]
  12. baser-b

    Need a quick fix on a box model please

    <style> .whatever { position: relative; display: flex; float: left; background-color: #336699; color: white; padding: 10px; font-family: Candara, Sans-Serif; /* width: 400px; */ } .whateverer { position: absolute; left: 0; bottom: 0; margin: 10px; } .buttonbox { display: flex; float: right; background-color: #FFFFFF; padding: 5px; align: right; } </style> <br><br> <div class='whatever'><b>User:</b> $user :: <b>Project ID: </b>00021<div class='whateverer'><small><b>Last Login:</b> @ 4:32 / 12 June 2018</small></div> <div class='buttonbox'><a href='account.php'><small><button>Settings</button></a> <a href='logout.php'><button>Logout</button></a></small></div></div> This is almost exactly what I want EXCEPT User: $user | Project ID: 0002 and the Buttons are shmooshed together. To make it easier to see what I'm talking about here's a link: http://hosted.olivermoore.co/testing.html
  13. <html> <style> .box { color: #d0d0d0; font-weight: 300; padding: 30px 0; background: #336699; } .whatever { float: left; background-color: #336699; color: white; padding: 10px; font-family: Candara, Sans-Serif; width: 400px; } .buttonbox { float: right; background-color: #FFFFFF; padding: 4px; align: right; width: 131px; } </style> <div class='box'>Here's some shit for whatever.</div><br><br><br> <div class='whatever'><b>User:</b> $user | <b>Project ID: </b>00021<br><small><b>Last Login:</b> @ 4:32 / 12 June 2018</small> <div class='buttonbox'><a href='account.php'><small> <button>Settings</button></a> <a href='logout.php'><button>Logout</button></a></small></div></div> </html> Basically all I want is the "buttonbox" to be in the center next to the 'User: and Project ID: with Last Login underneath' text with any extra trimmed to be evenly padded and look nice. I am having trouble figuring it out.
  14. echo >>>HEREDOC <table name='AccountInfo'><form method='post' action='<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>' enctype='multipart/form-data'> <tr><th><span class='fieldname'>Username:</span></th><td><?php echo $user; ?></td></tr> <tr><th><span class='fieldname'>Password:</span></th><td><input type='password' size='16' name='pass' value='<?php echo $pass; ?>'></td></tr> <tr><th><span class='fieldname'>First Name:</span></th><td><input type='name' size='16' maxlength='16' name='fname' value='<?php echo $fname; ?>'></td></tr> <tr><th><span class='fieldname'>Last Name:</span></th><td><input type='name' size='16' maxlength='16' name='lname' value='<?php echo $lname; ?>'></td></tr> <tr><th><span class='fieldname'>Email:</span></th><td><input type='email' maxlength='20' name='email' value='<?php echo $email; ?>'></td></tr> <tr><th><span class='fieldname'>Phone:</span></th><td><input type='tel' maxlength='10' name='phone' value='<?php echo $phone; ?>'></td></tr> <tr><th><span class='fieldname'>Title:</span></th><td><input type='title' maxlength='16' name='title' value='<?php echo $utitle; ?>'></td></tr> <tr><th><span class='fieldname'>Company:</span></th><td><input type='text' maxlength='20' name='company' value='<?php echo $company; ?>'></td></tr> <tr><th><span class='fieldname'>Website:</span></th><td><input type='url' maxlength='20' name='website' value='<?php echo $website; ?>'></td></tr> <tr><th><span class='fieldname'>Mailing Address:</span></th><td><input type='address' maxlength='30' name='snailmail' value='<?php echo $snailmail; ?>'></td></tr></table> <tr><td><input type='submit' value='Save Info'></td></tr></form></div><br> <h3>Upload/Edit Account Photo</h3> <table name='UploadPhoto'><form method='post' action='<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>' enctype='multipart/form-data'> <tr><th>Select a Photo:</th><td><input type='file' name='image'></td><td><input type='submit' value='Save Photo'></td></tr></form></div><br></center> HEREDOC; I keep getting this error: [16-Oct-2018 12:05:16 UTC] PHP Parse error: syntax error, unexpected '>>' (T_SR) in /home/iqy0804tq6fq/public_html/portal/account.php on line 247 There is no whitespace, I can't figure out why '>>' all of a sudden causes an error.
  15. baser-b

    When to use { }

    Well I keep getting an error with this code, saying the 'else' is wrong. function showCollaborators($user) { $entry = queryMysql("SELECT collaborator FROM users WHERE user='$user'"); echo "Collaborator(s): "; if ($entry->num_rows > 0) { while ($row = $entry->fetch_assoc() && $entry->num_rows > 1) { $row['name'] = $view; echo "<a href='users.php?view=$view'>" . $view . "</a>, "; } else { echo "<a href='users.php?view=$view'>" . $view . "</a>."; } } }

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.