Jump to content

Search the Community

Showing results for tags 'Insert Photos'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 1 result

  1. Hi, I'm trying to do a simple website where I can upload some information about homes and add photos to a MySQL database and then display the information. So I have an html form that sends the details of the home to a php file called details.php. The html form is as follows. <!DOCTYPE html> <html> <body> <form action="details.php" method="POST"> <pre> Name <input type="" name="name"> Bedrooms <input type="text" name="bedrooms"> Length <input type="text" name="length"> Width <input type="text" name="width"> Serial Number <input type="text" name="serialno"> <input type="submit" value="ADD RECORD"> </pre> </body> </html> The details.php look like the following: <?php require_once 'login.php'; $conn = new mysqli($hn, $un, $pw, $db); if ($conn->connect_error) die($conn->connect_error); if (isset($_POST['delete'])&& isset($_POST['serialno'])) { $serialno = get_post($conn, 'serialno'); $query = "DELETE FROM holidayhomes WHERE serialno='$serialno'"; $result = $conn->query($query); if (!$result) echo "DELETE failed: $query<br>" . $conn->error . "<br><br>"; } if (isset ($_POST['name']) && isset ($_POST['bedrooms']) && isset ($_POST['length']) && isset ($_POST['width']) && isset ($_POST['serialno'])) { $name = get_post ($conn, 'name'); $bedrooms = get_post ($conn, 'bedrooms'); $length = get_post ($conn, 'length'); $width = get_post ($conn, 'width'); $serialno = get_post ($conn, 'serialno'); $query = "INSERT INTO holidayhomes (name, bedrooms, length, width, serialno) VALUES ('$name','$bedrooms', '$length', '$width', '$serialno')"; $result = $conn->query($query); if (!$result) echo "INSERT failed: $query<br>" . $conn->error . "<br><br>"; } $query = "SELECT * FROM holidayhomes"; $result = $conn->query($query); if (!$result) die ("Database access failed: " . $conn->error); $rows = $result->num_rows; for ($j = 0 ; $j < $rows ; ++$j) { $result->data_seek($j); $row = $result->fetch_array(MYSQLI_NUM); echo <<<_END <pre> Name $row[0] Bedrooms $row[1] Length $row[2] Width $row[3] Serial No $row[10] MainPic <img src="$row[4]" width=auto height=auto><br><br> </pre> <pre> <form action="details.php" method="POST"> <input type="hidden" name="delete" value="yes"> <input type="hidden" name="serialno" value="$row[10]"> <input type="submit" value="DELETE RECORD"> </form> </pre> <pre> <form action="mainphoto.php" method="post" enctype="multipart/form-data"> Select main photo: <input type="file" name="fileToUpload" id="fileToUpload"> <input type="submit" value="Upload Image" name="submit"> </form> </pre> _END; } $result->close(); $conn->close(); function get_post($conn, $var) { return $conn->real_escape_string($_POST[$var]); } ?> ​So the above inserts the information (about a home entered in the html form) into the MySQL database then displays the information and an option to delete the homes information then I have a form to upload a photo for the home. For uploading the photo I have a php file called mainphoto.php which is as follows: <?php require_once 'login.php'; $conn = new mysqli($hn, $un, $pw, $db); if ($conn->connect_error) die($conn->connect_error); $target_dir = "uploads/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION); if(isset($_POST["submit"])) { $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if($check !== false){ echo "FIle is an image - " . $check["mime"] . "." ; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } } if ($uploadOk == 0){ echo "Sorry, your file was not uploaded."; } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)){ echo "The file " . basename( $_FILES["fileToUpload"]["name"]) . " has been uploaded."; } else { echo " off!"; } } $mainpic = basename( $_FILES["fileToUpload"]["name"]); $query = "INSERT INTO holidayhomes (mainpic) VALUES ('$mainpic')"; $result = $conn->query($query); if(!$result) echo "INSERT failed: $query<br>" . $conn->error . "<br><br>"; ?> How do I get the form to submit and add the name of the photo to the same record(row) as the homes information? So then when it iterates through the record(rows) in the MySQL database I can display the photo to the relevant information about the home?
×
×
  • Create New...