Jump to content

Html

Members
  • Content Count

    611
  • Joined

  • Last visited

Community Reputation

7 Neutral

About Html

  • Rank
    Invested Member
  • Birthday 03/17/1989

Profile Information

  • Gender
    Male
  • Location
    Greater London

Recent Profile Visitors

15,821 profile views
  1. Html

    Upload image code example

    So image needs to be changed a little?
  2. Html

    Upload image code example

    Hmm, the reason I began searching these examples is because I couldn't go further with just learning the language. I do have the SQL in easy steps book, but I don't it covers quite what I am doing. It is all to do with just editing in the actual sql db, not using it in php for web pages. That code alone has vulnerability? Where about is it, and it is easy to patch up?
  3. Html

    Upload image code example

    I'm going to need an example. 😕
  4. Html

    Upload image code example

    $sql = "SELECT FROM images WHERE user_id users.userid=$user_id AND images.userid =$user_id "; I think this is correct on the names.
  5. Html

    Upload image code example

    I remove the auto increment setting for images table. So, this sql statement will fit into this code. This below is wrong, $sql = "SELECT FROM images WHERE user_id images.userid=$user_id AND imagetablename.userid =$user_id "; <?php while ($row = msql_fetch_array($result, MSQL_ASSOC)) echo "<div id='img_div'>"; echo ".$row['user_id']."'"; echo "<img src='images/".$row['image']."' >";  echo "<p>".$row['image_text']."'</p>";  echo "</div>"; } ?> 
  6. Html

    Upload image code example

    CREATE TABLE IF NOT EXISTS images ( user_id INT UNSIGNED NOT NULL AUTO_INCREMENT, image VARCHAR(100) NOT NULL, image_text text NOT NULL, reg_date DATETIME NOT NULL, PRIMARY KEY (user_id) ); I decided to create the table this way, so user_id is consistent. The other way I couldn't really get it edited, and working. So may be this is a little better. As for values, what exactly, this is the image table, and the user table is obviously different, in values, so I don't quite understand what you mean by adding the same values, only user_id is currently the same in both tables now. As well reg_date, not that important, I guess?
  7. Html

    Upload image code example

    Instead of id, user_id? Keep both. echo ".$row['user_id']."'"; This alone will link them? it will connect with it. I am going to need to type some code for this? , 'you retrieve user table and image table together where user_id equals userid or user_id? from the image table '
  8. Html

    Upload image code example

    Well, are you getting at they must be linked somehow, here is an image, I'm not giving enough info on what I have. All I did was do what the page has stated.
  9. Html

    Upload image code example

    <?php while ($row = msql_fetch_array($result, MSQL_ASSOC)) echo "<div id='img_div'>"; echo ".$row['user_id']."'"; echo "<img src='images/".$row['image']."' >";  echo "<p>".$row['image_text']."'</p>";  echo "</div>"; } ?>  There is only id for the images table, so user_id won't work like I have placed it above? Since user_id is on the users table.
  10. Html

    Upload image code example

    <?php while ($row = msql_fetch_array($result, MSQL_ASSOC)) echo "<div id='img_div'>"; echo "<img src='images/".$row['image']."' >";  echo "<p>".$row['image_text']."'</p>";  echo "</div>"; } ?>  Keep it like this, I thought the example was necessary for an id add in.
  11. I tried this code or another, but it didn't work. The user site I use, it uses Sha2. I tried removing it, it only breaks the system, so how to use it with this, I am not sure about that. Change pass is something I am not that concerned about, especially if the code is rubbish as you've pointed out. Remove data was important, i got some code help elsewhere for that. Now that image id task.
  12. Html

    Upload image code example

    So add image and image_text to the users table? Hmm, as for the id, how does that work out with the code above? <?php while ($_Session, $row = mysqli_fetch_array($result)) { echo "<div id='img_div'>"; echo "<img src='images/".$row['image']."' >"; echo "<p>".$row['image_text']."</p>"; echo "</div>"; } ?> while ($row = msql_fetch_array($result, MSQL_ASSOC)) { echo $row['id'] . ': ' . $row['name'] . "\n"; Is this above required for the code from the image code? <?php while ($row = msql_fetch_array($result, MSQL_ASSOC)) { echo $row['id'] . ': ' . $row['image'] : ' . $row['image_text'] . "\n"; echo "<div id='img_div'>"; echo "<img src='images/".$row['image']."' >"; echo "<p>".$row['image_text']."</p>"; echo "</div>"; } ?>
  13. Html

    Upload image code example

    Yes, not sure where, I tried the obvious above for the display of the image, but that won't work in the php code checker. Currently it just uploads an image, stores in the db, and displays on the same page as the code displays. So for it to be a particular user, session id is required especially for the display code. I did try it, but it didn't work, that is without the $_session. <?php while ($_Session, $row = mysqli_fetch_array($result)) { echo "<div id='img_div'>"; echo "<img src='images/".$row['image']."' >"; echo "<p>".$row['image_text']."</p>"; echo "</div>"; } ?> $result = mysqli_query($dbc, "SELECT * FROM images"); This below is where the display begins. https://www.php.net/manual/en/function.msql-fetch-array.php while ($row = msql_fetch_array($result, MSQL_ASSOC)) { echo $row['id'] . ': ' . $row['name'] . "\n";
  14. <?php # Access session. session_start() ; # Redirect if not logged in. if ( !isset( $_SESSION[ 'user_id' ] ) ) { require ( 'login_tools.php' ) ; load() ; } // Create database connection $dbc = mysqli_connect("", "", "", ""); // Initialize message variable $msg = ""; // If upload button is clicked ... if (isset($_POST['upload'])) { // Get image name $image = $_FILES['image']['name']; // Get text $image_text = mysqli_real_escape_string($db, $_POST['image_text']); // image file directory $target = "images/".basename($image); $sql = "INSERT INTO images (image, image_text) VALUES ('$image', '$image_text')"; // execute query mysqli_query($dbc, $sql); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { $msg = "Image uploaded successfully"; }else{ $msg = "Failed to upload image"; } } $result = mysqli_query($dbc, "SELECT * FROM images"); ?> <!DOCTYPE html> <html> <head> <title>Image Upload</title> <style type="text/css"> #content{ width: 50%; margin: 20px auto; border: 1px solid #cbcbcb; } form{ width: 50%; margin: 20px auto; } form div{ margin-top: 5px; } #img_div{ width: 80%; padding: 5px; margin: 15px auto; border: 1px solid #cbcbcb; } #img_div:after{ content: ""; display: block; clear: both; } img{ float: left; margin: 5px; width: 300px; height: 140px; } </style> </head> <body> <div id="content"> <?php while ($row = mysqli_fetch_array($result)) { echo "<div id='img_div'>"; echo "<img src='images/".$row['image']."' >"; echo "<p>".$row['image_text']."</p>"; echo "</div>"; } ?> <form method="POST" action="upload.php" enctype="multipart/form-data"> <input type="hidden" name="size" value="1000000"> <div> <input type="file" name="image"> </div> <div> <button type="submit" name="upload">POST</button> </div> </form> </div> </body> </html> I got this upload an image code from here, I have tinkered it so it works, I just need to get it be personal for a user, and display the uploaded image at a particular page. https://codewithawa.com/posts/image-upload-using-php-and-mysql-database <?php while ($_Session, $row = mysqli_fetch_array($result)) { echo "<div id='img_div'>"; echo "<img src='images/".$row['image']."' >"; echo "<p>".$row['image_text']."</p>"; echo "</div>"; } ?> $_SESSION[ 'user_id' ] This particular code I want to display on the home.php page. I need to tuck in a $_session Thanks.
  15. Hey there, So I checked out this code, is this okay to use? Obviously, the php code, I am looking at here. For the db, a new column, I guess in users table, would be needed a password and as varchar 20. `password` varchar(55) NOT NULL, <?php session_start(); $_SESSION["userId"] = "1"; $conn = mysqli_connect("localhost", "root", "test", "blog_samples") or die("Connection Error: " . mysqli_error($conn)); if (count($_POST) > 0) { $result = mysqli_query($conn, "SELECT *from users WHERE userId='" . $_SESSION["userId"] . "'"); $row = mysqli_fetch_array($result); if ($_POST["currentPassword"] == $row["password"]) { mysqli_query($conn, "UPDATE users set password='" . $_POST["newPassword"] . "' WHERE userId='" . $_SESSION["userId"] . "'"); $message = "Password Changed"; } else $message = "Current Password is not correct"; } ?> <html> <head> <title>Change Password</title> <link rel="stylesheet" type="text/css" href="styles.css" /> <script> function validatePassword() { var currentPassword,newPassword,confirmPassword,output = true; currentPassword = document.frmChange.currentPassword; newPassword = document.frmChange.newPassword; confirmPassword = document.frmChange.confirmPassword; if(!currentPassword.value) { currentPassword.focus(); document.getElementById("currentPassword").innerHTML = "required"; output = false; } else if(!newPassword.value) { newPassword.focus(); document.getElementById("newPassword").innerHTML = "required"; output = false; } else if(!confirmPassword.value) { confirmPassword.focus(); document.getElementById("confirmPassword").innerHTML = "required"; output = false; } if(newPassword.value != confirmPassword.value) { newPassword.value=""; confirmPassword.value=""; newPassword.focus(); document.getElementById("confirmPassword").innerHTML = "not same"; output = false; } return output; } </script> </head> <body> <form name="frmChange" method="post" action="" onSubmit="return validatePassword()"> <div style="width: 500px;"> <div class="message"><?php if(isset($message)) { echo $message; } ?></div> <table border="0" cellpadding="10" cellspacing="0" width="500" align="center" class="tblSaveForm"> <tr class="tableheader"> <td colspan="2">Change Password</td> </tr> <tr> <td width="40%"><label>Current Password</label></td> <td width="60%"><input type="password" name="currentPassword" class="txtField" /><span id="currentPassword" class="required"></span></td> </tr> <tr> <td><label>New Password</label></td> <td><input type="password" name="newPassword" class="txtField" /><span id="newPassword" class="required"></span></td> </tr> <td><label>Confirm Password</label></td> <td><input type="password" name="confirmPassword" class="txtField" /><span id="confirmPassword" class="required"></span></td> </tr> <tr> <td colspan="2"><input type="submit" name="submit" value="Submit" class="btnSubmit"></td> </tr> </table> </div> </form> </body> </html> https://phppot.com/php/php-change-password-script/
×
×
  • Create New...