Jump to content

Search the Community

Showing results for tags 'mysql'.



More search options

  • 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

Calendars

  • Community Calendar

Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 249 results

  1. utf8 VS utf8mb4

    Dear all, I came across the following statement on one website: "Note: Since MySQL 5.5.3 you should use utf8mb4 rather than utf8. They both refer to the UTF-8 encoding, but the older utf8 had a MySQL-specific limitation preventing use of characters numbered above 0xFFFD." 1) Is there any drawbacks in using utf8mb4, or it is recommended for use from now on?
  2. Hi I have been working on building a custom post a result set to a database which thankfully I have now managed with some help, now I am working on the other end of this project the displaying the saved data back to users, From the start of this I have an online tournament hosting group that go to my form and post a list of player names with points earned per tournament. Once the form is submitted it's sent to my form_processing.php where the results are exploded and split into 2 arrays "$player_name, $points" Then on the INSERT I have an INSERT $sql = "INSERT into `bg_points` (`player_name`, `points`) values (?, ?) on duplicate key update points = points + ?"; to of course update current player points if the exist or add new records if not. Then finally saved into my DB table, now I am working on building the page to display these points back to the players so they can track their earned points and standings each month. which is easy enough I just call an MySQL SELECT * FROM statement on the DB table that's done, Now I need to sort these results in lowest to highest order by points so if player1 has 120 points player2 has 50 points player3 has 75 points player4 has 5 points then I need to be displaying these back as player4 player2 player3 player1 I have had a look online for some possible examples to help guide me into this and I either get HTTP 500 or just no effect at all. here is the very basic code I have put together so far which I can and will update and add into my site framework once I have it in order and working... <HTML> <head></head> <body bgcolor="#0000FF"> <?PHP $servername = "localhost"; $username = "***********"; $password = "*******"; $dbname = "***********"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } //output the saved data $sql = "SELECT * FROM `bg_points` "; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "id: " . $row["id"]. " $nbsp $nbsp Playerv Name: " . $row["player_name"]. " $nbsp $nbsp Points: " . $row["points"]. "<br>"; } } else { echo "0 results"; } $conn->close(); ?> </body> </html> thanks for any help or ideas in advanced
  3. Hi I am having trouble inserting data into my MySQL database. This is my PHP code ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); static $connection; if(!isset($connection)) { $connection = new mysqli("localhost","username","password"); } if ($connection->connect_error) { die("Connection failed: " . $connection->connect_error); } $stmt = $connection->prepare("INSERT into Product(product_title,product_price,product_availability,productImage_1,productImage_2,productImage_3,productImage_4,product_description,product_shipping,product_pickup) VALUES(?,?,?,?,?,?,?,?,?,?)"); $product_title = $_POST['title']; $product_price = $_POST['price']; $product_availability = $_POST['stock']; $null = NULL; $product_description = $_POST['description']; $product_shipping = $_POST['postage']; $product_pickup = $_POST['pickup']; $stmt->bind_param('sisbbbbsis',$product_title,$product_price,$product_availability,$null,$null,$null,$null,$product_description,$product_shipping,$product_pickup); $stmt->send_long_data(3, file_get_contents($_FILES['img1']['tmp_name'])); $stmt->send_long_data(4, file_get_contents($_FILES['img2']['tmp_name'])); $stmt->send_long_data(5, file_get_contents($_FILES['img3']['tmp_name'])); $stmt->send_long_data(6, file_get_contents($_FILES['img4']['tmp_name'])); $stmt->execute(); $stmt->close(); $connection->close(); echo "Product inserted successfully"; I am also getting these errors. Notice: Undefined index: title in /Applications/MAMP/htdocs/Bourke/insertproduct.php on line 61 Notice: Undefined index: price in /Applications/MAMP/htdocs/Bourke/insertproduct.php on line 62 Notice: Undefined index: stock in /Applications/MAMP/htdocs/Bourke/insertproduct.php on line 63 Notice: Undefined index: description in /Applications/MAMP/htdocs/Bourke/insertproduct.php on line 67 Notice: Undefined index: postage in /Applications/MAMP/htdocs/Bourke/insertproduct.php on line 68 Notice: Undefined index: pickup in /Applications/MAMP/htdocs/Bourke/insertproduct.php on line 69 Fatal error: Call to a member function bind_param() on boolean in /Applications/MAMP/htdocs/Bourke/insertproduct.php on line 71 Thanks in advance.
  4. <?php $host = 'localhost'; $username = 'root'; $password = ''; $datadase = 'registerfinal'; $connect = mysqli_connect($host, $username, $password) or die ('error to connect to datadase'.mysqli_error()); if ($connect) { echo 'mysqli connect succsessfull'; } echo '<br /><br />'; $selectdb = mysqli_select_db($connect, $datadase) or die ('unable to select datadase'.mysqli_error()); if($selectdb) { echo 'database selected succsessfully'; } if(isset($_POST['savedetails'])) { $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $username = $_POST['username']; $password = $_POST['password']; $repeat_password = $_POST['repeat_password']; $gender = $_POST['gender']; $country = $_POST['country']; if(isset($_POST['food'])) { $food = $_POST['food']; $favfood = ""; foreach($food as $meal ) { $favfood = $meal.","; print_r($favfood); } } if(isset($_POST['imageUpload'])) { $imageUploadname = $_FILES['imageUpload']['name']; $imageUploadsize = $_FILES['imageUpload']['size']; $imageUploadtmp_name = $_FILES['imageUpload']['tmp_name']; $imageUploadtype = $_FILES['imageUpload']['type']; $uploadFolder = "uploadFolder/"; $destinationName = rand(1000, 10000).$imageUploadname; move_uploaded_file($imageUploadtmp_name, $uploadFolder.$destinationName); echo "$imageUploadname"; echo "$imageUploadsize"; echo "$imageUploadtmp_name"; echo "$imageUploadtype"; echo "$destinationName"; } $sqltwo = "INSERT INTO `registerfinaltable` (`id`, `firstname`, `lastname`, `username`, `password`, `repeat_password`, `gender`, `food`, `country`, `imageUploadname`, `imageUploadsize`, `imageUploadtype`) VALUES (NULL, '$firstname', '$lastname', '$username', '$password', '$repeat_password', '$gender', '$favfood', '$country', '$destinationName', '$imageUploadsize', '$imageUploadtype')"; $results = mysqli_query($connect, $sqltwo) ; if($results){ echo "inserted successfully"; } } ?> <html> <head> <title>register</title> </head> <body> <form action = "" method = "post" enctype = "multipart/form-data" > <label>first name : <input type = "text" name = "firstname" /> </label> <br /><br /> <label>last name : <input type = "text" name = "lastname" /> </label><br /><br /> <label>username : <input type = "text" name = "username" /> </label><br /><br /> <label>password : <input type = "password" name = "password" /> </label><br /><br /> <label>repeat password : <input type = "password" name = "repeat_password" /> </label><br /><br /> <label>Male : <input type = "radio" name = "gender" value = "Male" /> </label><br /><br /> <label>Female : <input type = "radio" name = "gender" value = "Female" /> </label><br /><br /> <label>pizza : <input type = "checkbox" name = "food[]" value = "pizza"/> </label><br /><br /> <label>burger : <input type = "checkbox" name = "food[]" value = "burger"/> </label><br /><br /> <label>chips : <input type = "checkbox" name = "food[]" value = "chips"/> </label><br /><br /> <label>sausage : <input type = "checkbox" name = "food[]" value = "sausage"/> </label><br /><br /> <label>sandwich : <input type = "checkbox" name = "food[]" value = "sandwich"/> </label><br /><br /> <label>Image : <input type = "file" name = "imageUpload" /> </label><br /><br /> <select name = "country"> <?php $sql = 'SELECT * FROM `countrie` '; $querry = mysqli_query($connect, $sql); while($country = mysqli_fetch_array($querry)):; ?> <option value = "<?php echo $country['country']; ?>"><?php echo $country['country']; ?></option> <?php endwhile;?> </select> <br /> <input type = "submit" name = "savedetails" /> </form> <table border = "1" bgcolor = "" width = "100%"> <tr><th>id</th><th>Firstname</th><th>Lastname</th><th>Username</th><th>Password</th><th>Password 2</th><th>Gender</th><th>Fav. Food</th> <th>Image</th> <th>Country</th><th>imageUploadname</th><th>imageUploadsize</th><th>imageUploadtype</th></tr> <?php $sqldata = "SELECT * FROM registerfinaltable"; $querysqldata = mysqli_query($connect, $sqldata); while($rows = mysqli_fetch_array($querysqldata) ):; ?> <tr> <td><?php echo $rows['id'];?></td> <td><?php echo $rows['firstname'];?></td> <td><?php echo $rows['lastname'];?></td> <td><?php echo $rows['username'];?></td> <td><?php echo $rows['password'];?></td> <td><?php echo $rows['repeat_password'];?></td> <td><?php echo $rows['lastname'];?></td> <td><?php echo $rows['gender'];?></td> <td><?php echo $rows['food'];?></td> <td><?php echo $rows['country'];?></td> <td><?php echo $rows['imageUploadname'];?></td> <td><?php echo $rows['imageUploadsize'];?></td> <td><?php echo $rows['imageUploadtype'];?></td> <?php endwhile;?> </tr> </table> </body> </html>
  5. store javascript in a database column

    My goal is to store javascript code into a database. My first idea was to use htmlspecialchars; store it in mysql in a table column and later retrieve it with htmlspecialchars_decode. All this to prevent injection / hacking. But online I read one or two warnings that it wouldnt work, which I assume is so (I didnt test it, but it seems quite obvious afterwards) . So my question is: is it possible to have a user store javascript in a database and use it in a php script for specific purposes in a secure way?
  6. Hi i am new for the PHP, i had the experienced before to do a login system page but what i want it is HTML and PHP file to separate i dont want PHP with HTML together to 1 file , cause professional people will more likely to use 2 file rather than 1 file easy to maintain and edit how to use the external PHP file coding without re-design whole page cause normally what i tested before was link or turn to other new page and result will come out but the design was totally gone so have any ways and suggestion to do that ... in the end, im sorry i not well in english and my knowledge of PHP still quite new , thanks you so much
  7. HI i trying to create a website of forum textarea editor are necessary too for recommendation which editor are best for textarea such as summernote, wysihtml5 .... and how is work to store the data/value/text with styling effect in mysql database ? Thanks all of you
  8. HI i trying to create a website of forum textarea editor are necessary too for recommendation which editor are best for textarea such as summernote, wysihtml5 .... and how is work to store the data/value/text in mysql database ? Thanks all of you
  9. textarea editor

    HI i trying to create a website of forum textarea editor are necessary too for recommendation which editor are best for textarea such as summernote, wysihtml5 .... and how is work to store the data/value/text in mysql database ? Thanks all of you
  10. Database Connection Issue

    <?php $serv = "localhost:81"; $user = "root"; $password = ""; try { $con = new PDO("mysql:host=$serv;dbname=test", $user, $password); $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Successfully connected."; } catch (PDOException $e) { echo "Connection failed: " . $e->getMessage(); } ?> Here I'm trying to use PDO to connect to my SQL database "test". However, I receive this error each time I connect: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. Am I connecting with the wrong server, user or password? Because I fail to see here the mistake.
  11. Display Everything on the same page

    Hi, I'm trying to get a form where you submit information about a home to a database and below the form it displays the homes with the information and a photo. Below the home information and photo I have a button to DELETE RECORD and a button to upload a photo. All of the php and forms are in one file so submitting the home info and deleting record are just have action="samefile.php". This is so that it stays on the same page and doesn't have to jump to another page. I cannot get the upload photo to stay on the same page. The only way I can get the upload photo to work is to send it to another file. This of course takes me to another page which I don't want. I want everything to stay on the same page. The code I have (in a file called "PicTest03.php) is as follows: <!DOCTYPE html> <head> </head> <html> <body> <form action="PicTest03.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> </form> <br><br><br> <?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 $row[4] <img src="uploads/$row[4]" width=200 height=200> </pre> <pre> <form action="PicTest03.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="mainphoto01.php" method="post" enctype="multipart/form-data"> Select main photo: <input type="hidden" name="serialno" value="$row[10]"> <input type="file" name="fileToUpload" id="fileToUpload"> <input type="submit" value="Upload Image" name="submit"> </form> </pre> <br><br> _END; } $result->close(); $conn->close(); function get_post($conn, $var) { return $conn->real_escape_string($_POST[$var]); } ?> </body> </html> The code for "mainphoto01.php is: <?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 "Hello!"; } } $mainpic = basename( $_FILES["fileToUpload"]["name"]); if(isset($_POST["serialno"])) $serialno = $_POST['serialno']; $query = "UPDATE holidayhomes SET mainpic='$mainpic' WHERE serialno='$serialno'"; $result = $conn->query($query); if(!$result) echo "INSERT failed: $query<br>" . $conn->error . "<br><br>"; ?> No matter what I try I cannot get the above code to work if I keep it in the "PicTest03.php" file. Can someone please show what the code should look like so I can get everything to show on the same page? I have had a look as the PHP and AJAX and DATABASE http://www.w3schools.com/php/php_ajax_database.asp which I got the example working but it uses a drop down list. Is there a way to convert the code used for the example on http://www.w3schools.com/php/php_ajax_database.asp and instead of drop down list just have the information from the database shown under the form for submitting the home information?
  12. JSON data from web server running PHP and MySQL Example

    Hi, I'm trying to follow the JSON example at http://www.w3schools.com/json/json_example.asp I have adjusted the code a little but the code is as follows: jsonTest.html <!DOCTYPE html> <html> <head> <style> h1 { border-bottom: 3px solid #cc9900; color: #996600; font-size: 30px; } table, th , td { border: 1px solid grey; border-collapse: collapse; padding: 5px; } table tr:nth-child(odd) { background-color: #f1f1f1; } table tr:nth-child(even) { background-color: #ffffff; } </style> </head> <body> <h1>Customers</h1> <div id="id01"></div> <script> var xmlhttp = new XMLHttpRequest(); var url = 'jsonTestPHP.php'; xmlhttp.onreadystatechange=function() { if (this.readyState == 4 && this.status == 200) { myFunction(this.responseText); } } xmlhttp.open("GET", url, true); xmlhttp.send(); function myFunction(response) { var arr = JSON.parse(response); var i; var out = "<table>"; for(i = 0; i < arr.length; i++) { out += "<tr><td>" + arr.Name + "</td><td>" + arr.Bedrooms + "</td><td>" + arr.Length + "</td></tr>"; } out += "</table>"; document.getElementById("id01").innerHTML = out; } </script> </body> </html> jsonTest.php <?php header("Access-Control-Allow-Origin: *"); header("Content-Type: application/json; charset=UTF-8"); require_once 'login.php'; $conn = new mysqli($hn, $un, $pw, $db); if ($conn->connect_error) die($conn->connect_error); $result = $conn->query("SELECT name, bedrooms, length FROM holidyhomes"); $outp = "["; while($rs = $result->fetch_array(MYSQLI_ASSOC)) { if ($outp != "[") {$outp .= ",";} $outp .= '{"Name":"' . $rs["name"] . '",'; $outp .= '"Bedrooms":"' . $rs["bedrooms"] . '",'; $outp .= '"Length":"'. $rs["length"] . '"}'; } $outp .="]"; $conn->close(); echo($outp); ?> So I have changed the var url = "http://www.w3schools.com/website/customers_mysql.php"; from the jsonTest.html to var url = 'jsonTestPHP.php'; When I run this I get "Invalid character: var arr = JSON.parse(response);" I just want to be able to grab the data from my database and display it on screen using JSON. Can anyone help me understand why I'm getting this Invalid character error or tell me if I'm going about this the totally wrong way? Thanks
  13. Interactive web comic aggregator general design?

    Hello, I am currently in the middle of creating a web comic aggregation website. So far, I have written a PHP-based RSS reader that grabs the image source links and publication dates for various web comics from their RSS feeds, and uses this to update a MySQL database. This RSS reader/database updater is configured to run once every several hours and update the database with any new comics it finds. It seems to be working fine, and now I am starting to work on the front end of the website, which needs to grab this information from the ever-growing database, and display it in a user-friendly and interactive format. I wrote the database updater in a fairly procedural way, because it didn't strike me as something that lent itself very much to object-oriented development. However, the front end of the website does strike me as something that I can save myself a lot of time on by coming up with a decent object oriented design first. Unfortunately, I don't have a lot of experience in this, so I thought I would look online for suggestions. So far, I have decided specifically what I would like the front end to do, and have come up with 2 possible approaches to designing it, but am unsure about both. Here's what I would like it to do: (To clarify, when I say the phrase "comic strip," I'm referring to a whole strip like XKCD, Dilbert, the far side, etc., and when I say the phrase "comic," it refers to an individual comic within a comic strip, i.e. the Dilbert comic for 8/30/2016). I would like my webpage, by default, to display a vertically stacked list of the latest comic images from each comic strip in the database. For customization, I want a comic strip control panel, which allows users to decide which comic strips are enabled/disabled, and in what order they are displayed. I would like each comic image to appear between text denoting the name/author of the strip and an individual set of buttons that allows the user to go forward and backward through the archived comics, and also to adjust the size/scaling of the image. Finally, I would like a similar but generalized set of buttons that allows the user to control all the comic strips in the same fashion, but at once. Based on my basic understanding of object oriented programming, and the design approach suggested in this stack overflow answer: http://stackoverflow.com/questions/1100819/how-do-you-design-object-oriented-projects, I came up with one possible design: Two classes: 1) a comic strip class that contains attributes like the comic strip's name, ID number (from my database), enabled/disabled status, and current comic to display (an object of the next class), in addition to functions to get and set each of these variables, 2) a comic class that contains attributes like the image source link, publication date, and scaling percentage, in addition to functions to get and set each of these variables Then the main webpage would contain a comic strip control panel and general comic control panel as described in the desired functionality. In addition, it would contain an array of individual comic control panels, and an array of div tags (or a similar tag), which would be displayed vertically stacked and alternating along with the comic strip names in plain text. Finally, there would be functions for updating comic and comic strip object information from the database, and functions for updating the div tag content for comic display based on the comic object information. All the functions would be called using JavaScript/Ajax from the appropriate buttons. However, I was unsure about this design, so I asked a friend, who suggested that I use a model-view-controller design pattern, which I guess is popular in web development because its potential for separating all the various languages. After reading about this online, I have come up with a possible alternative design: Model: PHP, an array of comic strips, including name and ID number, active/inactive status, and current comic image URL/publishing date View: PHP generated HTML/CSS, as described before, a comic strip control panel for enabling/disabling and ordering, a vertically stacked list of comic strip names, constituent comic images, and individual control buttons, and a general set of buttons for controlling all enabled comics at once Controller: PHP/MySQL, a function to update order and active/inactive comic strip status, a function to update a given comic strip's current comic information, and a function to update all comic strips' current comic information at once As I understand it, the controller functions would be called upon user input into the view (clicking the buttons), which would then update the information stored in the model, and then somehow that would trigger a refresh of the view based on the new model information. I am worried I may have missed something in each of these designs (especially the first one), and unsure about the potential merits of one versus another. I was also wondering if it might be possible to combine the two somehow. Does anyone have any suggestions? Help would be much appreciated
  14. UPLOAD THEN DISPLAY PHOTOS TO/FROM MySQL WITH PHP

    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?
  15. I have the following peace of code. I cant solve how to fetch all the records in the database. I have to use prepare but if I use place holders for $sql then it doesnt work I tried foreach and while but I dont know how to use it. Can someone please tell what code to use to fetch multiple records from a table? <?php // make connection to database $sql = "SELECT id_nr, name FROM table;"; $id_nr =1; if ($stmt = $conn->prepare($sql)) { $stmt->bind_param('i', $id_nr); $stmt->execute(); $stmt->store_result(); $num_of_rows = $stmt->num_rows; $stmt->bind_result($id_nr, $name); while ($stmt->fetch()) { echo ' id number : ' . $id_nr . '<br>'; echo ' name : ' . $name . '<br>'; } $stmt->free_result(); } $stmt->close(); mysqli_close($conn); } ?>
  16. Hello, I am creating a web comic aggregation website. I am currently working on the back end in PHP, which uses an RSS reader to update a MySQL database every so often. Than I want the front end to access this database every time a user accesses the website. However, it seems like this will inevitably cause simultaneous reading from and writing to the database, from the front and back ends, respectively. Is this going to cause problems down the line? Or can MySQL handle this without glitching? Thanks in advance
  17. query to check existance of a record

    How to find a record in a table? I now use : $sql = "SELECT col1 FROM table WHERE col1 = '$var' " ; if ($stmt = $conn->prepare($sql)) { $stmt->execute(); $stmt->bind_result($var); while ($stmt->fetch()) { echo $var; echo ' : this variable exists <br>'; } $stmt->close(); } to fetch $var. But this actually results in an echo of the input. The goal is not necessarily echoing it, but determining whether it exists or not and report that its not existing So is it possible with other query to determine if $var exists and then use that as TRUE ?
  18. Selecting No of records in php & mysql

    i want to show the record from mysql database when the users are not paid the initial amount? my database look like this: i've a table called roombooking in that field i've several columns like name,mob ,paid_amount and balance_amount.. so i want to retrieve a data who are all not paid the initial amount.... can u please tell me how to show it? Thanks in advance
  19. trying to design an efficient database for my website?

    Hello, I am currently working on a web comic aggregation website. My general Design is an RSS reader that grabs the publishing date and image source link From various web comic RSS feeds each time they are updated, and uses this to update a database. Then the front end accesses this database info to be displayed in a user-friendly format each time someone accesses the website. I might eventually add a user account system to store user preferences about comic arrangements, which would also need to be put in the database. I am currently writing the back end in PHP and MySQL, and am trying to decide on a general database design. I googled how to design an efficient relational database, which provided a lot of information, but also filled me with fear that my database will be massively inefficient (because I've never done this before), and that it will eventually make my site slow and unusable. So I thought I would check my design on some forums before I proceed. My original plan was to have two databases: one for comics, then one for users later (am not too concerned about this one, because I'm sure there are a ton of examples for how to make an efficient username/password/info database). The comics database would have one table for each different comic, and each table would have a column for publishing date and image source link. However, after reading about database normalization, I thought of an alternative design: one table for comics, including their name and a primary ID,and then one table for publishing dates and one table for image source links, both including their own primary ID, and also the foreign key of the comic ID for each link or date. However, then I realized that the publishing dates table isn't going to make any sense because the publishing date is kind of like a key for the image source link. So basically I'm pretty confused as to how to generally arrange my tables and fields. I was wondering if anyone has any suggestions? I also have another concern. Some RSS feeds do not include publication dates, so it's possible that I am going to need to have some null entries for publishing dates. The MySQL manual told me to use the "NOT NULL" whenever possible, so I was wondering if not using it for this category will be a problem? Finally, there are a few miscellaneous things that I was wondering about. I have read that I can change table types, storage engines, and row format (compact, dynamic, compresse, etc.). I have also read that sometimes websites sacrifice normalization (and thus total storage space) for speed somehow. I was wondering if these more nitpicky details are important for my website? Although I plan on accumulating very long lists of individual comics (at least thousands, maybe tens of thousands for each different web comic), and the website could potentially become accessed very frequently if it became popular, it doesn't seem like what I am trying to do with my database is nearly as complicated as the kinds of things that most people are trying to do. So I was wondering how much of this optimization stuff is really worth the time, and how much of it is just going to make insignificant differences in the performance of my website? Help would be much appreciated
  20. How To show category wise posts using custom fields i am use acf plugin and i want show custom fields page i have 3 custom fields 1 album 2 artist 3 lyrics and 2 category 1st remix 2nd top song i want creat deffrant page for all 3 fields like 1st page album where i can show all album with 1st category with paging See Below Attached file For Best Understanding
  21. "Require_once" produces "undefined variable"

    Hi guys! I have a little problem and it's that I get an error in a determined function where I call my connection and I don't know why. The errors are: 1) Notice: Undefined variable: conexionidiomas in C:\wamp64\www\idiomas\preguntas-frecuentes.php on line 10 2) Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\wamp64\www\idiomas\preguntas-frecuentes.php on line 11 This is what I have from "/Connections/conexionidiomas.php": # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_conexionidiomas = "p:localhost:3307"; $database_conexionidiomas = "idiomasbd"; $username_conexionidiomas = "root"; $password_conexionidiomas = "asdasdf"; $conexionidiomas = mysqli_connect($hostname_conexionidiomas, $username_conexionidiomas, $password_conexionidiomas, $database_conexionidiomas); and this in "preguntas-frecuentes.php": <?php require_once('Connections/conexionidiomas.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($conexionidiomas, $theValue) : mysqli_escape_string($conexionidiomas,$theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO tblfrecuentes (strPregunta,fchFecha) VALUES (%s,NOW())",GetSQLValueString($_POST['strPregunta'], "text")); $Result1 = mysqli_query($conexionidiomas,$insertSQL) or die(mysqli_error($conexionidiomas)); } ?> So, if someone could help me I'd appreciate it so much. Regards!
  22. Hi I want to bring this information to insert multiple records from select <?PHP error_reporting(0); include("connect.inc.php"); ?> <?php include "connect.inc.php"; if (isset($_POST['submit'])) { $province_id = $_POST['province_id'][$i]; $province_id = $_POST['travel_id'][$i]; $i = 0; foreach ( $_POST as $val) { mysql_query("INSERT INTO travel_list (province_id, travel_id) VALUES ('$province_id', '$travel_id')"); $i++; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="css/bootstrap.min.css" rel="stylesheet" media="screen"> <script src="js/bootstrap.min.js"></script> <title>Untitled Document</title> </head> <body> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> <script src="respond.js"></script> <form action="index.php" method="post"> <!--ส่งค่า post ไปหน้าเดิม --> <table width="896" border="1"> <thead> <tr> <th width="239">จังหวัด</th> <th width="552">สถานที่ท่องเที่ยว</th> <th width="83"><input type="hidden" id="txtNum" value="1" size="2" /></th> </tr> <tr> <th width="239"> <select id="selProvince" name="province_id[]"> <!--Default จังหวััด--> <option value="">กรุณาเลือกจังหวัด</option> <?PHP $SelectPr="SELECT * FROM province"; $QueryPro=mysql_query($SelectPr); while($Pro=mysql_fetch_array($QueryPro)){ ?> <option value="<?=$Pro['province_id']?>"><?=$Pro['province_name']?></option> <?PHP } ?> </select> </th> <th width="552"><select name ="travel_id[]" id="selTravel"><option value="">กรุณาเลือกจังหวัด</option></select></th> <th width="83"><button type="button" id="btnP">เพิ่มรายการ</button></th> </tr> <tr><td colspan="3"><center>รายการที่เพิ่ม</center></td></tr> </thead> <tbody> </tbody> </table> <input name="submit" type="submit" value="add"> </form> <br><br><br> <!--ทอสอบ ค่าแสดงผล Muti Atrray--> </body> </html> I'm insert 1 record but I choose just one , but more data is imported into fifth data . Informationprovince_id, travel_id not insert into HELP ME HOT FIX CODE I choose just one , but more data is imported into fifth data .
  23. I need to check if value inserting in database while **import excel file** , if it has already value in database then it should get update. Below is producttab table value in database prdid | prdname 00A | prd1 00B | prd2 00C | prd3 00D | prd4 Below is EXCEL FILE data prdid | prdname 00A | prdnew 00B | prd2new 00E | prd8 00H | prd9 So if i upload above excel file then , 00A , 00B should get UPDATE IN producttab table as they are already present there... but 00E,00H should get insert below is what i have tried, value is getting insert properly only UPDATE IS NOT HAPPENING if(isset($_POST["Upload"])) { $fileinfo = pathinfo($_FILES["uploadFile"]["name"]); $filetype = $_FILES["uploadFile"]["type"]; $remark = NULL; //Validate File Type if(strtolower(trim($fileinfo["extension"])) != "csv") { $_SESSION['msg_r'] = "Please select CSV file"; header("location:importfile.php"); exit; } else { $file_path = $_FILES["uploadFile"]["tmp_name"]; } $row = 0; $tempFileName = time().".csv"; if ( is_uploaded_file( $file_path ) ) { $fileCopied = copy( $file_path , $tempFileName); if (($handle = fopen($tempFileName, "r")) !== FALSE) { fgetcsv($handle); while (($data = fgetcsv($handle, 6000, ",")) !== FALSE) { $num = count($data); for ($c=0; $c < $num; $c++) { $col[$c] = $data[$c]; } $col1 = $col[0]; // prdid $col2 = $col[1]; // prdname $sql = "SELECT prdid FROM producttab WHERE prdid = '".$col1."' "; $query = db_query($sql); $pfetech = db_fetch($query); if($col1 == $pfetech['prdid']){ $sqlup = "UPDATE producttab SET prdid = ".$pfetech['prdid'].", prdname = ".$col2." "; $sqlup .= " WHERE prdid = ".$pfetech['prdid']." "; $resultsqlupdate = mysql_query($sqlup); }else{ $query = "INSERT INTO producttab(prdid,prdname) VALUES('".$col1."','".$col2.")"; $s = mysql_query($query); } } fclose($handle); } echo "<center>File data imported to database!!</center>"; } } }
  24. I have a table which is either empty or has 1 record If the table is empty i cant retrieve info from the database and get an error message. my code: $sql = "SELECT id FROM users WHERE id = (SELECT MAX(id)FROM users)"; $result = $conn->query($sql); foreach ( $conn->query($sql) as $row ) { $id = $row['id']; the for each line gives an error message: how to solve this?
  25. Its PHP MYSQL : I have a table prodt , in which i first INSERT a value and with its LAST INSERT ID i do update for MAX + 1 as below , BUT I AM GETTING ERROR You can't specify target table 'prodt' for update in FROM clause $a = db_insert_id(); $sqllast = "UPDATE prodt SET pdname= ((SELECT pdname FROM ( SELECT MAX( pdname ) AS pdname FROM prodt WHERE oid = ".db_escape($oid)." ) AS pdname ) + 1 ), pcyn = ".db_escape(0)." WHERE id = ".db_escape($a)." AND oid= ".db_escape($oid)." "; $resultsqllast = db_query($sqllast); if((!$resultsqllast) || (db_mysql_affected_rows($db) <= 0)) { throw new Exception('Wrong SQL UPDATE' . $sqllast . ' Error: '.db_error_msg($db) . db_error_no()); } After research i tried below : $sqllast = "UPDATE prodt SET pdname= ((SELECT pdname FROM ( SELECT MAX( pdname ) AS pdname FROM ( SELECT * FROM prodt WHERE oid = ".db_escape($oid)." )AS pdname ) AS pdname ) + 1 ), pcyn = ".db_escape(0)." WHERE id = ".db_escape($a)." AND oid= ".db_escape($oid)." "; $resultsqllast = db_query($sqllast); if((!$resultsqllast) || (db_mysql_affected_rows($db) <= 0)) { throw new Exception('Wrong SQL UPDATE' . $sqllast . ' Error: '.db_error_msg($db) . db_error_no()); } But still its not working, getting same error message ... Thanks
×