-
Posts
15,266 -
Joined
-
Last visited
-
Days Won
431
Everything posted by requinix
-
Manipulating (cutting) Array Data and Output Size
requinix replied to vbcoach's topic in PHP Coding Help
Remember that code I posted yesterday? Have you tried to do anything with it? If you're still wondering where to put it then you should think about what the code is doing and where it would make sense for it to go. -
Without any error checking, $h = fopen("file.txt", "rt"); while (!feof($h)) { $title = trim(fgets($h)); $url = trim(fgets($h)); // output } fclose($h);
-
Try dumping the $_SESSION in the Admin page where it fails the login check. Apparently something is different between the two page loads and what's in (or not) the session may explain that. If your session data isn't too complex then you can error_log(json_encode($_SESSION));Or to the screen, but then the header redirect won't work (which would be fine for this).
-
Is it possible that the login code is executing after those checks?
-
Warning: Creating default object from empty value in /home3/aundie/public_html/dandewebwonders.com/BBProject 4/Controllers/Controller.php on line 41 {"data":[{"Id":"1","FirstName":"Chico","LastName":"Escuela","HomeTown":"San Juan, PR","Bats":"L","Throws":"R","Team":null},{"Id":"2","FirstName":"Christopher","LastName":"Henry","HomeTown":"Pittsburgh, PA","Bats":"","Throws":"","Team":null},{"Id":"3","FirstName":"Travis","LastName":"Hubbard","HomeTown":"Boise, ID","Bats":"","Throws":"","Team":null},{"Id":"4","FirstName":"Richard","LastName":"McCoy","HomeTown":"Austin, TX","Bats":"","Throws":"","Team":null},{"Id":"5","FirstName":"Al","LastName":"Torres","HomeTown":"Baltimore, MD","Bats":"","Throws":"","Team":null},{"Id":"6","FirstName":"Everett","LastName":"Greer","HomeTown":"Wilmington, DE","Bats":"","Throws":"","Team":null},{"Id":"7","FirstName":"Johnnie","LastName":"Joseph","HomeTown":"St. Paul, MN","Bats":"","Throws":"","Team":null},{"Id":"8","FirstName":"Milton","LastName":"Osborne","HomeTown":"Davidson, TN","Bats":"","Throws":"","Team":null},{"Id":"9","FirstName":"Dewey","LastName":"McDonald","HomeTown":"St. Louis, MO","Bats":"","Throws":"","Team":null},{"Id":"10","FirstName":"Ervin","LastName":"Lawrence","HomeTown":"Anaheim, CA","Bats":"","Throws":"","Team":null},{"Id":"11","FirstName":"Thomas","LastName":"Copeland","HomeTown":"St. Petersburg, FL","Bats":"","Throws":"","Team":null},{"Id":"12","FirstName":"Christian","LastName":"Shelton","HomeTown":"Akron, OH","Bats":"","Throws":"","Team":null},{"Id":"13","FirstName":"Jackie","LastName":"Harris","HomeTown":"Rochester, NY","Bats":"","Throws":"","Team":null},{"Id":"14","FirstName":"Bob","LastName":"Barnes","HomeTown":"Newark, NJ","Bats":"","Throws":"","Team":null},{"Id":"15","FirstName":"Woodrow","LastName":"Zimmerman","HomeTown":"Baltimore, MD","Bats":"","Throws":"","Team":null},{"Id":"16","FirstName":"Willard","LastName":"Harrington","HomeTown":"Glendale, AZ","Bats":"","Throws":"","Team":null},{"Id":"17","FirstName":"Orville","LastName":"Gregory","HomeTown":"Reno, NV","Bats":"","Throws":"","Team":null},{"Id":"18","FirstName":"Tony","LastName":"Jennings","HomeTown":"Denver, CO","Bats":"","Throws":"","Team":null},{"Id":"19","FirstName":"Benjamin","LastName":"Hawkins","HomeTown":"Philadelphia, PA","Bats":"","Throws":"","Team":null},{"Id":"20","FirstName":"Andre","LastName":"Wells","HomeTown":"Kansas City, MO","Bats":"","Throws":"","Team":null},{"Id":"21","FirstName":"Rafael","LastName":"McDaniel","HomeTown":"Norfolk, VA","Bats":"","Throws":"","Team":null}]}
-
Manipulating (cutting) Array Data and Output Size
requinix replied to vbcoach's topic in PHP Coding Help
You don't really need to worry about dealing with arrays here. Both of the things you want to do only manipulate strings - it's just that the strings you want are inside of an array. 1. The first character of a $string is easy to get using $string[0]. Works just like an array. And yes, it also works with things besides a simple variable. $firstnameinitial = $lrow['firstname'][0];2. strlen() tells you the length of a string. Use an if to set a new variable with the displayable name of the team according to your rule. Then substr() to get a substring. if (strlen($lrow['rteamname']) > 25) { $teamname = substr($lrow['rteamname'], 0, 25) . "..."; } else { $teamname = $lrow['rteamname']; }Now use those two new variables in your echo. -
Huh. How did I miss that? I even scrolled down to see the rest of the if block... Okay. There's two things that need to change: supporting empty uploads, of course, but there's a larger problem of SQL injection where apostrophes in any of the fields (for example) will cause your INSERT to fail. At best; a malicious user could instead do damage to your database. Fixing that problem will also change how you deal with the empty uploads so you should do that first. The solution is with prepared statements. Instead of $sql = "INSERT INTO events VALUES(id, '{$title}', '{$date}', '{$time}', '{$desc}', '{$presenter}', '{$file_name}', '{$file_size}', '{$file_type}')"; mysqli_query($con, $sql) or die (mysqli_error($con)); echo "Success";you do $sql = "INSERT INTO events VALUES(id, ?, ?, ?, ?, ?, ?, ?, ?)"; $stmt = mysqli_prepare($con, $sql); mysqli_stmt_bind_param($stmt, "ssssssss", $title, $date, $time, $desc, $presenter, $file_name, $file_size, $file_type); // probably should be more like // $stmt->bind_param("ssssssis", $title, $date, $time, $desc, $presenter, $file_name, $file_size, $file_type); // because $file_size and whatever the column in the events table is are both numbers and not strings mysqli_stmt_execute($stmt);With that changed, all you have to do for an empty upload is set $file_name, $file_size, and $file_type to null. (And make sure the table supports NULL in those three columns.) So modify the upload logic to look something like switch (error status) { case successful: do the rest of the upload handling, including error checking; break; case no file uploaded: set those three variables to null; break; other cases:... }(which references the switch I posted earlier)
-
Split from Parse Error. Are you saying you have the exact same problem as the other poster?
-
1. The first piece of code doesn't have any SQL stuff in it. It doesn't make sense to me that the second piece should go with it. Surely there's more code somewhere else that also does an INSERT? You should be modifying that so it can support an empty image, rather than making a whole new INSERT just for that one case. 2. The first piece of code doesn't support an empty image. I think it will complain about an invalid extension. You need to use the upload "error" status (a) period, because you can't just assume that the upload was successful, and (b) to tell if no file was uploaded. $file_error = $_FILES['image']['error']; switch($file_error) { case UPLOAD_ERR_OK: // okay break; case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: // file is too large break; case UPLOAD_ERR_PARTIAL: // file upload did not complete break; case UPLOAD_ERR_NO_FILE: // no file was uploaded break; case UPLOAD_ERR_NO_TMP_DIR: case UPLOAD_ERR_CANT_WRITE: case UPLOAD_ERR_EXTENSION: default: // system error preventing the file from being uploaded break; }
-
If the web server still supports PHP then yes, you can probably make a simple email script that takes data like the send_mail.php did. How much PHP do you know?
-
Oh, so you're trying to prevent more duplicates.
-
Right... and you should always have the link. If not then you don't know what is a duplicate of what. So, what do you mean if it "does not exist"?
-
It seemed like a one-time thing; if not then there are larger problems that need to be addressed. If Link is NULL then the GROUP BY won't work. That's what you were using to de-duplicate. So what do you mean if it "does not exist"?
-
Can't delete from a table and pull data from it at the same time. Quick solution: use a temporary table. CREATE TEMPORARY TABLE fooTableName LIKE TableName; INSERT INTO fooTableName SELECT * FROM TableName; DELETE FROM TableName WHERE ID NOT IN (SELECT MAX(ID) FROM fooTableName GROUP BY Link HAVING MAX(ID) IS NOT NULL); DROP TEMPORARY TABLE fooTableName;Not quite as nice if TableName has a lot of rows. Definitely not as nice if bad data is still being added into TableName (and if so then you need to fix that before doing this). Side comment: HAVING MAX(ID) IS NOT NULL only matters if your ID can be null. Surely something called "ID" cannot be null, right?
-
Twilio is the most popular service and can do exactly what you want.
-
Which web browser is best for mobile phones?
requinix replied to krishnanayak's topic in Miscellaneous
What kind of answer are you actually expecting to get? Are you going to install one on your phone and you don't know which to use? Are you trying to design a mobile website and you want to know what most people are using on their device? Or are you just throwing out questions that sound relevant but are actually meaningless in order to increase your post count? -
First there's a problem: 'title' => 'FABLife', 'desc' => 'Mark Cuban (``Shark Tank\'\'); top five must-haves; collectors try to guess the prices of celebrity memorabilia; creating a high-end playroom and eliminating toy clutter without breaking the bank.', 'title' => 'The First 48', 'desc' => 'A young man is robbed and killed while meeting up with a girl he met earlier; a man is gunned down outside an annual football game.', 'title' => 'Teen Titans Go!', 'desc' => 'Robin makes the other Titans sell their treasured mementos from past adventures.',Can't do that. There can only be one "title" and "desc" in the array. You need to come up with a different way of representing everything. I suggest 'info' => array( array( 'title' => 'FABLife', 'desc' => 'Mark Cuban (``Shark Tank\'\'); top five must-haves; collectors try to guess the prices of celebrity memorabilia; creating a high-end playroom and eliminating toy clutter without breaking the bank.' ), array( 'title' => 'The First 48', 'desc' => 'A young man is robbed and killed while meeting up with a girl he met earlier; a man is gunned down outside an annual football game.' ), array( 'title' => 'Teen Titans Go!', 'desc' => 'Robin makes the other Titans sell their treasured mementos from past adventures.' ) )
-
That's a PHP thing, not a Javascript thing. Make sure you have the most recent version of elFinder - they may have fixed this already. Otherwise I suggest fixing the problem in the actual code. You'd have to post what's in elFinder.php around lines 300-350.
-
Inside the foreach loop you have to use $entry. $xml->entry-> will only get you stuff from the first .
-
Uh, no. You'd use a form. As in <form action="page.php" method="post"> <input type="hidden" name="id or whatever" value="1"> <button type="submit">Delete</button> </form>
-
What is the name of the actual file containing the code? And did the .htaccess thing work for you or not?
-
... 1. salesperson_delete.php has nothing to do with admin_subfile_delete.php. Just because "id" in one file means a salesperson doesn't mean "id" anywhere must only be a salesperson. 2. You know you can put whatever you want in the query string, right? You could call the sales ID "sales_id" or "sid" or "potato", it doesn't matter.
-
restrict a few pages with disclaimer agreement
requinix replied to debsdesign's topic in PHP Coding Help
Most people don't want to download attachments and fire up a PHP editor to read someone's code online. In the future, help us all out by posting the code right in the post itself. (I've done it for you this time.) // if not set, send back to agreement echo ' <a href="https://www.macreon.com.au/WholesaleAgree.php"></a>';All you're doing here is outputting a link to the agreement page. You have to actually force the user to go back to it, and you do that with code like // if not set, send back to agreement header('Location: WholesaleAgree.php', true, 307); exit;This tells the browser to redirect, the 307 means it's only a temporary redirect, and the exit prevents the rest of the code from executing. Keep in mind that code that uses header() like this must happen before there is any output whatsoever. [edit] Oh. You're also missing a check for the acceptance flag in the session. All you look at now is the form - gotta check both of them.