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. Hello, I am looking for a php script to import a .Sql file that is in a specific url (like: http://www.dropbox.com/s/xxxx/file.sql) to MySql DB. Thanks
  2. Im using excelwriter.inc.php library to write data in XLS. I have a system where I select column names like "id" , "name", "description" etc. This columns can be chosen from list. The column count can vary from choosing 1 or 2 or 40 columns to appear in XLS. As I chose more columns to appear in XLS. The data is not shown in proper format. Some data goes missing in between or with large number of chosen column the count is reduced to 8000-9000 rows. Suppose if column count is around at max 2 . Suppose id , name , the total rows would be perfectly shown having 10k records. But as I increase the column say adding a description . The row count would reduce to suppose 8-9k. Now If I keep increasing more column than The record count keep on decreasing and also some columns data goes missing. There is some problem with the excelwriter library to write data in XLS. LOGIC : One sheet will have maximum 10k rows. If count exceeds 10k . It will generate a new sheet. excelwriter.inc.php
  3. Hi all, I have a form that submits data to a mysql db. It's working fine. What I am trying to do is output an html page (or possibly 2) that is propagated with the data that I just sent to the db. example: when I submit a new workorder, a page comes up with all the data i just submitted. so that can be printed as a "customer copy". and in a perfect world, another page comes up that is a material order form. That can be faxed to my vendor to order the materials for that job. Not looking to auto print or fax anything. I am just having trouble getting the data into my html page. Here is what I have, but sadly is not working. <?php $link = mysqli_connect("xxxx", "xxxx", "xxxx", "xxxx"); $sql = "SELECT customer FROM jobs WHERE id=6487"; echo $sql; mysqli_close($link); ?> I would like to use the data from the last id submitted and have tried several things like: WHERE id=mysqli::$insert_id and WHERE id=$insert_id with no luck. Here is a pic of the html form and the output i'm getting. Any help would be greatly appreciated. Thanks in advance. OGBugsy
  4. http://stackoverflow.com/questions/29881417/how-to-search-punjabi-regional-language-keyword-in-mysql i am getting different result when running query using PHPMyAdmin and using PHP script. It is our regional language Punjabi keyword ਹਰਪ੍ਰੀਤ ਕੌਰ ਪਟਿਆਲਾ I am executing below MySql query using PHPMyAdmin select * from postinfo where match(info) against('ਹਰਪ੍ਰੀਤ ਕੌਰ ਪਟਿਆਲਾ') Giving me accurate result. But when running same Query using PHP form Search **Code:** $name=trim($_POST['name']); $sql="select * from postinfo where match(info) against('$name') LIMIT 10"; $result=mysql_query($sql); Then the result is blank. Image getting result using mysql query in PHPMyAdmin http://i.stack.imgur.com/SX20C.png
  5. I looked at a tutorial on youtube to make a blog. I need to be connected after logging in my admin login with the admin panel. What is my mistake here? Thank you very much! index.php <?php include_once "../blog/connect.php"; include_once "../blog/functie.php"; ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"/> <title>Dashboard I Admin Panel</title> <link rel="stylesheet" href="css/layout.css" type="text/css" media="screen" /> <!--[if lt IE 9]> <link rel="stylesheet" href="css/ie.css" type="text/css" media="screen" /> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <script src="js/jquery-1.5.2.min.js" type="text/javascript"></script> <script src="js/hideshow.js" type="text/javascript"></script> <script src="js/jquery.tablesorter.min.js" type="text/javascript"></script> <script type="text/javascript" src="js/jquery.equalHeight.js"></script> <script type="text/javascript"> $(document).ready(function() { $(".tablesorter").tablesorter(); } ); $(document).ready(function() { //When page loads... $(".tab_content").hide(); //Hide all content $("ul.tabs li:first").addClass("active").show(); //Activate first tab $(".tab_content:first").show(); //Show first tab content //On Click Event $("ul.tabs li").click(function() { $("ul.tabs li").removeClass("active"); //Remove any "active" class $(this).addClass("active"); //Add "active" class to selected tab $(".tab_content").hide(); //Hide all tab content var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content $(activeTab).fadeIn(); //Fade in the active ID content return false; }); }); </script> <script type="text/javascript"> $(function(){ $('.column').equalHeight(); }); </script> </head> <body> <?php if(session("login") && session("uye_rutbe") == 1){ require_once "inc/default.php"; }else{ } if ($_POST){ $kadi= p("kadi"); $sifre = md5(p("sifre")); if (!$kadi || !$sifre){ echo "kullanıcı adı sifre bos bırakılamaz"; } else{ $row = $connect->query("SELECT * FROM uyeler WHERE uye_kadi = '$kadi' && uye_sifre = '$sifre'"); $row = $connect->fetch(PDO::FETCH_ASSOC); if ( $row["uye_id"]) { $session = array( "giris_yap" => true, "uye_id" => $row["uye_id"], "uye_kadi" => $row["uye_kadi"], "uye_rutbe" => $row["uye_rutbe"] ); session_olustur($session); header("Refresh:0;"); } else { echo "<font color='red'>Böyle Bir Yönetici Yoktur.</font>"; } } } ?> <div id="giris_yap"> <form action="" method="post"> <table cellpadding="0" cellspacing="0"> <tr> <td>Gebruikersnaam:</td> <td><input type="text" name="kadi" /></td> </tr> <tr> <td>Wachtwoord:</td> <td><input type="password" name="sifre" /></td> </tr> <tr> <td></td> <td><button type="submit">Inloggen</button></td> </tr> </table> </form> </div> </body> </html> function.php <?php function p($par, $st =false){ if($st){ return htmlspecialchars(trim($_POST[$par])); }else{ return trim( $_POST[$par]); } } function g($par){ return strip_tag(trim($_GET[$par])); } function kisalt($par,$uzunluk = 50){ if(strlen($par) > $uzunluk){ $par=mb_substr($par,0,$uzunluk,"UTF-8").". ."; } return $par; } function go($par, $time = 0){ if($time == 0){ header("Location: {$par}"); }else{ header("Refresh: {$time}; url={$par}"); } } function session($par){ if ($_SESSION[$par]){ return $_SESSION[$par]; }else{ return false; } } function session_olustur($par){ foreach ($par as $anahtar => $deger){ $_SESSION[$anahtar]=$deger; } } function sef_link($url){ $url = trim($url); $url = strtolower($url); $find = array('<b>', '</b>'); $url = str_replace ($find, '', $url); $url = preg_replace('/<(\/{0,1})img(.*?)(\/{0,1})\>/', 'image', $url); $find = array(' ', '"', '&', '&', '\r\n', '\n', '/', '\\', '+', '<', '>'); $url = str_replace ($find, '-', $url); $find = array('é', 'è', 'ë', 'ê', 'É', 'È', 'Ë', 'Ê'); $url = str_replace ($find, 'e', $url); $find = array('í', 'ì', 'î', 'ï', 'I', 'Ã', 'ÃŒ', 'Ã', 'Ã', 'Ä°', 'ı'); $url = str_replace ($find, 'i', $url); $find = array('ó', 'ö', 'Ö', 'ò', 'ô', 'Ó', 'Ã’', 'Ô'); $url = str_replace ($find, 'o', $url); $find = array('á', 'ä', 'â', 'à ', 'â', 'Ä', 'Â', 'Ã', 'À', 'Â'); $url = str_replace ($find, 'a', $url); $find = array('ú', 'ü', 'Ãœ', 'ù', 'û', 'Ú', 'Ù', 'Û'); $url = str_replace ($find, 'u', $url); $find = array('ç', 'Ç'); $url = str_replace ($find, 'c', $url); $find = array('Å', 'ÅŸ'); $url = str_replace ($find, 's', $url); $find = array('Ä', 'ÄŸ'); $url = str_replace ($find, 'g', $url); $find = array('/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/'); $repl = array('', '-', ''); $url = preg_replace ($find, $repl, $url); $url = str_replace ('--', '-', $url); return $url; } function query($query){ return mysql_query($query); } function row($query){ return mysql_fetch_array($query); } function rows($query){ return mysql_num_rows($query); } { } ?> Connect.php <?php session_start(); $host = "localhost"; $database = "blog"; $user = "root"; $password = ""; try { $connect = new PDO("mysql:localhost={$host};dbname={$database}", $user, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); $connect->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING ); } catch (PDOException $e) { return 'Hay Allah!, Connection Error: '. $e->getMessage(); } ?>
  6. Hello everyone, I have joined this forum just now hoping to find some help for my problem. I have a mysql query in my php file which i output to an array of html divs. The code is as follows: $result = mysql_query("SELECT * FROM numserved WHERE status = 'on'") or die(mysql_error()); while($row = mysql_fetch_array($result)) { ?> <div style="font-size:<?php echo $fontsize; ?>pt;" valign="middle" class="numberz" align="center" > <?php echo $row['number']; ?></div><?php } ?> I wanted to know if anyone could help me write the code to make this query be updated every 3 seconds without reloading the whole page. I know it is done by Ajax and tried to implement the Jquery solution , but I wasnt able to apply it. Anyone would be so kind to tell me the exact code i need and where to place it? Thank you
  7. I am trying to coonect my jquery price slider to my database in order to search for recipes depending on the price. I have written the code below but I am not sure were i am going wrong. Could anyone help? <!--Javascript code for jquery price range slider--> <script type="text/javascript"> $(function() { $( "#slider-range" ).slider({ range: true, min: 0, max: 10, values: [ <?php echo $min?>,<?php echo $max?> ], // This line could be the issue? slide: function( event, ui ) { $( "#amount" ).val( "£" + ui.values[ 0 ] + " - £" + ui.values[ 1 ] ); } }); $( "#amount" ).val( "£" + $( "#slider-range" ).slider( "values", 0 ) + " - £" + $( "#slider-range" ).slider( "values", 1 ) ); }); </script> <!--php code to connect to jquery price slider--> <?php require_once './config.php'; include './header.php'; include('database.php'); if($_POST && isset($_POST['amount'])){ $values = $_POST['amount']; $values = str_replace(array(' ', '£'), '', $_POST['amount']); list($min, $max) = explode('-', $values); $sql = "SELECT `recipe_name`, `recipe_price`, `Image` FROM `recipe` WHERE `recipe_price` BETWEEN :min AND :max"; $stmt = $DB->prepare($sql); $stmt->execute(array(':min' => $min, ':max' => $max)); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); if (count($rows) > 0) { foreach ($rows as $row) { // do loop stuff } } else { $min = 0; $max = 10; $HTML = ''; } } ?> <!--HTML code for price slider --> <form action="" method="post" id="recipe"> <div style="margin-left:20px"> <label for="amount">Price range:</label> <input type="text" id="amount" name="amount" style="border:0; color:#f6931f; font-weight:bold;" readonly> <br><br> <div id="slider-range" style="width:50%;"></div> <br><br> <input type="submit" value="Find" /> <br><br> <?php echo $HTML?> </div> </form> <!-- connnect to Database - PDO connection--> <?php error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE); ob_start(); define('DB_DRIVER', 'mysql'); define('DB_SERVER', 'localhost'); define('DB_SERVER_USERNAME', 'xxxxx'); define('DB_SERVER_PASSWORD', 'xxxx'); define('DB_DATABASE', 'xxxxx'); define('PROJECT_NAME', 'BudGet Recipes'); $dboptions = array( PDO::ATTR_PERSISTENT => FALSE, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', ); try { $DB = new PDO(DB_DRIVER . ':host=' . DB_SERVER . ';dbname=' . DB_DATABASE, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, $dboptions); } catch (Exception $ex) { echo $ex->getMessage(); die; } ?>
  8. Hello everyone! I'm having issues with a delete button on a table row, im getting this error: Catchable fatal error: Object of class mysqli could not be converted to string in C:\xampp\htdocs\consultas\newdatapull.php on line 19 I'm not sure whats going on, here's my code: <?php include('header.php'); $servername = "localhost"; $username = "un"; $password = "admin"; $dbname = "emelyconsultas"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); }; if (isset($_POST['delete'])) { $deleteQuery = "DELETE FROM hoteles WHERE id='$_POST[delete]'"; mysqli_query("$conn, $deleteQuery, "); }; $sql = "SELECT id, Full_Name, Email_Address, Telephone_Number, pais, ciudad, nombre_hotel, fecha_in, Fecha_out, adultos, ninos, mensaje FROM hoteles"; $result = $conn->query($sql); if ($result->num_rows > 0) { echo "<div class='container-fluid'> <div class='col-md-12'> <div id='datatable'class='table-responsive well'> <h1 class='text-center'>Entradas</h1> <table id='table' class='table'> <tr> <th>ID</th> <th>Nombre</th> <th>Correo Electronico</th> <th>Numero Telefonico</th> <th>Pais Destinado</th> <th>Ciudad Destinada</th> <th>Hotel</th> <th>Check In</th> <th>Check Out</th> <th>Adultos</th> <th>Niños</th> <th>Mensaje</th> </tr>"; // output data of each row while($row = $result->fetch_assoc()) { echo "<form action=newdatapull.php method=post>"; echo "<tr>"; echo "<td>" .$row['id'] . " </td>"; echo "<td>" .$row['Full_Name'] . " </td>"; echo "<td>" .$row['Email_Address'] . " </td>"; echo "<td>" .$row['Telephone_Number'] . " </td>"; echo "<td>" .$row['pais'] . " </td>"; echo "<td>" .$row['ciudad'] . " </td>"; echo "<td>" .$row['nombre_hotel'] . " </td>"; echo "<td>" .$row['fecha_in'] . " </td>"; echo "<td>" .$row['Fecha_out'] . " </td>"; echo "<td>" .$row['adultos'] . " </td>"; echo "<td>" .$row['ninos'] . " </td>"; echo "<td>" .$row['mensaje'] . " </td>"; echo "<td>" .$row['id'] . " </td>"; echo "<td>" ."<input class=input-group type=submit name=delete value=Borrar>" . "</td>"; "</form>"; echo "</tr></table></div></div></div>"; } } else { echo "0 results"; } $conn->close(); include('footer.php'); ?> thanks in advance to anyone that can help, Error comes up once I click the Delete button on the row...
  9. Hi all, For example, many vendor websites allow users to refine a search e.g. Lowest Price First. I need some help to implement this into my website. I have tired to do this using a submit button but it just refreshes the page, and the data that the user has used to search for the produce in the first place.
  10. Hi there, I'm learning PHP and working on building an ecommerce site using a MVC. I can display all six categories from the database on the index page however I only want to show four of these, as the links at the top will be the six categories. By using the next() method I can display all six categories: <?php while ($categories->next()) { ?> <section class="product"> <a href="products/<?= $categories->getURL() ?>"><h3 class="upper"><?= $categories->getName() ?></h3></a> <br/> <img src="<?= IMAGE_URL . $categories->getImage() ?>" style="width:80%; height:auto;" alt="Menu Tab"/> <h3 class="under"><a href="products/<?= $categories->getURL() ?>">SHOP NOW >></a></h3> </section> <?php } } } ?> I am wondering how to only extract certain products (each has a catID in the database). I thought the switch statement might be the answer and here was my attempt that did not work. I guess I am still not saying which catID to get but unsure how to fix this. Or is there another way not using switch? while ($categories->next()) { switch ($categories->getID()) { case 1: case 2: case 3: case 4: ?> <section class="product"> <a href="products/<?= $categories->getURL()?>"><h3 class="upper"><?=$categories->getName() ?></h3></a> <br/> <img src="<?=IMAGE_URL. $categories->getImage()?>" style="width:80%; height:auto;" alt="Menu Tab"/> <h3 class="under"><a href="products/<?= $categories->getURL()?>">SHOP NOW >></a></h3> </section> <?php break; default: return ""; } } } } ?> Any help would be greatly appreciated! Cheers
  11. Hello guys. I have a problem with signup form record in database. My code works good but only firstname input doesnt send it to database. Other all information shown up in database. Do you have any idea why it is not working? <?php // index.php session_start(); require_once 'functions.php'; $userfirstname = $lastname = $email = $remember = $error = $username = $pass = $password1 = $password2 = $user = $birthday = $bdd = $bdm = $bdy = ""; $imgavatar = 'img/default_user_avatar.png'; $userstr = '(Guest)'; if (isset($_SESSION['user'])) { $user = $_SESSION['user']; $loggedin = TRUE; $userstr = " ($user)"; } else $loggedin = FALSE; if ($loggedin){ //redirect for profile page } if(isset($_POST['username'])&&($_POST['first']) && ($_POST['lastname']) && ($_POST['email'])){ $username = sanitizeString($_POST['username']); $password1 = sanitizeString($_POST['p']); $password2 = sanitizeString($_POST['p2']); $email = sanitizeString($_POST['email']); $userfirstname = sanitizeString($_POST['first']); $lastname = sanitizeString($_POST['lastname']); $bdd = sanitizeString($_POST['day']); $bdm = sanitizeString($_POST['month']); $bdy = sanitizeString($_POST['year']); $birthday = $bdd." / ".$bdm." / ".$bdy; if ( ($username == "") || ($email =="") || ($password1 =="") || ($password2 =="") || ($userfirstname = "") || ($lastname == "")) { $error = "You didn't give us enough information for Signup"; } else { $result = queryMySQL("SELECT * FROM Members WHERE username='$username'"); if($result->num_rows) { $error ="This Username is already exists"; } else { queryMysql("INSERT INTO Members VALUES( '$userfirstname','$lastname','$email','$username','$password1','$birthday')"); die("<h4>Account created</h4>Please Log in. Your first name is $userfirstname<br><br>"); } } } echo <<<_END <DOCTYPE html> <html> <head> <title>World. Your New World</title> <link rel='stylesheet' href='styles.css' type='text/css'> <script type="text/javascript" src="javascript/javascript.js"></script> </head> <body class='home'> <div class='loginform'> <img id='imgavatar' src='$imgavatar'> <form method='post' action='index.php'> <input class = 'loginput' type='text' maxlength='16' name='user' value='$user' placeholder='Username'> <input class = 'loginput' type='password' maxlength='16' name='pass' value='$pass' placeholder='Password'> <h6 id='rememberme'><input type="checkbox" value="None" name="check" checked='checked' />Remember Me</h6> <span>$error<br></span> <input type='submit' value='Login'> </form> </div> <div class='signupform'> <h1 id='signhead'>Join Us!</h1> <p id='signhead'>It will be free and it will always be free!<br> Creat your own personal tree</p><br><br><br> <form method='POST' action='index.php'> <input class= 'loginput' type='text' maxlength='16' name='first' value='$userfirstname' placeholder='Name'> <input class= 'loginput' type='text' maxlength='16' name='lastname' value='$lastname' placeholder='Last Name'><br> <input class= 'loginput' type='email' maxlength='32'name='email' value='$email' placeholder='E-mail'> <input class= 'loginput' type='text' maxlength='16' name='username' value='$username' placeholder='Username' onBlur='checkUser(this)'><br> <input class= 'loginput' type='Password' maxlength='16' name='p' value='$password1' placeholder='Password'> <input class= 'loginput' type='Password' maxlength='16' name='p2' value='$password2' placeholder='Repeat Password'><br> <select name="month" onchange="call()" value='$bdm'> <option value="0">-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">Jun</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> <select name="day" value='$bdd'> <option value="">-Day-</option> </select> <select name="year" onchange="call()" value='$bdy'> <option value="">-Year-</option> </select> $userfirstname $lastname <input type='submit' value='Sign Up'> </form> </div> </body> </html> _END; ?>
  12. I'm trying to get a users email so it will update them when they purchased premium, I'm using Stripe as my payment system. The only way I can get it to work, is if I insert their email/id into my php page. I'm wanting the page to get the users email on it's on. $_SESSION['user_id'] = 9; $stripe = array( "secret_key" => "sk_test_rDYOBYxCErhrgGCeWQJhR4mQ", "publishable_key" => "pk_test_3mIuE3OsajKO4cnFppcDDISu" ); \Stripe\Stripe::setApiKey($stripe['secret_key']); $db = new PDO('mysql:host=127.0.0.1;dbname=blog', 'root', ''); $userQuery = $db->prepare(" SELECT id, username, email, premium FROM users WHERE id = :user_id "); $userQuery->execute(['user_id' => $_SESSION['user_id']]); $users = $userQuery->fetchObject(); I'm using ID's right now, I have to enter them on my own. The website isn't live, just testing. I can get the users email with Stripe on my checkout page by putting echo $users->email & the email shows up on the purchase screen, where normally they would have to type it. I'm not sure how to get it on purchase so it will update the user in the DB though.
  13. Is there a way to get the count of rows like this? $count = somefunctionthatreturnscount(mysqli_query($mysqli, "SELECT COUNT(*) FROM table")); Instead of... $count = mysqli_num_rows(mysqli_query($mysqli, "SELECT id FROM table")); //or even... $count = mysqli_fetch_array(mysqli_query($mysqli, "SELECT COUNT(*) as count FROM table")); Ultimately, I want the method that will get the count the quickest and if can be done similarly to the first code and still have good performance. Thanks in advance! Update: Reported post as duplicate. Need moderate to delete duplicates as that option is not appearing for me.
  14. Hi, I am currently using the results of one query to query another table. I'm looking for a simple solution to combine both these queries into a single query & achieve the same result. Part of my code is below. Could you please help me to re-write my query? Thanks. $query1=("SELECT * FROM test_log WHERE '$mktime' < expiry ORDER BY id DESC"); $result1=mysql_query($query1); $num1=mysql_num_rows($result1); while ($row1 = mysql_fetch_array($result1)) { $id = $row1["id"]; $keyword = $row1["keyword"]; $sale = $row1["sale_rent"]; $agents = $row1["e_num"]; $email = $row1["email"]; $cc_email = $row1["cc_email"]; $expiry = $row1["expiry"]; $query2= ("SELECT * FROM condo WHERE (location LIKE '%{$row1['keyword']}%' AND sale_rent LIKE '%{$row1['sale_rent']}%' AND e_num LIKE '{$row1['e_num']}') AND (date >= '$sendate') AND TRIM(IFNULL(`phone_1`,'')) <> '' ORDER BY sale_rent, location"); $result2=mysql_query($query2); $num2=mysql_num_rows($result2); From the code above, I am using the results of $query1 to query the condo table ($query2). So now I want to do away with two queries & have just one query to achieve the same results. Could you show me the code please? Thanks
  15. i just created a new website for my local school i want to create a databse which will contain roll number ,marksof variosu subjects & name of students i created the database but now when i am trying to create a php script to enter students details i am having prouble in connection access denied for user 'abc'@'localhost' todatabse 'abc_db' what am i doing wrong ?? i think its because of user dont have proper privileges, how to give user privileges ?
  16. I's trying to transform data from mysql into something like $books below but it doenst seem to be working $books = array( "phil" => array("my girl" => 2.5, "the god delusion" => 3.5, "tweak" => 3, "the shack" => 4, "the birds in my life" => 2.5, "new moon" => 3.5) ) this is how I tried doing: $sql = "SELECT * from rating where user_id=11 limit 5"; $db_result = mysql_db_query($dbname,$sql) or trigger_error(mysql_error()); $num_rows = mysql_num_rows($db_result) or trigger_error(mysql_error()); while ($row = mysql_fetch_array($db_result)) { $one = $row['bookId']; $two = $row['user_id']; $three = $row['rating']; $ArraY= array( $two => array($one=>$three) ); print_r($ArraY); } but this is what i get : Array ( [11] => Array ( [123715] => 5 ) ) Array ( [11] => Array ( [140329] => 5 ) ) Array ( [11] => Array ( [3083854] => 4 ) ) Array ( [11] => Array ( [871236761] => 1 ) ) Array ( [11] => Array ( [451179757] => 1 ) ) Array ( [11] => Array ( [451403886] => 3 ) ) Array ( [24] => Array ( [044661095X] => 4 ) ) Array ( [24] => Array ( [014010268X] => 1 ) ) Array ( [24] => Array ( [812576063] => 5 ) ) Array ( [24] => Array ( [038076654X] => 1 ) ) instead of something like: Array ( [phil] => Array ( [my girl] => 2.5 [the god delusion] => 3.5 [tweak] => 3 [the shack] => 4 [the birds in my life] => 2.5 [new moon] => 3.5 ) [sameer] => Array ( [the last lecture] => 2.5 [the god delusion] => 3.5 [the noble wilds] => 3 [the shack] => 3.5 [the birds in my life] => 2.5 [new moon] => 1 ) [john] => Array ( [a thousand splendid suns] => 5 [the secret] => 3.5 [tweak] => 1 ) [peter] => Array ( [chaos] => 5 => 3.5 ) [jill] => Array ( [the last lecture] => 1.5 [the secret] => 2.5 [the noble wilds] => 4 [the host: a novel] => 3.5 [the world without end] => 2.5 [new moon] => 3.5 ) [bruce] => Array ( [the last lecture] => 3 [the hollow] => 1.5 [the noble wilds] => 3 [the shack] => 3.5 [the appeal] => 2 [new moon] => 3 ) [tom] => Array ( [chaos] => 2.5 ) ) Any help with how i can transform that will be much appreciated THANKS
  17. In the beginning, I had just one unique key set up in a table: username. When a username duplication in the Registration form was entered, I'd catch it and handle it like this: catch (PDOException $ex){ if ($ex->getCode() == 23000){ //Check if it's a duplciate key violation. $unameErr = '* Username already in use'; } Today, in the same table, I added another unique key: email. Now that I have two unique keys that will both have the same violation, how can I tell which one was the duplicate so I can provide the correct error to the user?
  18. I have a question about how I would structure a query. I have 2 tables. Store store_id -- primary key zip_code Merchandise item_id -- primary key item_name description cost storeID -- foreign key that references the store_id from the store. I am using InnoDB. I want the user to be able to input 1-5 choices that are 1 word apiece and it would cross reference the decription and tell me the store that has them both. For instance, choice 1 = clock, choice 2 = paper, and choice 3 = food. It would query a result that would give me the stores that have items that match the description of them all. For instance, it would return Wal - Mart based on this query because it would be the only store that had an item to match each description. Any help is much appreciated. Thanks!
  19. Hey guys I am struggling here. I am making an recipe website and right now attempting to create an search engine, to search the database for recipes. BUT the search form has form filters the user can edit such as one dropdown menu with preptime, another with what type of meal type, another like what type of cooking method etc etc. So how would the php if statements, query look like, I am not very experienced in sql so that is an main reason I am having such an struggle. Thanks
  20. So I have a simple script that adds and returns mysql data without refreshing the page. Everything works as it should. The only issue that I've noticed is that if I login as a user and insert a record(text) the FIRST time, it won't return that record in the row below. Not until I refresh the page. Now if I delete that record and insert a new record, it will then automatically return the record without the page refresh, as it should. Can you tell me why this is happening? Here is my js code. <script> $(document).ready(function(){ var recordId = $("#record-id").val(); function showRecord(){ $.ajax({ type: "POST", url: "bid-actions.php", data: "recordId="+recordId+"&action=showRecord", success:function(data){ $(".show-records").html(data); } }); } showRecord(); $(document).on('click','#record-submit',function() { var message = $("#message").val(); var recordId = $("#record-id").val(); $.ajax({ type: "POST", url: "bid-actions.php", data: "message="+message+"&recordId="+recordId+"&action=insertRecord", success:function(data){ showRecord(); $("#message").val(''); } }); }); }); </script> Html code. <div id="record-submit-form"> <input type="hidden" id="record-id" value="<?php echo $record_id; ?>"> <textarea id="message"></textarea> <input type="button" id="record-submit" value="Submit"> </div> <div class="show-records"> </div>
  21. Hello guys. I got a problem that whenever you register on my page, the registration is successful, no errors, successful redirection to login page, but the registration does not write the information into database and I have no idea why... I'm sure that i'm connecting correctly, to the correct table, with the correct commands, but it kinda does not work... BTW (This registration and login and all worked a few weeks ago, but I got an sudden internal server error, so I had to delete and reupload all files, and I had to change database. I changed the database, created the same table with the same columns, also I overwrote ALL old database information to the new (password, dbname,name) and, so page works fine, but that registration does not...I'm including my code for registration and registration form) Registration process CODE: <?php include_once 'db_connect.php'; include_once 'psl-config.php'; $error_msg = ""; if (isset($_POST['username'], $_POST['email'], $_POST['p'])) { // Sanitize and validate the data passed in $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING); $email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL); $email = filter_var($email, FILTER_VALIDATE_EMAIL); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { // Not a valid email $error_msg .= '<p class="error">The email address you entered is not valid</p>'; } $password = filter_input(INPUT_POST, 'p', FILTER_SANITIZE_STRING); // Username validity and password validity have been checked client side. // This should should be adequate as nobody gains any advantage from // breaking these rules. // $prep_stmt = "SELECT id FROM members WHERE email = ? LIMIT 1"; $stmt = $mysqli->prepare($prep_stmt); // check existing email if ($stmt) { $stmt->bind_param('s', $email); $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows == 1) { $error_msg .= '<p class="error">A user with this email address already exists.</p>'; } $stmt->close(); } // check existing username $prep_stmt = "SELECT id FROM members WHERE username = ? LIMIT 1"; $stmt = $mysqli->prepare($prep_stmt); if ($stmt) { $stmt->bind_param('s', $username); $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows == 1) { $error_msg .= '<p class="error">A user with this username already exists.</p>'; } $stmt->close(); } // TODO: // We'll also have to account for the situation where the user doesn't have // rights to do registration, by checking what type of user is attempting to // perform the operation. if (empty($error_msg)) { // Create salted password $passwordHash = password_hash($password, PASSWORD_BCRYPT); // Insert the new user into the database if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password) VALUES (?, ?, ?)")) { $insert_stmt->bind_param('sss', $username, $email, $passwordHash); // Execute the prepared query. if (! $insert_stmt->execute()) { header('Location: ../error.php?err=Registration failure: INSERT'); } } header('Location: ./continue.php'); } } and Registration form : <div class="register-form"> <center><h2>Registration</h2></center> <form action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>" method="post" name="registration_form"> <center><p></p><input type='text' name='username' placeholder="Username" id='username' /><br></center> <center><p></p><input type="text" name="email" id="email" placeholder="Email" /><br></center> <center><p></p><input type="password" name="password" placeholder="Insert Password" id="password"/><br></center> <center><p></p><input type="password" name="confirmpwd" placeholder="Repeat Password" id="confirmpwd" /><br></center> <center><p></p><input type="submit" class="button" value="Register" onclick="return regformhash(this.form, this.form.username, this.form.email, this.form.password, this.form.confirmpwd);" /> </center> </form> </div> Anybody know where is problem?
  22. Php value which was assigned to a text box, how to get this value to be used further with mysql query. Pls help me with the code
  23. I have done this a while back but lost the code. It worked back then. I am trying to recreate it but my memory isn't perfect. It's basically a follow/unfollow button like twitter. This is the main reference. http://jsfiddle.net/jakie8/ZECEN/ The php/mysql action queries do work if I call it through normal a href link; but for some reason, it's not being called through ajax. The jquery/ajax set variables do show up correctly when I test an alert with them inside. So that works too. I could really use fresh pair of eyes to see what I might have done wrong. Here is the index.php page. <html> <head> <script src="js/jquery-1.11.0.min.js"></script> <script> $(function() { $(document).on('click','.followButton',function(e) { e.preventDefault(); $button = $(this); if($button.hasClass('following')){ //$.ajax(); Do Unfollow var unfollow = $(this).attr('rel'); var follower = $("#follower-id").val(); $.ajax({ type: "POST", url: "actions.php", data: "unfollow="+unfollow+"follower="+follower+"&action=unfollow", success:function(data){ $button.removeClass('following'); $button.removeClass('unfollow'); $button.text('+ Follow'); } }); } else { // $.ajax(); Do Follow var following = $(this).attr('rel'); var follower = $("#follower-id").val(); $.ajax({ type: "POST", url: "actions.php", data: "following="+following+"follower="+follower+"&action=follow", success:function(data){ $button.addClass('following'); $button.text('Following'); } }); // return false; } }); $('button.followButton').hover(function(){ $button = $(this); if($button.hasClass('following')){ $button.addClass('unfollow'); $button.text('Unfollow'); } }, function(){ if($button.hasClass('following')){ $button.removeClass('unfollow'); $button.text('Following'); } }); }); </script> </head> <body> <div class="container"> <input type="hidden" id="follower-id" value="<?php echo $follower_userid; ?>"> <button class="btn followButton following" rel="<?php echo $following_userid; ?>">+ Follow</button> </div> </body> </html> And here is actions.php page. require_once 'core/init.php'; if($action == "follow") { $following = $_POST['following']; $follower = $_POST['follower']; $date = date('Y-m-d H:i:s'); $follow = $db->prepare("INSERT INTO followers(following_id, follower_id, date, active) VALUES(:following_id, :follower_id, :date, :active)"); $follow->bindParam(':following_id', $following); $follow->bindParam(':follower_id', $follower); $follow->bindParam(':date', $date); $follow->bindValue(':active', 1); $follow->execute(); } else if($action == "unfollow") { $unfollow = $_POST['unfollow']; $follower = $_POST['follower']; $date = date('Y-m-d H:i:s'); $unfollow = $db->prepare("UPDATE followers SET date = :date, active = :active WHERE following_id = :following_id AND follower_id = :follower_id"); $unfollow->bindParam(':following_id', $unfollow); $unfollow->bindParam(':follower_id', $follower); $unfollow->bindParam(':date', $date); $unfollow->bindValue(':active', 0); $unfollow->execute(); } else { // echo 'no action'; }
  24. Hello all. I am trying to get values from two tables but i am getting the wrong output regardless of the type of join i use. The two query have some similar columns/rows. I want to fetch only the specified columns/rows with their unique data but my query is giving me on a column the value of just another column. For instance if a description column in table A has a value of INVOICE and on table B the description is RECEIPT all my query show is either INVOICE or RECEIPT in all the columns regardless of whether the description is receipt or not and also i want all the fields that is not on the other table to be blank and not replicate columns eg. description. image refuse to show when attached and wouldn't allow me to use the image link on the editor, said i am not allowed. SELECT table1.trans_ref, table1.description, table1.date_paid, table1.recurring, table1.amt, table1.bill_code, table2.trans_ref, table2.description, table2.amt_deposited, table2.deposit_date FROM table1 RIGHT JOIN table2 ON table1.username = table2.username ps: would want amount and deposit amount to be on same column and also use a where username = username. or maybe i am not doing the right thing? is it possible to a select on two tables without using a JOIN? so that you can echo only the needed values in a loop. thanks
  25. Well, this makes the 8th forum today I guess this is not the normal query to be asking help on, but here we go. I have these two tables: attendees & history. Each attendee has a single entry in the attendee table, while all their payments to the therapist are stored in the history table. What I'm trying to do is retrieve the fields from the last payment the attendee made in the history table using MAX(historyid) and attendeeid, while getting their name from the attendee table. Here are the table schemas: TABLE `attendees` ( `attendeeid` int(10) unsigned NOT NULL AUTO_INCREMENT, `fname` varchar(20) NOT NULL, `lname` varchar(20) NOT NULL, `dojid` varchar(10) NOT NULL, `address1` varchar(25) NOT NULL, `address2` varchar(25) NOT NULL, `city` varchar(20) NOT NULL, `state` char(2) NOT NULL, `zipcode` varchar(5) NOT NULL, `phonenumber` varchar(15) NOT NULL, `paroleofficer` varchar(20) NOT NULL, `childrest` char(1) NOT NULL, `casedetails` varchar(255) NOT NULL, `disdate` date NOT NULL, `memberid` int(10) unsigned NOT NULL, PRIMARY KEY (`attendeeid`), KEY `memberid` (`memberid`), CONSTRAINT `attendees_ibfk_2` FOREIGN KEY (`memberid`) REFERENCES `members` (`memberid`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; TABLE `history` ( `historyid` int(10) unsigned NOT NULL AUTO_INCREMENT, `amount` float NOT NULL, `subsidy` char(1) NOT NULL, `last_payment` date NOT NULL, `amount_paid` float NOT NULL, `balance` float NOT NULL, `attendeeid` int(10) unsigned NOT NULL, `memberid` int(10) unsigned NOT NULL, PRIMARY KEY (`historyid`), KEY `attendeeid` (`attendeeid`), CONSTRAINT `history_ibfk_2` FOREIGN KEY (`attendeeid`) REFERENCES `attendees` (`attendeeid`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; The query I'm using sure 'nuff returns MAX(historyid), but the fields are from the first-ever entered row in the History table instead of the MAX(historyid) row. select * from (select a.attendeeid,max(h.historyid),fname,lname,h.last_payment,h.balance FROM history AS h INNER JOIN attendees AS a ON a.attendeeid = h.attendeeid group by a.attendeeid) as maxHistoryPerAttendee where attendeeid = 29 I'm new to MySQL and really don't even understand the query (given to me by someone in another forum). Would someone please help me out of the woods here? I've been at this one for a day and a half with nothing to show for it.
×
×
  • 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.