Jump to content

Search the Community

Showing results for tags 'sql'.

  • 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. prolife

    Sql issue

    Hello please i dont know what went wrong ;this SQL is meant to count provided that this conditions are true. i want to count the total number of rooms that were booked for in a particular month. Please what is the right syntax to use when selecting from two different tables and then counting the total number of occurance. Here is the SQL i came up with but its messig up. SELECT (SELECT COUNT(*) FROM `rooms`) (SELECT COUNT(*) FROM `order`) AS `total_rooms` FROM `rooms` WHERE `order`.`checkin`>'$real_date' AND `rooms`.`cond` ='available'
  2. I'm attempting to use PHP to connect to an SQL database to use to store quotes from an IRC chat bot. So far the bot seems to be running, but the sql connection isn't working and I'm not exactly sure why. I've tried reading through all sorts of sites, and I modified code I found on the WC3 schools site just to be sure I wasn't missing some huge 'derp'. Nothing seems to work, and I'm feeling my brain melt. Relevant connection data for writing to the db: function addquote() { $con=mysqli_connect("localhost","BotBot","password","Quotes"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_query($con,"INSERT INTO `Quotes`.`quotes` (`ID_NUM`, `DATA`, `USER`) VALUES (NULL, \'$qd\', \'\');"); $this->pm("Quote added to database."); mysqli_close($con); } Second connection for reading a random result from the db and messaging it: function randomquote() { $con=mysqli_connect("localhost","BotBot","password","Quotes"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM quotes ORDER BY RAND() LIMIT 1"); $this->pm($result); mysqli_close($con); } "password" in both is being replaced with the relevant password for that user account, and the account has full access to r/w the db. I am getting the pm("Quote added to database") line returned to me through the IRC bot, and it doesn't disconnect the moment you try to use these functions (took about a week of pokes and prods to figure out what I was doing wrong!). I'm not exactly sure how a response down past that sql connection could be working if it's not connecting, not without giving me a 'die'. PHPMyAdmin isn't showing that 'BotBot' account even attempting a connection and dying for a bad password or anything, so... kinda running out of ideas here. If anyone can give me a hand here, I'd be grateful for it.
  3. I have a problem that when I submit the page goes blank or goes to the location specified in header but it does not update the sql record. This used to work but I made some changes and now I cannot get it back. Any assistance would be appreciate. <?php require('edb.php'); $id=$_REQUEST['id']; $ActivateCode=$_REQUEST['ActivateCode']; $result=mysql_query("SELECT * FROM `eusers` WHERE id = '$id' && ActivateCode = '$ActivateCode'"); $test=mysql_fetch_array($result); if (!$result) { die("Error: Data not found.."); } $id=$test['id']; $FirstName=$test['FirstName']; $LastName=$test['LastName']; $State=$test['State']; $Username=$test['Username']; $Password=$test['Password']; $Email=$test['Email']; $Active=$test['Active']; $SecurityCode=$test['SecurityCode']; $AdviserCode=$test['AdviserCode']; $UserType=$test['UserType']; $ActivateCode=$test['ActivateCode']; if(isset($_POST['Submit'])) { $Password_save =sha1($_POST['Password']); $Email_save =$_POST['Email']; $Active_save =$_POST['Active']; $SecurityCode_save =$_POST['SecurityCode']; $ActivateCode_save =$_POST['ActivateCode']; mysql_query("UPDATE `eusers` SET Password ='$Password_save', Email ='$Email_save', Active ='$Active_save', SecurityCode ='$SecurityCode_save', ActivateCode ='$ActivateCode_save' WHERE id ='$id'") or die(mysql_error("Did not Save")); echo "Saved!"; header("Location: index.php"); } ?>
  4. Hi, I have been trying to get this piece of coding to submit my form after checking but it keeps going to a 500Error. I have spent so long trying to work it out that now I am confused on what works and what doesn't. Can someone please help with where I am going wrong. <?php if(isset($_POST['Submit'])){ $DateUploaded = protect($_POST['DateUploaded']); $AdviserCode = protect($_POST['AdviserCode']); $DocName = protect($_POST['DocName']); $URL = protect($_POST['URL']); $ImageType = protect($_POST['ImageType']); $Current = protect($_POST['Current']); $css_class = protect($_POST['css_class']); if(!$ImageType || !$DocName){ echo "<center>You need to fill in all of the required filds!</center>"; }else{ $res = mysql_query ("INSERT INTO `adocs_cpd` (`DateUploaded`, `AdviserCode`, `DocName`, `URL`, `ImageType`, `Current`, `css_class`) VALUES ('".$DateUploaded."','".$AdviserCode."','".$DocName."','".$URL."','".$ImageType."','".$Current."','".$css_class."')"); echo "Saved!"; } } ?>
  5. Hello! I have made a query and displaying this - it's working. But I want this query-result to be a link (href) to another query that I want to display. My query right now is: <ul> <?php $test = mysql_query("SELECT * FROM `huvudProject` WHERE `categoryProject` = 1"); while($row = mysql_fetch_assoc($test)) { echo "<li>" . $row['huvudProjectName'] . "</li>"; } ?> </ul> I want the 'huvudProjectName' be the name of a link. How can I do this? Also, I want this link to do a query when I click it for this: SELECT * FROM `project` WHERE `projectHuvudId` = 1 And then show the result somewhere. Is this possible?
  6. prolife

    SQL error

    Good day everyone, my SQL is giving yet another result i dont like, its duplicating results. Please anyone with an iidea on how to get this solved? Below is my sql: SELECT `rooms`.* , `order`.* FROM `rooms` INNER JOIN `order` ON `order`.`room-id`!=`rooms`.`roomid` AND `rooms`.`cond`='not taken' AND `order`.`checkin` !='$checkin' AND `order`.`checkout` !='$checkout'. In brief the results are to be displayed as long as the 'checkin' and 'checkout' dates are not already recorded or stored in the order table and also that the condition or maybe status of the room is 'not taken ' Thanks
  7. Hello every one... I'm developing a project for my friend and i've some queries... How to control facebook like page system.. Means the user will not able to login into his account after registration untill and unless he likes our facebook page... How to aheive this... How can I know whether he liked the page or not... Any help will be greatly appreciated..
  8. I have a notifications system and after many late nighters and dr peppers I finally have it working. My only issue is that the notifications "bell" has the number of new notifications in the middle of it. When I click the button it will show me my unread notifications and when I close it the number of unread notifications stays the same. I'm using a sql statement to get the number of unread posts on load but when I click the button to reveal the notifications I'd like it to update the number of unread posts as well. Here's some code I have: //GETS THE NOTIFICATIONS function toggleDiv(divId) { $("#"+divId).show(); $(document).ready(function(){ $("#myContent").load("getnotes.php"); }); } //BUTTON TO PRESS TO SHOW THE NOTIFICATIONS PANEL <a data-ajax="false" href="#myContent" onclick="toggleDiv('myContent');" data-role="button" data-iconpos="notext" class="icon-bell-alt icon-2x" style="background: none; margin-right: 20px;"></a> //SHOWS THE NUMBER OF UNREAD POSTS <div id='notes_number'><? if ($number == "0") { echo $number; } else { echo "<a style='color: #FF0000;'>$number</a>"; }?></div> What can I do to update the number?
  9. I am trying to pull data from SQL where the ID and activation code match the record by using the URL to request the info. The form pulls up the first record but I cannot get it to return the correct id and code. URL example: www.domain.com/activate.php?id=7&ActivateCode=xajkdfjeklhwekjfhergh Not sure how to write this in the php, what I have tried does not seem to pull anything other than the first record in the system. <?php require('edb.php'); $id=$_REQUEST['id']; $ActivateCode=$_REQUEST['ActivateCode']; $result=mysql_query("SELECT * FROM `eusers` WHERE id = '$id' & ActivateCode = '$ActivateCode'"); $test=mysql_fetch_array($result); if (!$result) { die("Error: Data not found.."); } $FirstName=$test['FirstName']; $LastName=$test['LastName']; $State=$test['State']; $Username=$test['Username']; $Password=$test['Password']; $Email=$test['Email']; $Active=$test['Active']; $SecurityCode=$test['SecurityCode']; $AdviserCode=$test['AdviserCode']; $UserType=$test['UserType']; $ActivateCode=$test['ActivateCode']; if(isset($_POST['Submit'])) { $Password_save=sha1($_POST['Password']); $Email_save=$_POST['Email']; $Active_save=$_POST['Active']; $SecurityCode_save=$_POST['SecurityCode']; $ActivateCode_save=$_POST['ActivateCode']; mysql_query("UPDATE `eusers` SET Password ='$Password_save', Email ='$Email_save', Active ='$Active_save', SecurityCode ='$SecurityCode_save', ActivateCode ='$ActivateCode_save' WHERE id ='$id'") or die(mysql_error("Did not Save")); echo "Saved!"; header("Location: index.php"); } ?>
  10. I have been trying to figure this out for days but no luck so far. I have two tables which I want to pull info from and from what I read a join query is the way to go. I need to pull the info from the bank table based on the login id in the users table. I keep getting a black page result or a Data not Found result. Because this is the first time I have tried a join query I don't really know what I am doing. Is anyone able to give me some advice? <?php //if the login session does not exist therefore meaning the user is not logged in if(strcmp($_SESSION['uid'],"") == 0){ //display and error message header('Location: ../index.php'); }else{ //otherwise continue the page //this is out update script which should be used in each page to update the users online time $time = date('U')+50; $update = mysql_query("UPDATE `e-users` SET `Online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'"); ?> <?php //make sure you close the check if their online } ?> <?php require("../edb.php"); $result = mysql_query("SELECT AcctName, BSB1, BSB2, AccNumber, Adviser, Bank FROM a-bank JOIN e-users ON a-bank.Adviser = e-users.id; WHERE e-users.id = '".$_SESSION['uid']."'"); if (!$result) { die("Error: Data not found.."); } $AcctName=$test['AcctName']; ?>
  11. Registration and login work fine. Update also updates the information to the database. However if 2 people with the same first name register on the database it automatically defaults both those accounts to the last person who has the same first name that registered on the database instead of updating and showing the information for that particular user. So if Joe - joe@xxx.co.za registers and then another Joe - joe@sss.co.za then when Joe (sss) logins in he can see all Joe(xxx) information and when he updates his details it updates Joe (xxx) account instead of showing and updating Joe (sss) account. I think there is a problem with the session "id" and the update "id" that's causing this problem but I just can't see where it is.... can anyone assist with this? It's not using the email address as the "id" but is using the "name"..... Here's the code: The start session coding: <?php session_start(); $toplinks = ""; if (isset($_SESSION['id'])) { // Put stored session variables into local php variable $userid = $_SESSION['id']; $email = $_SESSION['email']; $toplinks = '<a href="member_account.php?id=' . $userid . '">Enter CV step-by-step</a> | <a href="view_personal_details.php?id=' . $userid . '">View Personal Details</a> | <a href="view_your_cv.php?id=' . $userid . '">View CV</a> | <a href="edit_your_cv.php?id=' . $userid . '">Edit CV</a> | <a href="change_password.php?id=' . $userid . '">Change Password</a> | <a href="logout.php">Log Out</a>'; } else { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } ?> And the update coding is: <?php include_once "connect_to_mysql.php"; echo print_r($_POST); $id = $_SESSION['id']; if (isset($_POST['email'])){ $update=''; if(isset($_POST['title']) and trim($_POST['title']) <> '') $update .= "title = '" . mysql_real_escape_string($_POST['title']) . "',"; if(isset($_POST['name']) and trim($_POST['name']) <> '') $update .= "name = '" . mysql_real_escape_string($_POST['name']) . "',"; if(isset($_POST['surname']) and trim($_POST['surname']) <> '') $update .= "surname = '" . mysql_real_escape_string($_POST['surname']) . "',"; if(isset($_POST['identityno']) and trim($_POST['identityno']) <> '') $update .= "identityno = '" . mysql_real_escape_string($_POST['identityno']) . "',"; if(isset($_POST['gender']) and trim($_POST['gender']) <> '') $update .= "gender = '" . mysql_real_escape_string($_POST['gender']) . "',"; if(isset($_POST['birthdate']) and trim($_POST['birthdate']) <> '') $update .= "birthdate = '" . mysql_real_escape_string($_POST['birthdate']) . "',"; if(isset($_POST['ethnicity']) and trim($_POST['ethnicity']) <> '') $update .= "ethnicity = '" . mysql_real_escape_string($_POST['ethnicity']) . "',"; if(isset($_POST['nationality']) and trim($_POST['nationality']) <> '') $update .= "nationality = '" . mysql_real_escape_string($_POST['nationality']) . "',"; if(isset($_POST['email']) and trim($_POST['email']) <> '') $update .= "email = '" . mysql_real_escape_string($_POST['email']) . "',"; if(isset($_POST['homeaddress']) and trim($_POST['homeaddress']) <> '') $update .= "homeaddress = '" . mysql_real_escape_string($_POST['homeaddress']) . "',"; if(isset($_POST['province']) and trim($_POST['province']) <> '') $update .= "province = '" . mysql_real_escape_string($_POST['province']) . "',"; if(isset($_POST['suburb']) and trim($_POST['suburb']) <> '') $update .= "suburb = '" . mysql_real_escape_string($_POST['suburb']) . "',"; if(isset($_POST['hometele']) and trim($_POST['hometele']) <> '') $update .= "hometele = '" . mysql_real_escape_string($_POST['hometele']) . "',"; if(isset($_POST['celltele']) and trim($_POST['celltele']) <> '') $update .= "celltele = '" . mysql_real_escape_string($_POST['celltele']) . "',"; if(isset($_POST['creditclear']) and trim($_POST['creditclear']) <> '') $update .= "creditclear = '" . mysql_real_escape_string($_POST['creditclear']) . "',"; if(isset($_POST['criminalrecord']) and trim($_POST['criminalrecord']) <> '') $update .= "criminalrecord = '" . mysql_real_escape_string($_POST['criminalrecord']) . "',"; if(isset($_POST['driverslicense']) and trim($_POST['driverslicense']) <> '') $update .= "driverslicense = '" . mysql_real_escape_string($_POST['driverslicense']) . "',"; if(isset($_POST['owntransport']) and trim($_POST['owntransport']) <> '') $update .= "owntransport = '" . mysql_real_escape_string($_POST['owntransport']) . "',"; if(isset($_POST['medicalconditions']) and trim($_POST['medicalconditions']) <> '') $update .= "medicalconditions = '" . mysql_real_escape_string($_POST['medicalconditions']) . "',"; $update=substr($update,0,-1); $sql = "UPDATE cic_candidates set $update WHERE id = '" . mysql_real_escape_string($id) . "'"; mysql_query($sql); echo $sql; echo '<center>'; echo '<strong><font color=black family=tahoma size=5><br /><br /><br /><br />Successful!<br /><br /><br /> Your account info has been updated...<br /><br /><br /> To view your updated information at <font color=blue>View Personal Details</font> - <a href="view_personal_details.php?id=' . $userid . '">click here<br /></a><br /><br />To return to your <font color=blue>Edit Personal Details</font> page - <a href="edit_personal_details.php?id=' . $userid . '">click here</a><br /><br /></font></strong>'; mysql_close(); exit(); } ?>
  12. I have searched over 1500 posts over the last 2 weeks and have not found the solution to make my code work. My registration and login forms work correctly but when the user logins to add or edit information the sql database does not update with the users input and the error/updated message does not echo. My users register with name, surname, email and password but once they login they need to add to their personal information and later be able to edit the personal information. But nothing I've tried has worked... my code is as follows: <?php include_once "connect_to_mysql.php"; $id = $_SESSION['id']; if ($_POST['username']) { $title = $row["title"]; $username = $row["username"]; $surname = $row["surname"]; $identityno = $row["identityno"]; $gender = $row["gender"]; $birthdate = strftime("%d %b %Y", strtotime($row["birthdate"])); $ethnicity = $row["ethnicity"]; $nationality = $row["nationality"]; $homeaddress = $row["homeaddress"]; $province = $row["province"]; $suburb = $row["suburb"]; $hometele = $row["hometele"]; $celltele = $row["celltele"]; $creditclear = $row["creditclear"]; $criminalrecord = $row["criminalrecord"]; $driverslicense = $row["driverslicense"]; $owntransport = $row["owntransport"]; $medicalconditions = $row["medicalconditions"]; $sql = mysql_query("UPDATE cic_candidates SET title='$title', username='$username', surname='$surname', identityno='$identityno', gender='$gender', birthdate='$birthdate', ethnicity='$ethnicity', nationality='$nationality', homeaddress='$homeaddress', province='$province', suburb='$suburb', hometele='$hometele', celltele='$celltele', creditclear='$creditclear', criminalrecord='$criminalrecord', driverslicense='$driverslicense', owntransport='$owntransport', medicalconditions='$medicalconditions' WHERE id='$id'"); echo 'Your account info has been updated, you will now see the new info.<br /><br /> To return to your profile edit area, <a href="edit_personal_details.php">click here</a>'; exit(); } ?>
  13. I have a created a "state" dropdown box on a form which enters into the SQL, when I php echo it shows the state ok as text but when I try to get it to populate on the edit screen within the dropdown box it does not show. I am trying to get the dropdown box to automatically select the state from the data in SQL. Where am I going wrong with this. Any help would be appreciated. <select name="State" id="State" selected="<?php echo $State ?>"> <option value="--">--</option> <option value="ACT">ACT</option> <option value="NSW">NSW</option> <option value="NT">NT</option> <option value="QLD">QLD</option> <option value="SA">SA</option> <option value="TAS">TAS</option> <option value="VIC">VIC</option> <option value="WA">WA</option> </select>
  14. Query: SELECT UMTS_napetude_cell.parent, UMTS_napetude_nodeb.idnap FROM UMTS_napetude_cell LEFT JOIN UMTS_napetude_nodeb ON UMTS_napetude_cell.parent IS NOT LIKE CONCAT('%',UMTS_napetude_nodeb.idnap,'%') WHERE UMTS_napetude_cell.parent IS NOT NULL Error: Thanks in advanced.
  15. I have been tasked to find the problem with this site's database connection. The site is a PHP, MySQL, Smarty site. Currently, I am getting the following when www.mysite.com is called. The index.php is located at www.mysite.com/index.php The current locations of the following files are: includes/ru_config.com includes/ru_connection.com All the replaced passwords, usernames, and site specific information worked previously so the problem is not there. One problem there might be, is in ru_connection where the paths for ru_4pear and DB.php might be wrong. There locations are: includes/ru_4pear.com libs/pear/DB.php ru_config.php index.php ru_connection.php DB.php ru_4pear.php
  16. I would like to solve this query. Query: $sql = 'SELECT DISTINCT *, c.ci as c_i FROM `GSM_cellule` c '. 'LEFT JOIN '.$table_freq.' f ON(c.nidtint=f.nidtint) '. 'WHERE c.NAP_'.$site->ur().' =\'1\' '. $this->_in.' and '.$this->_inetatbdespec.' and '.$this->_inindus.' GROUP BY c.nidtint ORDER BY c.nidtint '; Error: Thanks in advanced.
  17. Hey all. First I want to say that I'm very amateur when it comes to coding. Most of what I know has been self-taught so I don't have any formal education. My coding vocabulary is awful, but generally when I build code I understand what it's doing in laymen terms (ex. it's pulling data from the "users" row in a table and is displaying that data). Anyway...that's my disclaimer to ask you to be easy on me. So now to my actual issue. I've built a page where logged in users can share photos with their friends. I successfully built this without any issues. Now I want friends to be able to add comments to the photos. Not so easy. Problem is I have two tables built. One for the sharing of the photos the other for the comments. Here are how the tables are built out: Photo Table id | username | initiator | file | gallery | date_time Comment Table id | comment | user | file | date_time Initially I had two queries. Both use a "fetch" array in order to grab and then display specific info in a specific order only for specific users. This was almost working but whichever query came first would only display one result. The query that came after would display all the appropriate results which is what I wanted out of both queries. On another forum I was told that I needed to "join" or "union" the two queries together. Problem is that when I attempt to do that I get a single dead image, no comments other than the default stuff that is already entered in the PHP code and the error: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given... Here is the actual query and code: //WHERE I GATHER COMMENT & PHOTO DATA $sql = "SELECT comment, user, file, date_time FROM comment UNION ALL SELECT DISTINCT initiator, file, gallery FROM photo WHERE username='$log_username' OR initiator='$log_username' ORDER BY date_time DESC"; $query = mysqli_query($db_conx, $sql); while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) { $c = $row["comment"]; $us = $row["user"]; $pf = $row["file"]; $time = $row["date_time"]; $u = $row["initiator"]; $file = $row["file"]; $gallery = $row["gallery"]; $image = 'user/'.$u.'/'.$file; } //WHERE I DISPLAY THE PHOTO DATA $imagelist .= ' <img height="200" onclick="this.height=500;" ondblclick="this.height=200;" src="'.$image.'" alt="'.$u.'" /><br /> Added to <a href="user.php?u='.$u.'"><b>'.$u.''s</b></a> '.$gallery.' gallery<br /><br /> <form action="php_parsers/photocomments_system.php" enctype="multipart/form-data" method="post"> <input type="text" name="comment"> <input type="hidden" name="photo_file" value="'.$file.'"> <input type="submit" class="submit" value=" Submit Comment " /> </form><br /><p style="border-bottom: 1px dotted #A0A0A0;"></p>'; //WHERE I DISPLAY THE PHOTO COMMENTS AND DICTATE WHAT COMMENT SHOWS WITH WHAT PHOTO if ($pf == $file) { $imagelist .='<p style="background-color:#E0E0E0;"> <b>'.$us.'</b>: '.$c.' | '.$time.'</p> <br /><br /><hr/>'; } For the HTML portion this is where it actually gets displayed: <div id="page Middle"><?php echo $imagelist; ?></div> Anyway, I'm assuming there is something wrong with my query and that's why I'm getting the error. Problem is I'm not sure what is wrong with the query. If there is any easier way to do this and I was doing something wrong with the two separate queries that could easily be resolved I can show you how I built that as well. I would continue on the other forum with the guy that was helping me but he was a little bit too technical for me to understand his suggestions. Anyway, any help you could give would be GREATLY appreciated. Thanks!
  18. This query is not working. I need urgent help. Thanks a lot in adv. ROWS affected: 0 I have cross checked the data in the table for the given condition. $sql = 'UPDATE LTE_noria_cellule cel_bk_up SET cel.NAP_'.$site->ur().' = \'1\' '. 'WHERE cel.nidt IN ( select gn from LTE_noria_candidat_bk_up can INNER JOIN LTE_noria_site_bk_up site ON (site.codesite = can.codesite) WHERE '.$site->get_param('zone_bde').')'; I believe problem is because of WHITESPACE. When i search "codesite" in the table with "LIKE". I can't find it. But when i did "LIKE%" , it's working. I tried this also but not working $sql = 'UPDATE LTE_noria_cellule cel_bk_up SET cel.NAP_'.$site->ur().' = \'1\' '. 'WHERE cel.nidt IN ( select gn from LTE_noria_candidat_bk_up can INNER JOIN LTE_noria_site_bk_up site ON trim(site.codesite) LIKE CONCAT('%',trim(can.codesite),'%') WHERE '.$site->get_param('zone_bde').')';
  19. When trying to upload a picture file it goes error:Failed to upload file. Contact Site admin to fix the problem What am I doing wrong ======================= <?php include 'db.php'; $id=@$_GET['id']; $ya=mysql_query("select * from `registeronline` where user_id='$id'"); $yb=mysql_fetch_array($data); $val= '$id'+2400241106; if (!isset($_POST["Submit"])) { echo ""; }else{ $file=@$_POST['pix']; if (isset($HTTP_POST_FILES["pix"])){ $upload_type =$HTTP_POST_FILES["pix"]["type"]; $upload_name=$HTTP_POST_FILES["pix"]["name"]; $upload_size=$HTTP_POST_FILES["pix"]["size"]; $upload_tmp_name=$HTTP_POST_FILES["pix"]["tmp_name"]; } else { echo "" ; } if ($userfile_size >250000){$msg=$msg."Your uploaded file size is more than 250KB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>"; $file_upload="false";} if (!($userfile_type =="image/pjpeg" OR $userfile_type=="image/gif")){$msg=$msg."Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>"; $file_upload="false";} $add="upload/$userfile_name"; // the path with the file name where the file will be stored, upload is the directory name. if(move_uploaded_file ($userfile, $add)){ // Your Picture has been uploaded successfully. }else{echo "Failed to upload file. Contact Site admin to fix the problem";} $z=mysql_query("update `registeronline` set pix='$file' where `user_id`='$id' "); if (!$z ) { echo "<script>alert('Update Not Successful')</script>"; }else{ } }
  20. Hey, so to display an image from a database I was using $id = addslashes($_REQUEST['id']); $image = mysql_query("SELECT * FROM store_image WHERE id=$id"); $image = mysql_fetch_assoc($image); $image = $image['image']; header("Content-type: image/jpeg"); echo $image; That worked fine to return an image via matching the id. But I want to get ALL images from the table.. I tried this: $image = mysql_query("SELECT * FROM store_image"); while($image = mysql_fetch_array($image)){ $image = $image['image']; header("Content-type: image/jpeg"); echo $image; } But did not work.. what am I doing wrong?
  21. Hello guys, I posted this Question in MYSQL thread accidentally, so I'll try to ask the same here since I use Oracle RDBMS. Need help regarding SQL and aggregate function. I would like to do max function (or some join or something else), to get max value of column, and other column with it also. Here's the code: SQL> select department_id, sum(salary) place_total from employees where department_id is not null group by department_id; Previous query outputs this: DEPARTMENT_ID PLACE_TOTAL ------------- ----------- 90 58000 20 19000 110 20300 50 17500 80 30100 60 19200 10 4400 Now, how to edit previous sql statement so it can output department_id, and max(place_total), so the output result is: DEPARTMENT_ID PLACE_TOTAL ------------- ----------- 90 58000 Anyone have an idea, how to do this ? Thanks !
  22. I have found some code that I am trying to work with to import some data from a CSV file into a table of my database. It works and imports the data, but always inserts a NULL row for each column. Here is the code: <?php $self = $_SERVER['PHP_SELF']; $request = $_SERVER['REQUEST_METHOD']; if (!isset($_GET['success'])) { $get_success = ""; } else { $get_success = $_GET['success']; } if (!empty($_FILES)) { /* Format the errors and die */ function get_last_error() { $retErrors = sqlsrv_errors(SQLSRV_ERR_ALL); $errorMessage = 'No errors found'; if ($retErrors != null) { $errorMessage = ''; foreach ($retErrors as $arrError) { $errorMessage .= "SQLState: ".$arrError['SQLSTATE']."<br>\n"; $errorMessage .= "Error Code: ".$arrError['code']."<br>\n"; $errorMessage .= "Message: ".$arrError['message']."<br>\n"; } } die ($errorMessage); } /* connect */ function connect() { if (!function_exists('sqlsrv_num_rows')) { // Insure sqlsrv_1.1 is loaded. die ('sqlsrv_1.1 is not available'); } /* Log all Errors */ sqlsrv_configure("WarningsReturnAsErrors", TRUE); // BE SURE TO NOT ERROR ON A WARNING sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_ALL); sqlsrv_configure("LogSeverity", SQLSRV_LOG_SEVERITY_ALL); $conn = sqlsrv_connect('cslogs', array ( 'UID' => 'mailreport', 'PWD' => '123456', 'Database' => 'Mail', 'CharacterSet' => 'UTF-8', 'MultipleActiveResultSets' => true, 'ConnectionPooling' => true, 'ReturnDatesAsStrings' => true, )); if ($conn === FALSE) { get_last_error(); } return $conn; } function query($conn, $query) { $result = sqlsrv_query($conn, $query); if ($result === FALSE) { get_last_error(); } return $result; } /* Prepare a reusable query (prepare/execute) */ function prepare ( $conn, $query, $params ) { $result = sqlsrv_prepare($conn, $query, $params); if ($result === FALSE) { get_last_error(); } return $result; } /* do the deed. once prepared, execute can be called multiple times getting different values from the variable references. */ function execute ( $stmt ) { $result = sqlsrv_execute($stmt); if ($result === FALSE) { get_last_error(); } return $result; } function fetch_array($query) { $result = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC); if ($result === FALSE) { get_last_error(); } return $result; } $conn = connect(); /* prepare the statement */ $query = "INSERT Records values ( ? , ? , ? )"; $param1 = null; // this will hold col1 from the CSV $param2 = null; // this will hold col2 from the CSV $param3 = null; // this will hold col3 from the CSV $params = array( $param1, $param2, $param3 ); $prep = prepare ( $conn, $query, $params ); $result = execute ( $prep ); //get the csv file $file = $_FILES["csv"]["tmp_name"]; /* Here is where you read in and parse your CSV file into an array. That may get too large, so you would have to read smaller chunks of rows. */ $csv_array = file($file); foreach ($csv_array as $row_num => $row) { $row = trim ($row); $column = explode ( ',' , $row ); $param1 = $column[0]; $param2 = $column[1]; $param3 = $column[2]; // insert the row $result = execute ( $prep ); } /* Free statement and connection resources. */ sqlsrv_close($conn); header( "Location: test.php?success=1" ); } ?> <!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=iso-8859-1" /> <title>Import a CSV File with PHP & MS SQL Server</title> </head> <body> <?php if (!empty($get_success)) { echo "<b>Your file has been imported.</b><br><br>"; } //generic success notice ?> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> Choose your file: <br /> <input name="csv" type="file" id="csv" /> <input type="submit" name="Submit" value="Submit" /> </form> </body> </html> Now I know it is at this part wiht the $param1, $param2 and $param 3 that it is inserting the NULL values for each column: /* prepare the statement */ $query = "INSERT Records values ( ? , ? , ? )"; $param1 = null; // this will hold col1 from the CSV $param2 = null; // this will hold col2 from the CSV $param3 = null; // this will hold col3 from the CSV $params = array( $param1, $param2, $param3 ); $prep = prepare ( $conn, $query, $params ); $result = execute ( $prep ); But if I take that out them three out, the php errors out then doesn't import the data. Is there a way with what I have to ignore the first row to import? Or am I going about this all wrong?
  23. Update is not working.. UPDATE Customers SET ContactName='Alfred Schmidt', City='Hamburg' WHERE CustomerFirstName='Alfreds' AND CustomerLastName='Futterkiste' Thanks in advanced.
  24. I am having trouble getting a simple form to submit data to a database. I have followed an example in a PHP/MySQL book (Welling and Thomson) and created a simple form to update a DVD collection. Right now I just have a form started and am just trying to get it to INSERT records into my database. It is making a connection to the database, but it returns my Error stating that the record could not be added. While all of my code is very basic,I am just trying to get an understanding as to how it is working... I have looked in MySQL through command prompt and the database exists, but records are not being added. I can add records to the table through CMD prompt. I will post my code for the database and my two php files for inserting records. Database: create database movie_info; use movie_info; create table movies (movieid int unsigned not null auto_increment primary key, title char(50) not null, movieyear char(4) not null, genre char(25) not null, subgenre char(25), director char(30), actor1 char(30), actor2 char(30), actor3 char(30), discs char(2), season char(2), comments char(200) ); Form: function input_form(){ ?> <form method="post" action="insert_movie.php"> <table bgcolor="#cccccc"> <tr> <td colspan="2">Enter a new DVD:</td> <tr> <td>Title:</td> <td><input type="text" name="title"/></td></tr> <tr> <td>Year:</td> <td><input type="text" name="year"/></td></tr> <tr> <tr> <td>Genre:</td> <td><input type="text" name="genre"/></td></tr> <tr> <tr> <td>Sub-Genre:</td> <td><input type="text" name="subgenre"/></td></tr> <tr> <tr> <td>Director:</td> <td><input type="text" name="director"/></td></tr> <tr> <tr> <td>Actor:</td> <td><input type="text" name="actor1"/></td></tr> <tr> <tr> <td>Actor:</td> <td><input type="text" name="actor2"/></td></tr> <tr> <tr> <td>Actor:</td> <td><input type="text" name="actor3"/></td></tr> <tr> <tr> <td>Number of discs:</td> <td><input type="text" name="discs"/></td></tr> <tr> <tr> <td>Season:</td> <td><input type="text" name="season"/></td></tr> <tr> <tr> <td>Comments:</td> <td><input type="text" name="comments"/></td></tr> <tr> <td colspan="2" align="center"> <input type="submit" value="Submit"/></td></tr> <tr> </table></form> <?php } and the INSERT code: <?php require_once('movie_functions.php'); //require_once('db_functions.php'); do_html_header('Moviebase'); @$title = $_POST['title']; @$year = $_POST['year']; @$genre = $_POST['genre']; @$subgenre = $_POST['subgenre']; @$director = $_POST['director']; @$actor1 = $_POST['actor1']; @$actor2 = $_POST['actor2']; @$actor3 = $_POST['actor3']; @$discs = $_POST['discs']; @$season = $_POST['season']; @$comments = $_POST['comments']; if (!$title || !$year || !$genre) { echo "You have not entered all of the required details. <br />" ."Please go back and try again.<br /><br />" ."<a href='movies.php'>Go Back</a>"; exit; } @$db = new mysqli('localhost', 'root', '********', 'movie_info'); if (mysqli_connect_errno()) { echo "Error: Could not connect to database. Please try again later."; exit; } $query = "INSERT INTO movies VALUES (NULL, '".$title."', '".$year."', '".$genre."', '".$subgenre."', '".$director."', '".$actor1."', '".$actor2."', '".$actor3."', '".$discs."', '".$season."', '".$comments."')"; $result = $db->query($query); if ($result) { echo $db->affected_rows." has been inserted into the database."; //input_form(); } else { echo "An error has occurred. The item was not added."; //for testing echo "<br />Result: ".$result; echo "<br />".$title; echo "<br />".$year; echo "<br />".$genre; echo "<br />".$subgenre; echo "<br />".$director; echo "<br />".$actor1; echo "<br />".$actor2; echo "<br />".$actor3; echo "<br />".$discs; echo "<br />".$season; echo "<br />".$comments; //input_form(); } $db->close(); footer(); ?> This all will return all variable values (except $result), so it seems like $result is empty. Any help in understanding this would be greatly appreciated, Thanks!
  25. I wonder if anyone can help me. I'm creating an application in PHP and am using a SQL server database on my local computer to develop the application. The only problem is I cannot connect to the database. My code looks like <?php $serverName = "LIAMJAY-PC\SQLEXPRESS"; //serverName\instanceName $connectionInfo = array( "Database"=>"ONEDB"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn ) { echo "Connection established.<br />"; }else{ echo "Connection could not be established.<br />"; die( print_r( sqlsrv_errors(), true)); } ?> to connect to the database. However, everytime I run the code I keep getting a 18456 error code. Does anybody know what my problem is and if so, what is the solution???
×
×
  • 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.