PNewCode
Members-
Posts
331 -
Joined
-
Last visited
Everything posted by PNewCode
-
Subracting a number from decimal value in mysql
PNewCode replied to PNewCode's topic in PHP Coding Help
@ginerjmAll of that is because other parts of the page require it for other functions to work. But that's not what I'm posting about. I'm asking how to make it so this can deduct a half of a number instead of a whole number. Thats why I only included this bit because that is the function I'm working with -
Hello wise and wonderful people! Today I am tackling a task to make a function to subtract a value by decimal from mysql database. I am including the part that is the functioning part of the script to show. Right now, it works perfect for whole numbers (1, 3, 9, etc). In this bit, you can see it's at 1 The problem is, when I change this to .5 then it doesn't subtract anything at all. Could this be because in my database I have the column set to int(225) - null? PS: I only included this part because everything else is just connections and images and stuff like that. So far, what you see below works perfect for whole numbers. Edit: The goal is to subtract 1/2 token (number) so if the user has 3 tokens, then this will bring it to 2.5 tokens if(isset($_POST['submit3'])){ $user_updated_token = ($user_token) - 1; }else{ $user_updated_token = ($user_token) - 1; } $sql_l = "UPDATE users SET token='$user_updated_token' WHERE id=$user_id";
-
Hey moderators question for you
PNewCode replied to PNewCode's topic in PHPFreaks.com Website Feedback
@Barand Ahhh great thank you so much -
I didn't see anywhere to send a message to ask, so I apologize for this post if it's not welcome. I wanted to ask before I made an actual post about work on a page... Is it okay to post on this site that I will hire someone to do a page for me? Like for pay? I have one page that I have spent weeks on and I'm just not advanced to understand it yet. I am working hard on learning, but I need this one done really fast and I just don't have enough time to learn how in time to get it done on time. But anyways, if it's okay to do that then please tell me where and how is the best way so I don't break any rules. Many thanks
-
OH WOW!!!! I'm giving myself the major stink-eye right now. I'm so sorry to waste everyones time. The reason it wasn't working is because I had the WRONG DATABASE AT THE BEGINNING OF THE FILE!!! Yup, it was looking for something that wasn't there. Good grief. I changed the database info and now it works (face palm to myself) Hhahahaha
-
@ginerjmcorrect. And it is
-
Oh, sorry and @ginerjm to answer your question, the × gives the "x" to close out the popup
-
Also, I tried <div class="modal-body">" '.$row['bio'].' "</div> based on @ginerjm post and that didn't make a blank page but didn't have any change either
-
@ginerjm and @Barand thank you, but I should have told more. What I posted is actually inside an echo already. I just didn't post the whole pages script. I did try it with a double quote instead just to see if that would work but it didnt, it just made the page blank
-
Hello. Today I'm working on making some text that a user enters (biography) show up as a popup when the button is clicked. I have managed to make the popup show the box with the title, and close correctly with some external JS and CSS What I'm failing at, is getting the value from the database. No errors are showing, and no errors in my error log on the hosting. What confuses me, is that when I put '.$row['bio'].' in other places on the page, then the value will appear, but not for this popup. Any thoughts? This is the part that is the popup. This is all within the php page inside an echo. If you need to see more, let me know and I will show it <div class="modal" id="modal"> <div class="modal-header"> <div class="title">Bio</div> <button data-close-button class="close-button">×</button> </div> <div class="modal-body">'.$row['bio'].'</div> </div> <div id="overlay"></div>
-
@mac_gyverthank you for taking all of that time to write out that education. I really appreciate it. I particularly liked the puzzle piece scenerio. Good way to put that in perspective. Thank you.
-
@ginerjm Here are the updates of what I tried. This form works for just uploading without the session for a basic file upload. But doesn't work for what I am trying to accomplish. This one has no errors listed but just says "page isn't working" Form <form action="Profile_updatepicture.php" method="post" enctype="multipart/form-data"> <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif"> <br> <br> Choose Pic <input type="file" name="file"> <input type="submit" name="submit" value="Upload"> </font> </div> </form> php <?php error_reporting(E_ALL); ini_set('display_errors', '1'); session_start(); include "Connection.php"; if(isset($_POST['edit'])) { $id=$_SESSION['id']; $file=$_FILES['file']; $select= "select * from users where id='$id'"; $sql = mysqli_query($conn,$select); $row = mysqli_fetch_assoc($sql); $res= $row['id']; if($res === $id) { $update = "update users set file='$file' where id='$id'"; $sql2=mysqli_query($conn,$update); // File upload path $targetDir = "images/"; $fileName = basename($_FILES["file"]["name"]); $targetFilePath = $targetDir . $fileName; $nameviewer = $_POST['nameviewer']; $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION); if(isset($_POST["submit"]) && !empty($_FILES["file"]["name"])){ // Allow certain file formats $allowTypes = array('jpg','png','jpeg','gif','pdf'); if (!file_exists($targetFilePath)) { if(in_array(strtolower($fileType), $allowTypes)){ // Upload file to server if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){ // Insert image file name into database $insert = $db->query("INSERT into users (img) VALUES ('".$fileName."'); if($insert){ $statusMsg = "The picture <b>".$fileName. "</b> has been uploaded successfully." . $backlink; }else{ $statusMsg = "File upload failed, please try again." . $backlink; } }else{ $statusMsg = "Sorry, there was an error uploading your picture." . $backlink; } }else{ $statusMsg = "Sorry, only JPG, JPEG, PNG, GIF, & PDF files are allowed to upload." . $backlink; } }else{ $statusMsg = "The file <b>".$fileName. "</b> is already exist." . $backlink; } }else{ $statusMsg = 'Please select a file to upload.' . $backlink; } // Display status message echo $statusMsg; ?>
-
@ginerjm That is because I have tried over a dozen different ones and I don't have a copy of any of them. None of them worked at all. The list of errors each time was extremely long that I thought it would be a waste of time to post and just get asked "Why did you do this and that". So I thought if someone had a method of doing this easily, then I could benefit from that in using it and my education.
-
Hello. I am having rotten luck in finding a simple update image form to use. I have a working form for users to update their name and email address, but not an image. I have been searching for a couple days on how to accomplish this however I can't seem to find anything that I can edit to be only the image and not the other information, or that works with my sessions. I'm showing below what I have that works for updating a name and email address. If someone has a way to change this to an image upload update (to change the profile image) I would be greatful. Note: The images are being stored in a folder called "images", and the file name for the image is being stored in a column called "img" in the table "users" I did not include the db connection file in this post but it is on my site and working, as well as the session for the user is working as well. I have learned A LOT since I started getting guidance and assitance on this website. I'm very greatful for that Here is the form html file <div align="center"> <p> </p> <p><img src="edit-banner.png" width="336" height="52"> <br> <br> </p> </div> <form action="Profile_update.php" method="post"> <div align="center"> <input type="text" name="fname" Placeholder="Update Name" style="font-size:20pt;" > <br> <br> <input type="email" name="email" Placeholder="Update Email Address" style="font-size:20pt;" > <br> <br> <input type="submit" name="edit" value="UPDATE" class="button button1 button4" > </div> </form> <div align="center"> <p><font face="Verdana, Arial, Helvetica, sans-serif"><b><font color="#CCCCFF">If You Want To Delete Your Account<br> </font></b></font><font face="Verdana, Arial, Helvetica, sans-serif"><b><font color="#CCCCFF">Let A Mod Know </font></b></font> </p> </div> And here is the php file <?php session_start(); include "Connection.php"; if(isset($_POST['edit'])) { $id=$_SESSION['id']; $fname=$_POST['fname']; $email=$_POST['email']; $select= "select * from users where id='$id'"; $sql = mysqli_query($conn,$select); $row = mysqli_fetch_assoc($sql); $res= $row['id']; if($res === $id) { $update = "update users set fname='$fname', email='$email' where id='$id'"; $sql2=mysqli_query($conn,$update); if($sql2) { /*Successful*/ header('location:Dashboard.php'); } else { /*sorry your profile is not update*/ header('location:Profile_edit_form.php'); } } else { /*sorry your id is not match*/ header('location:Profile_edit_form.php'); } } ?>
-
@Barand You're a genius. Thank you so much!!! And I learned quite a good exciting bit from this too. Many thanks!
-
@Barand I felt for sure you gave me the right answer, and you probably did. However I seem to have this wrong somehow. When I use the following, I echo blank spaces and gives the error Warning: Undefined array key "created_at" in /home/vbauyvmy/public_html/peredy1/modshit/phtokens4.php on line 137 which is <td><center><b><font color="green">'.$row["created_at"].'</font></b></td> This is what I have in the query $sql = "SELECT id,unique_id,fname,email,token,movie,movie2,date_format(created_at, '%b %e %Y %h:%i%p') FROM users ORDER BY fname"; (the second suggestion to put in that string gave me an undefined error on the whole page) date('M j Y g:ia', strtotime($row['created_at']))
-
@Barand Thank you. You rock!
-
Hello. Can someone help me with what I need to add to the following line of code to make it echo as Jan 6 2023 11:59pm instead of 2023-01-06 21:59:22 The column in the database is named "created_at" which is filled in when a user makes an account on my website. The issue is that I cannot change the way the date enters the database when a user signs up for an account. So I have to translate it on the page to view this for this line. Here is the line of code I have. <td><center><b><font color="green">'.$row["created_at"].'</font></b></td>
-
Php Mysql Remove from one row and add to another. I'm stuck
PNewCode replied to PNewCode's topic in PHP Coding Help
@Barand Thank you for the input and advice. The problem with that is I can't alter the database and restructure it because there are many many pages that already use this database with the structure it has, and adding new tokens when they are purchased. The only issue I'm having is making it so a person can send a token that they already have, to a different user. Everything else already works. It even works to deduct one from the person sending it and sending the transaction details to the other databases. It's the pesky part of getting the token added to the other user that has me stumped -
Php Mysql Remove from one row and add to another. I'm stuck
PNewCode replied to PNewCode's topic in PHP Coding Help
Here is the page that has the drop down and sends to the next page. This purpose is to start the session and collect the names to put in the drop down menu <html> <title> </title> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); // Start the session session_start(); $hostname_l = "removed for posting this"; $username_l = "removed for posting this"; $password_l = ")jremoved for posting this"; $dbname_l = "removed for posting this"; $conn_l = mysqli_connect($hostname_l, $username_l, $password_l, $dbname_l); if(!$conn_l){ echo "Database connection error".mysqli_connect_error(); } $user_id = $_SESSION['id']; $sql_l = "SELECT * FROM users WHERE id = '$user_id'"; $result = $conn_l->query($sql_l); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $user_token = $row["token"]; $fname = $row["fname"]; } } else { echo "0 results"; } ?> <?php $server="removed for posting this"; $userid ="removed for posting this"; $Password = "removed for posting this"; $myDB = "removed for posting this"; $con = mysqli_connect($server,$userid,$Password,$myDB); if (mysqli_connect_errno()) { # code... echo "Failed to connect to MySQL: " . mysqli_connect_error(); } ?> <header> <form action="insert.php" method="post" autocomplete="off"> <p align="center"> </p> <p align="center"><font face="Verdana, Arial, Helvetica, sans-serif" color="#CCCCFF"><b><font color="#FFFF00">Send A Playhouse User A Token<br> <i><font color="#CCCCCC">This Uses 1 Token<br> <br> </font></i></font></b></font></p> <div align="center"> <style> .button { background-color: #4CAF50; /* Green */ border: none; color: white; padding: 8px; text-align: center; text-decoration: none; display: inline-block; font-size: 25px; margin: 4px 2px; cursor: pointer; } .button {border-radius: 25%;} </style> <style> input[type="select"], option { background-color : #CCCCFF; } input::placeholder{ color: #660000; } input, select, textarea{ color: #660000; } textarea:focus, input:focus { color: #660000; } ::-webkit-input-placeholder { /* Edge */ color: #660000; } :-ms-input-placeholder { /* Internet Explorer 10-11 */ color: #660000; } ::placeholder { color: #660000; } </style> <style type="text/css"> body {background:none transparent; } </style> <style> .box1 { background-color: rgba(0,0,0,.3); color: #fff; } </style> <font face="Verdana, Arial, Helvetica, sans-serif" size="3"><font color="#FFFFFF"> <input type="hidden" name="fname" style="font-size:18pt;" value="<?php echo $fname; ?>" required /> <input type="hidden" name="tokens" style="font-size:18pt;" value="1" required /> </font></font> </div> <div id="box" align="center"> <div class="column" align="center"></div> <div class="column" align="center"> <div class="clear" align="center"></div> <font face="Verdana, Arial, Helvetica, sans-serif"><label class="first-column ">Choose A Playhouse User<br> </label></font> <div class="second-column" align="center"> <p align="center"> <select name="gname"> <option>Choose A Playhouse Member</option> <?php $sqli = "SELECT * FROM users"; $result = mysqli_query($con, $sqli); while ($row = mysqli_fetch_array($result)) { # code... echo '<option>'.$row['fname'].'</option>'; } ?> </select> </p> <p align="center"> <input type="submit" name="submit2" class="button" value="Send token" /> </p> <p align="center"><a href="main.php"><img src="cancel.png" width="190" height="55" border="0"></a></p> </div> <div class="clear" align="center"></div> <div class="clear" align="center"></div> </div> <div class="column" align="center"></div> </div> </form> </body> </html> <?php mysqli_close($con); ?> -
Php Mysql Remove from one row and add to another. I'm stuck
PNewCode replied to PNewCode's topic in PHP Coding Help
@mac_gyver Your example opened up a new thought for me. Perhaps my issue is that the page that is sending the "gname" is sending a user name, instead of the user id to add the token to? In the drop down menu on the first page (I didn't put that pages script in this thread), I name the drop down menu "gname", which is a list of the users in the database. The person gifting the token chooses the name and clicks "send" Then it goes to the page that I posted originally. So from your reply, that is making me think that my issue could be that I'm sending a name instead of an id. Thank you very much for that example. Am I close in what I'm getting from it? Oh, and the id being stored in the session is the person that is logged in, and is giving the token to someone else -
Php Mysql Remove from one row and add to another. I'm stuck
PNewCode replied to PNewCode's topic in PHP Coding Help
@phppup Thank you for all the time you spent helping me I appreciate it a lot -
Php Mysql Remove from one row and add to another. I'm stuck
PNewCode replied to PNewCode's topic in PHP Coding Help
So if I replicated the entire script that connects and replaced it with gname to retrieve from the previous page, but changed it to sql_2 then.... I think my brain just melted -
Php Mysql Remove from one row and add to another. I'm stuck
PNewCode replied to PNewCode's topic in PHP Coding Help
@phppup I just tried that edit with the script you posted to try and no errors, but nothing done at all either. I understand you're out of free time. I very much appreciate the effort you gave to help. I would also add that I went back to @mac_gyverreply to review it but I'm just simple cross-eyed trying to understand it. -
Php Mysql Remove from one row and add to another. I'm stuck
PNewCode replied to PNewCode's topic in PHP Coding Help
Haha it's okay. So should it just be the $gname = $row["fname"]; instead?