Jump to content

Search the Community

Showing results for tags 'mysql'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

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


Age


Donation Link

  1. hi, I have six tables each having a column field (order_no), now i want to match that something like this. 1- select order_no from table 1 where order_no != with order_no present in all other six tables. Can any one suggest which join query or which query i should use to achieve this? thanks
  2. Good Day Guys I have a bit of a urgent problem. Here is my Query: $query = "SELECT distinct Img.propertyId as PropertyId, Title, ImageUrl, Location, Bedrooms, Bathrooms, Parking, Price FROM PROPERTIES as Prop LEFT JOIN IMAGES as Img ON Img.PropertyId = Prop.PropertyId WHERE 1=1 AND Price >=1000 AND Price <=5000 "; I have a problem and the problem is here - AND Price >=1000 AND Price <=5000. This works fine but the problem comes as soon as I add more: For example: if I add OR Price >5000 AND Price <=10000 then it displays all my results from 1000 to 10000 and I want it to be if I select 5000 - 10000 it needs to display only the results between 5000 and 10000. Can someone please help me?
  3. Hello there, I'm really new at PHP and I've been reading several beginner tutorials so please accept my apologies for any stupid questions I may ask along the way. I've gotten as far as installing XAMPP, set up a database plus PHP form and I'm struggling to figure out how to insert values from an array into my database. I've learnt the code in one particular way (see beginner tutorials) so I was wondering if you could help me keeping this in mind. I know there'll be a million better ways to do what I'm doing but I fear I will be bamboozled with different code or differently structured code. Anyway the tutuorials I'm reading don't see to cover how I can insert an array of values into my database, just singular values. In the attached file, I have 10 rows of 2x text inputs (20 text inputs total). Each row allows the user to enter a CarID and CarTitle. I've commented out the jQuery which validates the inputs so I can build a rudimentary version of this validation with PHP. I thought that because the line $sql="INSERT INTO carids_cartitles (CarID, CarTitle) VALUES ($id, $title)"; is inside the foreach, means that for each pair of values from the form it'd insert to the database. It doesn't do this. If I enter two or more CarIDs and CarTitles, only one pair of values gets saved to the database. I'm sorry if I haven't explained this well enough, any questions please let me know. Many thanks for your help in advance. form.php
  4. Hi, I have multiple table Table -1 order_no name 1 raj table -2 order_no name 1 raj table 3 order_no name 1 raj table 4 order_no name 1 raj table 5 order_no name 1 raj I want a query to check if the id (one) is present in all tables or not, i create this. select order_no from prepress, press, postpress, qc, binding, dispatch where order_no=prepress.order_no AND order_no=press.order_no AND order_no=postpress.order_no AND order_no=qc.order_no AND order_no=binding.order_no AND order_no=dispatch.order_no but the ambiguous error for order_no. how to achieve this can anyone suggest me? thanks
  5. Hi I have this Query and would like to get help on this. I have a table with Price in it and on my search form I have Min Price and Max Price, I want to connect the min and max price to price so that when people do a search ith will display the results between the min and max price they chose, for instants: Min Price = 1000 and Max Price = 10000 it have to give me that results between that 1000 and 10000. $query = "SELECT distinct Img.propertyId as PropertyId, Title, ImageUrl, Location, Bedrooms, Bathrooms, Parking, Price FROM PROPERTIES as Prop LEFT JOIN IMAGES as Img ON Img.PropertyId = Prop.PropertyId WHERE 1=1 "; Thank you
  6. HI, I am a beginner at programing and I have to do this project where it is asking me to valid ISBN 10 and 13 using MySQL database to store the information. I checked my php code to validate ISBN 10 and 13 and it works, but when I try to store the data to MySQL it is not working. What I mean is that when I click ShowISBN link it doesn't show this information: ISBN Number ISBN Type Date Entered using timestamp Valid or Invalid This is the codes I have for input page of ISBN page: <?php //this is the isset function which allows us to submit back //to the same form. If there isn't anything in the ISBN, it will //show the bottom part of the form if(isset($_POST["ISBN"])|| empty($_POST['isbn_type']) || empty($_POST['Valid_Invalid'])) { $ISBN = $_POST["ISBN"];; $IsbnType = $_POST["isbn_type"];; $VaorIn = $_POST["Valid_Invalid"];; $ISBN_Arr = str_split($ISBN); $not10 =0; $notNum=0; $notX=0; //entering error checking for the code //check for 10 first, if clear do additional checking if(strlen($ISBN) == 10) {//start further error checking //check to make sure first 9 are numeric for($i=0;$i<=8;$i++) { if(!is_numeric($ISBN_Arr[$i])) $notNum = 1; }//end for loop check //check to see if there is a X or a x if($ISBN_Arr[9]=='x' || $ISBN_Arr[9]=='X') { $ISBN_Arr[9] = 10; } //if not an x, is it at least numeric? else if (!is_numeric($ISBN_Arr[9]) ) { $notX=1; } }//end additional error checking else { $not10=1; }//end not 10 check //start of error messages if prereqs are not met if($notNum ==1 || $notX ==1 || $not10) { Print "<h2>Input error</h2><br/>"; Print "Here is the error(s) discovered:<br/>"; if($notNum ==1) print"Your ISBN contains non-numeric data.<br/>"; if($notX ==1) print"The last digit is not a number or a X.<br/>"; if($not10 ==1) print"ISBN 10 number should contain 10 characters.<br/>"; include"ISBN_not_val_include.html"; } //end error checking else{ $chk_sum_num=10; $chk_sum =0; for($i=0;$i<=9;$i++) { $chk_sum +=$ISBN_Arr[$i] *$chk_sum_num; //print"$ISBN_Arr[$i] | $chk_sum_num<br/>"; $chk_sum_num--; }//end for loop $is_valid_ISBN= $chk_sum%11; //print"chk_sum: $chk_sum </br> is_valid_ISBN: $is_valid_ISBN</br>"; if($is_valid_ISBN==0) { print"<h3>VALID</h3><br/>"; print"$ISBN is a VALID 10 digit ISBN number.<br/>"; include"ISBN_val_include.html"; } else{ print"<h3>INVALID</h3><br/>"; print"$ISBN is an INVALID 10 number ISBN.<br/>"; include"ISBN_not_val_include.html"; }//end is_valid if }//end }//end is set if else{ include"ISBN_val_include.html"; }//end isset else ?> </form> <p><a href="_ShowISBN10and13DBProject.php">Show ISBN </a></p> </body> </html> This is the second part of the code that incorporates php and MySQL: <?php if (empty($_POST['ISBN'])|| empty($_POST['isbn_type']) || empty($_POST['Valid_Invalid'])) echo "<p>You must enter a Valid ISBN 10 to Continue! Please Click your browser's Back Button to return to the input page of ISBN 10 with Database.</p>\n"; else { $DBConnect = @mysql_connect("xxx.xxx.xx.xxx", "xxxxxxxx", "xxxxxxxx"); if($DBConnect === false) echo"<p>Unable to conenct to the database server.</p>" . "<p>Error code " . mysql_errno() . ": " . mysql_error() . "</p>"; else{ $DBName = "xxxxxxxx"; if (!@mysql_select_db($DBName, $DBConnect)) { $SQLstring = "CREATE DATABASE $DBName"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "<p>Unable to execute the query.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>"; else echo "<p>You are the first visitor!</p>"; } mysql_select_db($DBName, $DBConnect); $TableName = "isbn"; $SQLstring = "SHOW TABLES LIKE '$TableName'"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "<p>Unable to create the table.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>"; $ISBNum = stripslashes($_POST['ISBN']); $ISBNType = stripslashes($_POST['isbn_type']); $VaORIn = stripslashes($_POST['Valid_Invalid']); $SQLstring = "INSERT INTO $TableName VALUES(NULL, '$ISBNum', '$ISBNType', '$VaORIn')"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if($QueryResult === false) echo"<p>Unable to execute the query.</p>" . "<p>Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>"; else echo"<h1>Thank you for trying our ISBN 10 program!</h1>"; mysql_close($DBConnect); } } ?><!--End PHP Script--> This is the page where it is not working! <?php $DBConnect = @mysql_connect("xxx.xxx.xx.xxx", "xxxxxxx", "xxxxx"); if($DBConnect === false) echo"<p>Unable to conenct to the database server.</p>" . "<p>Error code " . mysql_errno() . ": " . mysql_error() . "</p>"; else{ $DBName = "xxxxxx"; if (!@mysql_select_db($DBName, $DBConnect)) echo"<p>There are no entries in the guest book!</p>"; else { $TableName = "isbn"; $SQLstring = "SELECT * FROM $TableName"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if (mysql_num_rows($QueryResult) == 0) echo"<p>There are no entries in the ISBN 10 Database!</p>"; else{ echo"<p>The following ISBN have been recorded:</p>"; echo"<table width='100%' border='1'>"; echo"<tr><th>ISBN Number</th><th>ISBN Type</th><th> Date Entred</th><th> Valid OR Invalid</th></tr>"; while (($Row = mysql_fetch_assoc($QueryResult)) !==FALSE) { echo "<tr><td>{$Row['ISBN']}</td>"; echo "<tr><td>{$Row['isbn_type']}</td>"; echo "<tr><td>{$Row['TIMESTAMP']}</td>"; echo "<td>{$Row['Valid_Invalid']}</td></tr>"; } } mysql_free_result($QueryResult); } mysql_close($DBConnect); } When I click show ISBN nothing happens and I am not shore why! This is how I have my table setup in MySQL Manually by clicking table and create table: Columns: count int(11) Al PK ISBN varchar(45) isbn_type varchar(45) TIMESTMP datetime PK Valid_Invalid varchar(45) Can someone please tell me why when I click Show ISBN in the input page the first code pasted I get nothing! How do I fix the issue because my validation works, but it's not storing it or showing up when click Show ISBN! Any help will be appreciate it!
  7. hi guys so i have this add contacts page and the form is divided into 3 different froms 1) primary contact 2)spouse 3)child and the child form data is inserted as array into database because in the primary contact part of the form there is a "Children ?" with yes and no radio button and if yes a drop down list is enabled where if user chooses say 2 then there would be 2 child form that appears. and since theres 2 children then in the database a new row and data will be added accordingly. image attached to be clearer. i got it inserted into database but in the specified field it says array: |child_name|dob|house_add1|mobile|office|email| inserted: |array|array-array-array|array|array|array|array| query: "INSERT INTO child VALUES('','".$childsalutations." $childfname $childlname',' ".$cday."-".$cmonth."-$cyear ','$childline1','$childline2','$childm','$childoff','$childemail')" in a stackoverflow question(not my own question) someone says: information stating arrays need to be split, before inserting into the table. does that mean something like this?: $cday = ($_POST['cday']); $cmonth = ($_POST['cmonth']); $cyear = ($_POST['cyear']); $childsalutations = ($_POST['child-salutations']); $childfname = ($_POST['child-fname']); $childlname = ($_POST['child-lname']); $childline1 = ($_POST['child-line1']); $childemail = ($_POST['child-email']); $childm = ($_POST['child-mobile']); $childoff = ($_POST['child-office']); $info = array('c_name' => $childsalutation $childfname $childlname, 'c_dob' => $cday-$cmonth-$cyear, 'c_line1' => $childline1, 'c_mobile' => $childm, 'c_office' => $childoff, 'c_email' => $childemail) just in case u wanted to c the html child form(warning its abit long,very!): <table class="prime"> <tbody> <br> <tr><td style="font-size:20px;font-weight:bold">Child <span id="number"></span></td></tr> <tr> <td>Salutation :</td> <td><select name="child-salutations[]" id="child-salutations"> <option value="" disabled selected>Salutations</option> <option value="Datin">Datin</option> <option value="Datin Paduka">Datin Paduka</option> <option value="Dato Paduka">Dato Paduka</option> <option value="Dato'">Dato'</option> <option value="Dato' Seri">Dato' Seri</option> <option value="Datuk">Datuk</option> <option value="Datuk Seri">Datuk Seri</option> <option value="Dr.">Dr.</option> <option value="Haji">Haji</option> <option value="Hajjah">Hajjah</option> <option value="HM">HM</option> <option value="HRH">HRH</option> <option value="Miss">Miss</option> <option value="Mrs.">Mrs.</option> <option value="Mr.">Mr.</option> <option value="Pehin">Pehin</option> <option value="Professor">Professor</option> <option value="Raja">Raja</option> <option value="Tan Sri">Tan Sri</option> <option value="Tengku">Tengku</option> <option value="Tuanku">Tuanku</option> <option value="Tun">Tun</option> <option value="Tunku">Tunku</option> <option value="Ungku">Ungku</option> </select> </td> </tr> <tr><td colspan="2"><label class="label" style="color:Red">*If a person has many salutations, choose the highest form of salutation</label></td></tr> <tr><td>First Name :</td><td><input type="text" name="child-fname[]" id="child-fname" class="style" /></td> <td>Last Name :</td><td><input type="text" name="child-lname[]" id="child-lname" class="style" /></td></tr> <tr> <td>Date of Birth : </td> <td> <select name="cday[]"> <option value=""selected disabled>Day</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select name="cmonth[]"> <option value="" selected disabled>Month</option> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> Year : <input type="text" name="cyear[]" maxlength="4" size="4" class="year"> </td> </tr> <tr><td>Where do they live ?</td><td colspan="3"><input type="radio" name="living[]" id="living-me" class="living-me"/>With Me<input type="radio" name="living[]" id="living-other" class="living-other"/>With Other Parent<input type="radio" name="living[]" id="living-own" class="living-own"/>Own</td></tr> <tr><td>House Address</td></tr> <tr><td>Line 1 :</td><td><input type="text" name="child-line1[]" id="child-line1" size="20" class="style" /></td> <td>Mobile No :</td><td><input type="text" name="child-mobile[]" id="child-mobile" class="style" /></td></tr> <tr><td>Office No :</td><td><input type="text" name="child-office[]" id="child-office" class="style" /></td> <td>Email Address : </td><td><input type="email" name="child-email[]" id="email" class="style" /></td></tr> </tbody> </table>
  8. Newbie here, would love some help to find out what I'm doing wrong on this code. I'm using phpChart to make a graph. This is my code, but the graph does not appear. <?php require_once("phpChart_Lite/conf.php"); include 'connection.php'; ?> <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>phpChart - Basic Chart</title> </head> <body> <?php $query = mysqli_query($con, "SELECT krl FROM diesel WHERE sted = 'Borgeskogen' ORDER BY dato ASC"); // set array $price = array(); // look through query while($row = mysqli_fetch_assoc($query)){ // add each row returned into an array $price[] = $row['krl']; } //$pc = new C_PhpChartX(array(array(11, 9, 5, 12, 14)),'basic_chart'); $pc = new C_PhpChartX(array($price),'basic_chart'); $pc->set_animate(true); $pc->draw(); ?> </body> </html>
  9. What's up guys! Can somebody please explain the meaning of PDO::PARAM_INT in the following statement: $pdoStmt->bindValue(":num", $num, PDO::PARAM_INT); I have already created a PDO Statement object called $pdoStmt. This line will bind the value of $num to the placeholder called :num. I know that PDO::PARAM_INT is a Predefined Constant but what does it do in this case? Thanx
  10. Hello All, I've added search to my CMS and one column of data in particular is a date column. My whileLoop spits out data I want however it sorts the date field ASC but I need is DESC. I've tried adding the ORDER BY in several different ways however I keep getting an error... what would be the best approach to get it to sort the way I want using my current SELECT statement $search_sql = " SELECT * FROM tracking INNER JOIN sender ON tracking_sender_id = sender_id INNER JOIN method ON tracking_method_id = method_id WHERE (tracking_recepient LIKE '%" . $_POST['search'] . "%')"; the above code works fine but the output sorts ASC, can seem to add the ORDER BY in an appropriate manner to get it DESC. Any advice ? Thank you in advance
  11. Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\page\verify_security.php on line 170 earlier the code has been running fine and now it is showing error to me , can you tell something more about it ???
  12. in database, I have faced error where query does not responded properly it was showing the error message that "too much query, user cannot execute more query".... when I increased the limit, it works for sometime and after sometime, it again generates the error , my question here is: "why the error is occurring ?" "what is the correct way to improve the execution of multiple queries at single instance ??? "
  13. Hi, I am little bit confuse with the result of num_rows that i used in my code. My table invoice have no value in current because i want to check if no value in the table. Here is my code code 1 gives $rowc value as 0 that is correct. $fetch1="select * from invoice"; $val1=$con->query($fetch1); $rowc=$val1->num_rows; echo $rowc; Code 2 gives $rowc value as 1 that is incorrect. $fetch1="select max(id) as id, order_no from invoice"; $val1=$con->query($fetch1); $rowc=$val1->num_rows; echo $rowc; I just want to know why the result giving two different values. Thanks
  14. File wont move to directory nor even upload to database here is my code , everything else uploads except the image <?php include('../connect.php'); if(isset($_POST['submit'])){ echo $post_title=mysqli_real_escape_string($connect,$_POST['title']); echo $post_date=date('m-d-y'); echo $post_price=mysqli_real_escape_string($connect,$_POST['price']); echo $post_keywords=mysqli_real_escape_string($connect,$_POST['keywords']); echo $post_content=mysqli_real_escape_string($connect,$_POST['content']); echo $post_image=mysqli_real_escape_string($connect,$_FILES['image']['name']); echo $image_tmp=mysqli_real_escape_string($connect,$_FILES['image']['tmp_name']); if($post_title=='' OR $post_price=='' OR $post_content=='' OR $post_keywords=='' OR $post_image=''){ echo "<script> alert('None of the post fields can be left blank')</script>"; }else{ //moves uploaded image into the image file move_uploaded_file($image_tmp,"../images/$post_image"); $insert_query="INSERT INTO posts (post_title,post_date,post_price,post_image,post_keywords,post_content) VALUES('$post_title','$post_date','$post_price','$post_image','$post_keywords','$post_content')"; if(mysqli_query($connect,$insert_query)){ echo "<script>alert('Succefully posted'); </script>"; } else "<h1> Did not work </h1>"; } if (is_uploaded_file($_FILES['image']['tmp_name'])) { echo "uploaded"; }else echo "could not upload"; var_dump(getcwd()); echo "<a href='logout.php'> Log out </a> <br/>"; echo "<a href='view_posts.php'> View Posts </a>"; ?> <?php } ; ?> here is the html <html> <head> <title> inserting new posts </title> <link rel="stylesheet" type="text/css" href="admin_style.css"> </head> <body> <div id="edit_postform"> <form method="post" action="insert_post.php" enctype="multipart/form-data"> <table width="600" align="centre" border"10"> <tr> <td> <h1> Insert New Post here </h1> </td> </tr> <tr> <td> Post title <td> <td> <input type="text" name="title" size="30"> </td> </tr> <tr> <td> Post Price<td> <td> <input type="text" name="price" size="30"> </td> </tr> <tr> <td> Post keywords<td> <td> <input type="text" name="keywords" size="30"> </td> </tr> <tr> <td> Post image <td> <td> <input type="file" name="image"> </td> </tr> <tr> <td> Post Content <td> <td> <textarea name="content" cols="20" rows="20" size="30"> </textarea> </td> </tr> <tr> <td> <input type="submit" name="submit" value="Publish now"> </td> </tr> </table> </form> </div> </body> </html>
  15. Hello, I am trying to load a txt file into mysql -uroot to create a database with all the tables and everything is prewritten. Here is what I thought I was supposed to write (but it's not working): mysql -uroot < skel_mysql.txt the skel_mysql.txt file is located in xampp/mysql/bin and this is a copy of the text in the file. CREATE DATABASE skel; USE skel; CREATE TABLE customers ( ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT, LAST CHAR(20) NOT NULL, FIRST CHAR(20) NOT NULL, PHONE CHAR(20) NOT NULL, SESSID CHAR(32) NOT NULL ); CREATE TABLE products ( SKU INT NOT NULL PRIMARY KEY, NAME CHAR(20) NOT NULL, DESCR VARCHAR(40) NOT NULL, PRICE DECIMAL(9,2) NOT NULL, IMAGE VARCHAR(20) NOT NULL ); INSERT INTO products VALUES(1121,'Small Lab Coat','White Lab Coat Adult Small',15.75,'labcoat.png'), (1122,'Medium Lab Coat','White Lab Coat Adult Medium',15.75,'labcoat.png'), (1123,'Large Lab Coat','White Lab Coat Adult Large',16.75,'labcoat.png'), (1124,'Beaker Kit','Set of 5 different beakers',22.05,'beakers.png'), (1125,'Petri Dishes','Set of three',9.99,'petri.png'), (1126,'Safety Glasses','Women's Safety Glasses',15.75,'wmglass.png'), (1127,'Mens Safety Glasses','Men's Safety Glasses',15.75,'mglass.png'), (1128,'Kids Safety Glasses','Kid's Safety Glasses',15.75, 'kglass.png'), ; CREATE TABLE cart ( ID CHAR(32) NOT NULL, DATE DATETIME NOT NULL, QTY INT NOT NULL, SKU INT NOT NULL ); Side note: I thought there was an error in my database so I dropped it and rewrote the code in a txt file and now I dont want to rewrite everything in the cmd prompt. This is for a simple shopping cart assignment Im doing for a PHP class.
  16. Hi, So I have an array var playlist = new Array(); And in it I have songs as so: playlist[0] = 'Avicii - Levels'; playlist[1] = 'Song'; playlist[2] = 'Song'; playlist[3] = 'Song'; playlist[4] = 'Song'; playlist[5] = 'Song'; playlist[6] = 'Song'; playlist[7] = 'Song'; playlist[8] = 'Song'; playlist[9] = 'Song'; playlist[10] = 'Song'; Now I'm not an expert at MySQL so I was wondering if there would be an easier way to do this with MySQL instead if adding playlist[number] = 'Song"; after every line. It would search the MySQL database for a column named songs and it would automatically put them into the array 'playlist'. Also code examples or a finished product would be VERY helpful! Thanks
  17. I am new to PHP and MySQL, but not to coding in general. I finally got brave and I am trying to move from a MS Access database to a server based MySQL database with a web enabled front end. The goal of the database is to be online aviation logbook with the ability to enter/retrieve data with my iPhone. My ultimate end state is to code my app for the phone. I have exported all of my Access data to a MySQL database on server. I've spent the last two weeks learning PHP and MySQL by writing small scripts and expanding as I learned. I finally reached a point where I was ready to write the code for entering all of the data for a flight and inserting into the database. I had mastered all of the sub-steps. I built a form for entering the data. The form querys the DB to populate some of the drop down menus. All of that works fine and the drop menus are populated with information from the DB. After I click on the "submit" button, the code throws an error. I eventually learned how to capture and display the error. I was getting the following: Access denied for user ''@'localhost' to database 'FltLogbook'. Initially, I thought that maybe there was some sort of data type mismatch (I wasn't displaying the error initially, just a phrase stating the add failed) and I ended up commenting out the INSERT query and trying to insert just one piece (column) of data. That didn't work. Then I finally stumbled on the method to display the error. After seeing the actual error statement, I thought that I was losing DB connectivity after pressing submit and executing the code or it may be a permission issue. If I place the "INSERT" code up in the portion of the code where the form is built, I can successfully add a record. So my username/password has the correct privileges since I can add a record using the code - just not where I want to do it. After googling, it looks like the code is passing a null value for user (and I assume password). I have no idea why, but suspect it has something to do with the "POST" process after the submit. Stumbling upon another function (connection_status), it passes a "0" for normal in both sections of the code. I am truly stumped and have been this way for three days now!! I have googled anonymous, the exact error phrase, etc. None of it has helped me bridge this impasse. I am sure, as in previous coding impasses, it will be quite obvious to someone. Thanks for any help, Heed <?php $conn = mysqli_connect("localhost", $_POST[user], $_POST[password], "FltLogbook"); if ($_POST[op] != "add") { //Form not shown, show it $display="<h1>Add Logbook Entry</h1>"; $CnxSt = connection_status(); $display .= "Connection Status: $CnxSt<br><br>"; $display .= " <form method=\"post\" action=\"$_SERVER[PHP_SELF]\"> <strong>Details:</strong> <table border=\"1\" width=\"520\"> <tr> <td><input type=\"checkbox\" name=\"Sim\">Simulator</td> <td colspan=\"2\">SimType: <select name=\"SimType\"> <option value=\"\"> NA </option> <option value=\"Miltary Visual\"> Military Visual </option> <option value=\"Military Non-Visual\"> Military Non-Visual </option> <option value=\"ATD\"> ATD </option> <option value=\"FTD\"> FTD </option> <option value=\"FFS\"> FFS </option></select></td> </tr> <tr> <td>Date: <input type=\"date\" name=\"FltDate\"></td> <td>Aircraft: <select name=\"Aircraft\"> <option selected=\"selected\" value=\"26\">C-172M</option>"; $AcftQuery="SELECT Aircraft.AirKey,Aircraft.Aircraft, Aircraft.ME, Aircraft.Complex, Aircraft.HighPerf FROM Aircraft"; $AcftResult=mysqli_query($conn, $AcftQuery) or die ("Aircraft Query Failed"); While ($AcftRow=mysqli_fetch_array($AcftResult)) { $AcftKey=$AcftRow['AirKey']; $AcftAircraft=$AcftRow['Aircraft']; $AcftME=$AcftRow['ME']; $AcftComplex=$AcftRow['Complex']; $AcftHP=$AcftRow['HighPerf']; $display .= "<option value=\"$AcftKey\"> $AcftAircraft </option>"; } $display .= " </select> </td> <td>Aircraft ID: <input type=\"text\" name=\"ID\" size=\"8\"></td> </tr> <tr> <td>From: <select name=\"From\"> <option selected=\"selected\" value=\"PVG\">PVG</option>"; $ArfldQuery="SELECT AirfieldID FROM Airfields ORDER BY AirfieldID"; $ArfldResult=mysqli_query($conn, $ArfldQuery) or die ("Airfield Query Failed"); While ($ArfldRow=mysqli_fetch_array($ArfldResult)) { $Arfld=$ArfldRow['AirfieldID']; $display .= "<option value=\"$Arfld\"> $Arfld </option>"; } $display .= " </select> </td> <td>To: <select name=\"To\"> <option selected=\"selected\" value=\"PVG\">PVG</option>"; $ArfldQuery="SELECT AirfieldID FROM Airfields ORDER BY AirfieldID"; $ArfldResult=mysqli_query($conn, $ArfldQuery) or die ("Airfield Query Failed"); While ($ArfldRow=mysqli_fetch_array($ArfldResult)) { $Arfld=$ArfldRow['AirfieldID']; $display .= "<option value=\"$Arfld\"> $Arfld </option>"; } $display .= " </select> </td> <td>Leg: <select name=\"Leg\"> <option value=\"1\">1</option> <option value=\"2\">2</option> <option value=\"3\">3</option> <option value=\"4\">4</option> <option value=\"5\">5</option> <option value=\"6\">6</option> </select> </td> </tr> </table><br> <strong>Flight Time Info:</strong> <table border=\"1\" width=\"520\"> <tr> <td>TPT: <input type=\"text\" name=\"TPT\" size=\"4\"></td> <td>PIC: <input type=\"text\" name=\"PIC\" size=\"4\"></td> <td>SIC: <input type=\"text\" name=\"SIC\" value=\"0.0\" size=\"4\"></td> </tr> <tr> <td>Solo: <input type=\"text\" name=\"Solo\" value=\"0.0\" size=\"4\"></td> <td colspan=\"2\">Dual Received: <input type=\"text\" name=\"Dual\" value=\"0.0\" size=\"4\"></td> </tr> <tr> <td>Cross Country: <input type=\"text\" name=\"XC\" value=\"0.0\" size=\"4\"></td> <td><input type=\"checkbox\" name=\"FARXCntry\" size=\"4\">FAR X-Cntry</td> <td><input type=\"checkbox\" name=\"ATPXCntry\" size=\"4\">ATP X-Cntry</td> </tr> <tr> <td>Single Engine: <input type=\"text\" name=\"SE\" size=\"4\"></td> <td>Multiengine: <input type=\"text\" name=\"ME\" size=\"4\"></td> <td>Night: <input type=\"text\" name=\"NT\" value=\"0.0\" size=\"4\"></td> </tr> <tr> <td>Complex: <input type=\"text\" name=\"Complex\" value=\"0.0\" size=\"4\"></td> <td colspan=\"2\">High Performance: <input type=\"text\" name=\"HP\" value=\"0.0\" size=\"4\"></td> </tr> <tr> <td>Instrument: <input type=\"text\" name=\"Inst\" value=\"0.0\" size=\"4\"></td> <td colspan=\"2\">Sim Instrument: <input type=\"text\" name=\"SimInst\" value=\"0.0\" size=\"4\"></td> </tr> <tr> <td>Instructor: <input type=\"text\" name=\"Instructor\" value=\"0.0\" size=\"4\"></td> <td>Pre-Post: <input type=\"text\" name=\"PrePost\" value=\"0.0\" size=\"4\"></td> <td>Ground: <input type=\"text\" name=\"Ground\" value=\"0.0\" size=\"4\"></td> </tr> </table><br> <strong>Actual Approaches:</strong> <table border=\"1\" width=\"520\"> <tr> <td>Precision: <input type=\"text\" name=\"PrecAct\" value=\"0\" size=\"3\"></td> <td>Non-Precision: <input type=\"text\" name=\"NonPrecAct\" value=\"0\" size=\"3\"></td> </tr> </table><br> <strong>Simulated Approaches:</strong> <table border=\"1\" width=\"520\"> <tr> <td>Precision: <input type=\"text\" name=\"PrecSim\" value=\"0\" size=\"3\"></td> <td>Non-Precision: <input type=\"text\" name=\"NonPrecSim\" value=\"0\" size=\"3\"></td> </tr> </table><br> <strong>Landings:</strong> <table border=\"1\" width=\"520\"> <tr> <td>Day Landings: <input type=\"text\" name=\"DayLdg\" size=\"3\"></td> <td>Night Landings: <input type=\"text\" name=\"NtLdg\" size=\"3\"></td> </tr> </table><br> <strong>Remarks:</strong><br> <textarea name=\"Remarks\" rows=\"5\" cols=\"70\"></textarea> <input type=\"hidden\" name=\"op\" value=\"add\"> <p><input type=\"submit\" name=\"submit\" value=\"Add Entry\"></p> </FORM>"; } else if ($_POST[op] == "add") { if ($_POST[Sim] == "") { $_POST[Sim] = "0"; } else { $_POST[Sim] = "1"; } if ($_POST[FARXCntry] == "") { $_POST[FARXCntry] = "0"; } else { $_POST[FARXCntry] = "1"; } if ($_POST[ATPXCntry] == "") { $_POST[ATPXCntry] = "0"; } else { $_POST[ATPXCntry] = "1"; } // $add_flt = "INSERT INTO FlightData (Date, MakeModel, AircraftID, Simulator, SimType, AfldFrom, AfldTo, // Leg, TPT, PIC, SIC, Solo, Dual, Night, XCntry, SE, ME, Complex, HighPerf, Inst_Act, Inst_Sim, // Instructor, PrePost, Ground, Prec_Act, Prec_Sim, NonPrec_Act, NonPrec_Sim, DCL, NCL, // FAR_XCntry, ATP_XCntry, Remarks) // VALUES ('$_POST[FltDate]', '$_POST[Aircraft]', '$_POST[ID],$_POST[Sim]', '$_POST[SimType]', '$_POST[From]', // '$_POST[To]', '$_POST[Leg]', '$_POST[TPT]', '$_POST[PIC]', '$_POST[SIC]', '$_POST[Solo]', '$_POST[Dual]', // '$_POST[NT]', '$_POST[XC]', '$_POST[SE]', '$_POST[ME]', '$_POST[Complex]', '$_POST[HP]', '$_POST[Inst]', // '$_POST[SimInst]', '$_POST[Instructor]', '$_POST[PrePost]', '$_POST[Ground]', '$_POST[PrecAct]', // '$_POST[PrecSim]', '$_POST[NonPrecAct]', '$_POST[NonPreSim]', '$_POST[DayLdg]', '$_POST[NtLdg]', // '$_POST[FARXCntry]', '$_POST[ATPXCntry]', '$_POST[Remarks]')"; $add_flt = "INSERT INTO FlightData (Date, MakeModel) VALUES ('$_POST[FltDate]', '$_POST[Aircraft]')"; $result = mysqli_query($conn, $add_flt) or die('Error: '. mysqli_connect_error()); $display = "<h1>Entry Added</h1> <p>Your entry was added.</p><br> <p>$_POST[FltDate] | $Make </p>"; // $CnxSt = connection_status(); // $display .= "Connection Status: $CnxSt<br><br>"; // $display .= "$_POST[FltDate] / $_POST[Aircraft] / $_POST[ID] / $_POST[Sim] / $_POST[FARXCntry] / $_POST[ATPXCntry]"; } ?> <html> <head> <title>Add Logbook Entry></title> </head> <body> <?php echo $display; ?> </body> </html>
  18. i am getting this error Notice: Undefined index: image . i am trying to upload an image to databse . I cannot figure out whats going on , everything else uploads except the image, not even the image name is uploaded to database below is code the size of the file is only 3kb. the echo $max_upload = (int)(ini_get('upload_max_filesize')); echo "<pre>" . print_r($_POST, true) . "</pre>"; echo "<pre>". var_dump($_FILES['image']) . "</pre>"; the print_r displays as Array ( [title] => This is a post [author] => Me [keywords] => posting [image] => url.jpg [content] => this is a new post [submit] => Publish now ) displays as NULL the vardump below is actual code. <html> <head> <title> inserting new posts </title> </head> <body> <form method="post" action="insert_post.php" enctype="multipart/form-data/"> <table width="600" align="centre" border"10"> <tr> <td> <h1> Insert New Post here </h1> </td> </tr> <tr> <td> Post title <td> <td> <input type="text" name="title" size="30"> </td> </tr> <tr> <td> Post Author<td> <td> <input type="text" name="author" size="30"> </td> </tr> <tr> <td> Post keywords<td> <td> <input type="text" name="keywords" size="30"> </td> </tr> <tr> <td> Post image <td> <td> <input type="file" name="image"> </td> </tr> <tr> <td> Post Content <td> <td> <textarea name="content" cols="20" rows="20" size="30"> </textarea> </td> </tr> <tr> <td> Post title <td> <td> <input type="text" name="title" size="30"> </td> </tr> <tr> <td> <input type="submit" name="submit" value="Publish now"> </td> </tr> </table> </form> </body> </html> <?php include('../includes/connect.php'); if(isset($_POST['submit'])){ echo $post_title=$_POST['title']; echo $post_date=date('d-m-y'); echo $post_author=$_POST['author']; echo $post_keywords=$_POST['keywords']; echo $post_content=$_POST['content']; echo $post_image=$_FILES['image']['name']; echo $image_tmp=$_FILES['image']['tmp_name']; if($post_title=='' or $post_keywords=='' or $post_content=='' or $post_author==''){ echo "<script> alert('none of the fields can be empty')</script>"; exit(); } else{ move_uploaded_file($image_tmp,"../images/$post_image"); //query is below to insert data $insert_query="INSERT into posts (post_title,post_date,post_author,post_image,post_keywords,post_content) VALUES('$post_title','$post_date','$post_author','$post_image','$post_keywords','$post_content')"; if(mysqli_query($connect,$insert_query)){ echo " <h1> successfully Posted </h1> "; } else " h1> Did not work </h1>"; } } echo $max_upload = (int)(ini_get('upload_max_filesize')); echo "<pre>" . print_r($_POST, true) . "</pre>"; echo "<pre>". var_dump($_FILES['image']) . "</pre>"; ?> thanks in advance guys.
  19. Hi, I'd get to do a join query with 3 (sometimes 2). Here is the structure of my 3 tables in question: items> id, cat, subcategory, created status> itemId, level Modify> id, itemId, date, type Here's my query so far: SELECT i.id, i.userId FROM items i LEFT OUTER JOIN statut s ON i.id = s.itemId WHERE CASE WHEN ( SELECT m.date FROM modification m WHERE m.itemId = i.id ORDER BY m.date DESC LIMIT 1 ) IS NULL THEN i.created END > DATE_SUB(NOW(), INTERVAL 90 DAY) AND s. LEVEL = 1 I would like to get a look at what the last change add and see if it has been over 90 days. In case no change was made compared with the creation date of the item. He that can strongly that there are several changes to a single item so it should really checked with the last added in case there. Thank you for your help!
  20. Hello everyone! I am here to ask for some help with a certain script I have concocted. I run a moderately sized gaming community (using vBulletin 4.2.2) that supports multiple games, and as such we needed an automated roster to keep track of who plays what games. The code displays a list of games on the left, and the actual roster to the right. The default page is a "leadership roster" listing all the leaders. Game Roster pages include several things. Username, User Rank, IGN/Game Account Name, Join Date, and Last Active Date. You can sort by Join and Last Active Dates. There are also two types of members on the roster. Those who play the game as their "main game" and those who play it occasionally as an "other game". It is easy to get the main game members, since you can only have one, vBulletin saves it as text, so you can match it. The other games selector is saved bitwise, so we have to run a check for the game's location in the list against the user's saved bitwise in their profile to see if they play it. To do this, instead of manually coding the bit number, since everything is alphabetical, we simply assign each game a number, and do a a bitshift (1<<x) to get the proper bit (I've been told bitshift is much faster than using pow(2,x)). However, because it's specific too us, I have hard coded a lot of stuff, including mixing presentation code with functional code. The code works just fine for us, but I want to make it much easier so that other staff members besides me can update it easily and so the code is easier to manage. I hope I have given a good explanation of what the code does! To see the code in action, click http://www.zealotgaming.com/forum/pages.php?pageid=15 To see the code with syntax highlighted, here is the pastebin: http://pastebin.com/Nuanj4Ci I thank you all in advance for any help and advice you can give me. I am a novice and have been learning as I go to do this for my community.
  21. Here is my button $( "#editVehicle" ).button().click(function( event ) { event.preventDefault(); var vp = $("input[name=vehicle_plate]").val(), dataString = 'vehicle_plate='+ vp; $.ajax({ type: "POST", url: "editvehicle.php", data: dataString, dataType: "json", success: function(data){ if(!data.error && data.success) { $("input[name=vehicle_model]").val(data.vehicleName); $("input[name=assigned_driver]").val(data.assignedDriver); } else { alert(data.errorMsg); } } }); }); And here is my PHP <?PHP include("db.classes.php"); $g = new DB(); $g->connection(); if($_POST) { $vehiclePlate = $g->clean($_POST["vehicle_plate"],1); $g->edit($vehiclePlate); } $g->close(); ?> and here is my db.classes public function edit($vehiclePlate) { $sql = "select vehicle_name, driver_id from vehicles where vehicle_plate='$vehiclePlate'"; $result = mysql_query($sql) or die(json_encode(array("error" => 0, "errorMsg" => "MySQL query failed."))); $row = mysql_fetch_array($result); if(mysql_num_rows($row)) { echo json_encode(array( "success" => 1, "vehicleName" => $row['vehicle_name'], "assignedDriver" => $row['driver_id'] )); } else { echo json_encode(array( "error" => 1, "errorMsg" => "No rows returned" )); } } There is an input field in my html where i input the vehicle plate then when the user clicks the button the program searches the database for the vehicle name and driver_id with the plate the user entered and returns the value to another inputfield named "vehicle_name" and "assigned_driver" but nothing is happening when the button is clicked not even the error alert message. Any idea on where am i going wrong here?
  22. Hi I need some help with this code. I have been trying to execute this query by clicking on the search button. The query should select a the data on the web page but only the for the id entered. but I can't seem to make to button execute the query. Can somebody help me? <table border="1" align="center" cellpadding="2" cellspacing="0"> <tr> <td colspan="4"> <div align="center"> <input type="button" name="Student ID" value="Search ID" onclick="f()" /> <input type="text" name="StudentID"> <?php function f(){ $StudentID=$_POST['StudentID']; // Connect to the database $dbLink = new mysqli('', '', '', ''); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } // Query for a list of all existing files $sql = 'SELECT `MeetingRef`, `StudentID`, `Created`, `Progress`,`Problems` FROM `Meeting` WHERE StudentID StudentID'; $result = $dbLink->query($sql); // Check if it was successfull if($result) { // Make sure there are some files in there if($result->num_rows == 0) { echo '<p>There are no dat saved for this student in the database</p>'; } else { // Print the top of a table echo '<table width="100px"> <tr> <td align ="center"><b>Meeting Ref</td> <td align ="center"><b>Student ID</td> <td align ="center"><b>Created</b></td> <td align ="center"><b>Progress</b></td> <td align ="center"><b>Problems</b></td> </tr>'; // Print each file while($row = $result->fetch_assoc()) { echo " <tr> <td>{$row['MeetingRef']}</td> <td>{$row['StudentID']}</td> <td>{$row['Created']}</td> <td>{$row['Progress']}</td> <td>{$row['Problems']}</td> </tr>"; } // Close table echo '</table>'; } // Free the result $result->free(); } else { echo 'Error! SQL query failed:'; echo "<pre>{$dbLink->error}</pre>"; } // Close the mysql connection $dbLink->close(); } ?> </div></td> </tr> </table>
  23. Hello All, I have a form that has a DropDown list that is called from an SQL statement; in the SQL table it has a "name" and "email", what I want is the form to grab the "email" as a variable from a "onChange" event so when my form is posted it carries the "email" as a variable that I can use in a function. I can add the email as a hidden <input> however since I don't know how to create an onChange event to grab the "email" from the SQL instance when the drop down is selected I can't pass the email as a variable when the form is posted. I suppose this either needs to be done in Ajax or using JQuery however I'm not sure what is the best approach or way to do it. Does anyone have any spare time to educate me on this, I've never written Ajax or JQuery code before, trying to do this in php alone does not seem like a solution. Thank you in advance
  24. The current infinite scroll script I have works great by it self. The masonry script I have works as well by itself. However when I combine them both, they won't work. I am wondering if there is an infinite scroll script that would work with Masonry?
  25. What would be the best way do implement this situation in php and mySQL: I want users to be able to rate and review restaurants. This would mean that their ratings and reviews have to be inserted into the databse. This wouldn't be a problem. My question is, what is the most efficient and SEO friendliest way to show the ratings and reviews per restaurant. Should I make a script that generate a page for each restaurant? Or should I have one page which gets the data from the database for each company (would that be SEO friendly).
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.