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. Dear all, Here is my scenario, I have a php page called index.php which is linked to dashboard. At the index page i will have 40-50 href's each with a id like dashboard.php/subcat=1 When a user click's particular href they will be forwarded to a page called dashboard and there i get this id. $subcat=$_REQUEST['subcat']; This dashboard is dynamic. In this page i have three different div's. Each with different query and result display. For example: My first div has a query and some 50 results. I want a display first four rows and remaining as a ajax pagination. similarly for the other two div's. There is no problem in using ajax pagination because it will be executed in different page and result will be display here. But the real problem is in each of my query i should pass the original subcat id which is what make the dashboard dynamic. Now, i need someway to pass this dynamic id for my external pagination for each query.
  2. Hi all, Im new to php and im trying to do something a bit fiddly. I was wondering if anyone knows how... I have a table 'obs' with columns '_sfm_form_submision_time_' (date and time of submission of dataset in format YYYY-MM-DD HH:MM:SS), 'mrn', 'sbp' and a few other variables. I want to echo the sbp and TIME (in the format HH:MM from _sfm_form_submision_time_), as long as the DATE of submission was today (ie date in _sfm_form_submision_time_ is current date) for a given value for mrn (passed from previous page). Ie, if 3 data sets were entered today for mrn 001 then i want to display the times these were entered, and the sbp entered. I have this so far but it keeps telling me no results for mrns that have datasets enetered today, so somewhere the code must be wrong but i can't figure out where! Any help to find the problem would be amazing, thanks! <?php //STEP 1 Connect To Database $connect = mysql_connect("localhost","jasperss_par1","password"); if (!$connect) { die("MySQL could not connect!"); } $DB = mysql_select_db('jasperss_par1pats'); if(!$DB) { die("MySQL could not select Database!"); } //STEP 2 Check Valid Information if(isset($_GET['mrn'])) { //STEP 3 Declair Variables $Search = $_GET['mrn']; $Find_Query1 = mysql_query("SELECT DATE_FORMAT(_sfm_form_submision_time_,'%H:%i') TIMEONLY, SBP FROM obs WHERE mrn='$Search' AND _sfm_form_submision_time_=CURRENT_DATE()"); if(!$Find_Query1) { die(mysql_error()); } // STEP 4 Get results while($row = mysql_fetch_assoc($Find_Query1)) { echo '<br/> TIME: '.$row['_sfm_form_submision_time_']; echo '<br/> SBP: '.$row['SBP']; echo '<br/>'; } $numCount = mysql_num_rows($Find_Query1); // STEP 5 error message if no results if ($numCount < 1) { print("no sbp found for that mrn today"); } } ?> Thanks again! M
  3. Hi All! So I’ve never really used SQL or PHP before, this is my first project. The idea is that nurses can search for patients in one table of a hospital database (patients table), and enter new records of their heart rate and blood pressure in a separate database table (observations table). I have managed to set up a database and the tables, and made a search form (searching using MRN, which is the patient's hospital number) which returns the patient details (name, dob, etc...) <?php //STEP 1 Connect To Database $connect = mysql_connect("localhost","jasperss_par1","k_dD6JsB"); if (!$connect) { die("MySQL could not connect!"); } $DB = mysql_select_db('jasperss_par1pats'); if(!$DB) { die("MySQL could not select Database!"); } //STEP 2 Check Valid Information if(isset($_GET['search'])) { //STEP 3 Declair Variables $Search = $_GET['search']; $Find_Query1 = mysql_query("SELECT * FROM patients WHERE mrn LIKE '%$Search%' "); if(!$Find_Query1) { die(mysql_error()); } while($row = mysql_fetch_assoc($Find_Query1)) { echo '<br/> MRN: '.$row['mrn']; echo '<br/> First Name: '.$row['fname']; echo '<br/> Last Name: '.$row['lname']; echo '<br/> Date of Birth: '.$row['dob']; echo '<br/> <a href="http://test.com/nextpage.php?mrn= ' .$row['mrn']>Click here</a>; } echo 'no patients were found'; } ?> There’s a few things I just can’t figure out how to do, although I should imagine it’s fairly straight forward when you know how! Any help or ideas anyone has would be very much appreciated. 1) The database will not record a number which starts with 0! (eg if I save a MRN number as 0001, it just saves as 1). I have tried various field types but can’t seem to do it. Does anyone know if there is a field type that will accept numbers starting with 0? 2) I only want my search to find the record if the exactly correct MRN number is entered. However, if I replace the ‘like’ condition with =, I get no returned results, even if I search for exactly the correct number, I can’t figure out why. 3) Because I only want to display one result, how do I echo ‘multiple results found’ if there is more than one record with the same mrn. 4) I want to link onto the next page, is there some way I can ‘post’ forward some of the data on this page (in order so i can autofill part of the form on the linked page with MRN and name, so the nurses can just fill in heart rate and blood pressure for that patient and submit it to observations table). You can see I have tried to do it by parsing the MRN in the link, but I must have the syntax wrong somewhere because its not working :-(. Thanks very much in advance for any help anyone can give me with this. Matt
  4. Hi all, I have very limited knowledge of HTML and SQL but I’m trying to create a web user interface to allow updating of medical records. The idea is to use an HTML web form to search a SQL database for a record based on a patient number, and return and display the patients name and date of birth, along with another form that can be used to enter a new record for that patient which could then update the database by adding this record. (ie would need to create a new database table with date, time and whatever data was input into the form (say 5 more fields). Im guessing that to do this one would need to pass the data using PHP somehow, but im afraid I don’t have enough knowledge of how. Can anybody help advise me on how to do this? Thanks in advance for any replies, Matt
  5. So I have a site with product categories, sub-cats, sub-sub, sub-sub-sub, and even sub-sub-sub-sub. So each category could be up to 5 levels deep. I want to be able to go to a category page and pull all the categories, and sub-cats this category belongs to, to create a sitemap. The database is structured like: category_id | category_name | parent_id | category_url 1 | Clothes | null | clothes 2 | Shirts | 1 | shirts 3 | Designer Shirts | 2 | designer-shirts So if I was to create a sitemap for Designer Shirts, I would want <a href="index.php">Home</a> >> <a href="clothes">Clothes</a> >> <a href="clothes/shirts">Shirts</a> >> <a href="clothes/shirts/designer-shirts">Design Shirts</a> So I want to do a mysql join that will find me all the categories that belong to the current page, and pull the urls (urls also have the parents urls contained too). And the query has to be useable for any hierachy of the category page.
  6. What I'm doing is dynamically creating a table that automatically calculates the due date (based off of original, single DB entry) and what I need to do NOW is interrupt the loop at a certain point to inject a payment from another table. Here's the code that I have: while($startdate <= $today) { if ($startdate <= $pmt_date) { echo '<tr><td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. date("m.d.Y", $startdate) . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$" . $english_format_number = number_format($row["supportamount"], 2, '.',',') . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>$0.00</center></td>';echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $intacc . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $appint . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $appprinc . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $bal . '</center></td></td>'; $startdate = strtotime('+1 month', $startdate); } else { echo '<tr><td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. date("m.d.Y", $pmt_date) . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>$0.00</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. "$".$english_format_number = number_format($row2["pmt_amt"], 2, '.',',') . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $intacc . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $appint . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $appprinc . '</center></td>'; echo '<td style="border-bottom-color:#3105b0; border-bottom-style:dashed; border-bottom-width:thin;"><center>'. $bal . '</center></td></td>'; } } echo '</table>'; There's only one instance of what is needed being injected working, then it repeated continuously. What I need to do it have it only apply ONCE during that loop... possibly a foreach() statement? If so, how would I do that and have the $pmt_date array automatically generated and how would the table generate?
  7. need to generate the correct format of this report, please advise if what i want is feasible or not. what i want is that at the image below i only want to show a distinct value under Severity, Category 2 and Category 3 columns, meaning there should just be one entry for Severity 3 and Severity 5 under Severity column and same goes for the Category 2 and Category 3 column entries here is the image: below is my SQL statement which generated the image above: $dates = $_POST['dates']; $sql="SELECT DISTINCT trouble_type_priority, category_1, category_2, status FROM tbl_main WHERE resolved_date = '$dates' ORDER BY trouble_type_priority,category_1,category_2"; here is the other part of the code: echo "<table width='150' border=0 align='center'> <tr> <th colspan='2'>Remaining Tickets:</th> </tr> <tr> <th width='72'>Wireless:</th> <th><input type='text' name='WirelessRemaining' id='WirelessRemaining' size='7' /></th> </tr> <tr> <th>Wireline:</th> <th><input type='text' name='WirelineRemaining' id='WirelineRemaining' size='7' /></th> </tr>"; echo "<table width='auto' cellpadding='1px' cellspacing='0px' border=1 align='center'> <tr> <th colspan='3' align='center'>Ticket Bucket</th> <th colspan='3' align='center'>Status</th> </tr> <tr> <th width='auto' align='center'>Severity</th> <th width='auto' align='center'>Category 2</th> <th width='auto' align='center'>Category 3</th> <th width='auto' align='center'>Resolved</th> <th width='auto' align='center'>Re-assigned</th> <th width='auto' align='center'>Closed</th> <th width='auto' align='center'>Grand Total</th> </tr>"; while($info = mysql_fetch_array($myData)) { echo "<form action='report.php' method='post'>"; echo"<tr>"; echo "<td align='center'>" . $info['trouble_type_priority'] . "<input type=hidden name=trouble_type_priority value=" . $info['trouble_type_priority'] . " size='1' maxlength='1' /> </td>"; echo "<td align='center'>" . $info['category_1'] . "<input type=hidden name=category_1 value=" . $info['category_1'] . "' /> </td>"; echo "<td align='center'>" . $info['category_2'] . "<input type=hidden name=category_2 value=" . $info['category_2'] . "' /> </td>"; echo "<td align='center'>" . $info['status'] . "<input type=hidden name=status value=" . $info['status'] . "' /> </td>"; echo "</tr>"; echo "</form>"; } } echo "</table>"; echo "<table width='auto' cellpadding='1px' cellspacing='0px' border=1 align='center'> <tr> <th colspan='3' align='center'>Total</th> <th> </th> <th> </th> <th> </th> </tr>"; echo "</table>";
  8. I am moving my site and database to a new server. The configuration is nearly the same except the new server is 64bit. I can connect to the database remotely with the username and password that I have in my php code to connect. Here is my database connect code: <?php $serverName = 'Nick_C_Desktop\SQLEXPRESS'; $connectionInfo = array('Database'=>'CSLogs', 'UID'=>'cslogslogin', 'PWD'=>'123456'); $connection = sqlsrv_connect($serverName, $connectionInfo); ?> This code worked perfectly fine on my old server, but gives me this error: Fatal error: Call to undefined function sqlsrv_connect() in C:\wamp\www\cslogs\includes\db_connect.php on line 4 I have these two items in my php.ini file enabled: extension=php_pdo_sqlsrv_53_ts.dll extension=php_sqlsrv_53_ts.dll Which is what I had before. Using Wamp Server. PHP 5.3.13 all the same as before. What else am I missing that is not allowing this to connect to the SQL server. Thanks in advance!
  9. need help in generating report from my db, i have a main page which i used to retrieved, delete data from db and i want to add a button that can generate a report. retrieve and delete button is already working, just need to make report generator work as well, because nothing is happening when i click on the Report Generator button, below is my main page code: <script type="text/javascript"> $(document).ready(function(){ $("#RetrieveList").on('click',function() { var xid = $('#XiD').val(); var date = $('#Date').val(); $.post('retrieve_test.php',{xid:xid, date:date}, function(data){ $("#results").html(data); }); return false; }); $("#DeletefromDB").click(function() { if (confirm("Are you sure you want to delete?")) var id = $('input[name=checkbox]:checked').map(function() { return $(this).val(); }).get(); $.post('delete_test.php',{id:id}, function(data){ $("#result").html(data); }); return false; }); }); $("#Report").click(function() { var date = $('#Date').val(); $.post('report.php',{date:date}, function(data){ $("#results").html(data); }); return false; }); </script> <form id="form2" name="form2" method="post" action=""> <table width="741" border="0" align="center"> <tr> <th colspan="9" align="center" style="font-size:14px" scope="col">Xid, Name:<span> <select name="XiD" id="XiD"> <option value="AAA">AAA</option> <option value="BBB">BBB</option> <option value="" selected="selected">Please Select...</option> </select> </span><span style="font-size:14px"> <label for="date">Date:</label> <input type="text" name="Date" id="Date" size="8"/> </span></th> </tr> <tr> <th colspan="9" scope="col"> </th> </tr> <tr> <th colspan="9" scope="col"> <div align="center"> <input name="action" type="button" id="RetrieveList" value="Retrieve List" /> <input name="action" type="button" id="DeletefromDB" value="Delete from DB" /> <input name="Clear" type="reset" id="Clear" value="Clear" onClick="window.location.reload()" /> <input name="action" type="button" id="Report" value="Report Generator" /> </div> <label for="Clear"></label> <div align="center"></div></th> </tr> </table> </form> <div id="results"> </div> while here is my report generator php code which doesn't seem to work: <?php require 'include/DB_Open.php'; $date = $_POST['date']; $sql="SELECT trouble_type_priority, category_1, category_2, status, COUNT (*) AS Total FROM tbl_main WHERE resolved_date = '$date' GROUP BY trouble_type_priority, category_1, category_2, status"; $myData = mysql_query($sql)or die(mysql_error()); echo "<table width='auto' cellpadding='1px' cellspacing='0px' border=1 align='center'> <tr> <th colspan='3' align='center'>Ticket Bucket</th> <th colspan='3' align='center'>Status</th> </tr> <tr> <th width='auto' align='center'>Severity</th> <th width='auto' align='center'>Category 2</th> <th width='auto' align='center'>Category 3</th> <th width='auto' align='center'>Resolved</th> <th width='auto' align='center'>Re-assigned</th> <th width='auto' align='center'>Grand Total</th> </tr>"; while($info = mysql_fetch_array($myData)) { echo"<tr>"; echo "<td align='center'>" . $info['trouble_type_priority'] . "</td>"; echo "<td align='center'>" . $info['category_1'] . "</td>"; echo "<td align='center'>" . $info['category_2'] . "</td>"; echo "<td align='center'>" . $info['status'] . "</td>"; echo "</tr>"; } echo "</table>"; include 'include/DB_Close.php'; ?> here is the image of how i want my report to be generated:
  10. please help, inserting datas from my textfields combined with my textareas to db not working, please help on how to combine my VALUES properly. I cant seem to figure out how to combine the implode for my textareas and the other values from textfields. below is my PHP code: $Category2 = $_POST['Category2']; $Category3 = $_POST['Category3']; $Status = $_POST['Status']; $Date = $_POST['Date']; $Severity = $_POST['Severity']; $BanType = $_POST['BanType']; $XiD = $_POST['XiD']; $Ticket = $_POST['Ticket']; //Process the input textareas into arrays $PhoneNumber = array_map('mysql_real_escape_string', explode("\n", $_POST['PhoneNumber'])); $Createdate = array_map('mysql_real_escape_string', explode("\n", $_POST['Createdate'])); $RemedyTicketNo = array_map('mysql_real_escape_string', explode("\n", $_POST['PhoneNumber'])); //Determine the values with the least amoutn of elements $min_count = min($PhoneNumber, $Createdate, $RemedyTicketNo); //Create array to hold INSERT values $values = array(); //Create the INSERT values for($index=0; $index<$min_count; $index++) { $values[] = "('{$PhoneNumber[$index]}', '{$Createdate[$index]}', '{$RemedyTicketNo[$index]}')"; } if (isset($RemedyTicketNo)) { $sql="INSERT into tbl_main (ars_no, phone_number, category_1, category_2, status, create_date, resolved_date, trouble_type_priority, ban_type, employee_id_name) VALUES ('" . implode (', ', $values) ."', '".$Category2."', '".$Category3."', '".$Status."', '".$Date."', '".$Severity."', '".$BanType."', '".$XiD."')"; $result=mysql_query($sql); header("Location: smp_backend_test.php"); }
  11. I have 2 tables that I want to compare and find the users that the username is not following and then display the username of the person not being followed. Table 1: users Table 2: follow In my head I see table 1 getting a list of all the usernames (column name is "username" from table 1) and then gets a list of all the usernames the user ($username) is not following (column name is "followname" from table 2). How do I make it compare the two lists and not display the usernames the user is following already? Table two is set up like so: (username) (User they follow) username followname derekshull dvdowns derekshull testuser testuser dvdowns Here's what I have so far. It's displaying users, but it's displaying users I follow and don't follow. Weird. $alluserslookup = mysql_query("SELECT * FROM users WHERE username!='$username'"); $thefollowerslookup = mysql_query("SELECT * FROM follow WHERE username='$username'"); while ($followersrow = mysql_fetch_assoc($thefollowerslookup)) { $afollower = $followersrow['followname']; while ($allusersrow = mysql_fetch_assoc($alluserslookup)) { $allusers = $allusersrow['username']; if ($afollower != $allusers) { echo "<a href='viewprofile.php?viewusername=$allusers'>$allusers</a><br>"; } } }
  12. Hi all! I am new so don't hate if I write something in a bad way. Thanks. I have a "logical captcha" which is like a quiz. Here is my code. I don't know what is wrong with it <?php $database_db="general"; $user_db="root"; $password_db="somepass"; $host_db="localhost"; $link = mysqli_connect($host_db, $user_db, $password_db, $database_db); if (mysqli_connect_errno()) { die ("couldnot connect: ".mysqli_connect_error()); exit(); } $answer = $_POST['answer']; if (array_key_exists("answer", $_POST) AND array_key_exists("question", $_POST)) { $id = intval($_POST['question']); $sql="SELECT question, answer FROM captcha WHERE question='$id' AND answer='".mysqli_real_escape_string($link, $answer)."'"; $result = mysqli_query($link, $sql) or exit('$sql failed: '.mysqli_error($link)); $num_rows = mysqli_num_rows($result); if($num_rows > 0) { header("Location: success.php"); } else { header("Location: error.php"); } exit; } else { $query = "SELECT id, question FROM `captcha` ORDER BY RAND() LIMIT 1"; if ($result = mysqli_query($link, $query)) { if ($row = mysqli_fetch_assoc($result)) { $id = $row["id"]; $question = $row["question"]; } } } ?> <html> <body> <form method="post"> <?php echo $question; ?><br /> <input type="hidden" name="question" id="question" value="<?php echo $id; ?>" /> <input type="text" name="answer" id="answer" /><br /> <input type="submit" name="submit" value="submit" /><br /> </form> </body> </html> So the problem is that it always redirects to error.php, even if I enter the right answer
  13. Hi, I'm in the middle of constructing my registration and login form and I keep getting this error when I try to process the login. Here's the error I'm getting: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'firstname' cannot be null Here's the PHP code: <?php class Users { public $firstname = null; public $lastname = null; public $username = null; public $email = null; public $password = null; public $salt = "Zo4rU5Z1YyKJAASY0PT6EUg7BBYdlEhPaNLuxAwU8lqu1ElzHv0Ri7EM6irpx5w"; public function __construct( $data = array() ) { if( isset( $data['username'] ) ) $this->username = stripslashes( strip_tags( $data['username'] ) ); if( isset( $data['password'] ) ) $this->password = stripslashes( strip_tags( $data['password'] ) ); } public function storeFormValues( $params ) { $this->__construct( $params ); } public function userLogin() { $success = false; try{ $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $sql = "SELECT * FROM members WHERE username = :username AND password = :password LIMIT 1"; $stmt = $con->prepare( $sql ); $stmt->bindValue( "username", $this->username, PDO::PARAM_STR ); $stmt->bindValue( "password", hash("sha256", $this->password . $this->salt), PDO::PARAM_STR ); $stmt->execute(); $valid = $stmt->fetchColumn(); if( $valid ) { $success = true; } $con = null; return $success; }catch (PDOException $e) { echo $e->getMessage(); return $success; } } public function register() { $correct = false; try { $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $sql = "INSERT INTO members(firstname, lastname, username, email, password) VALUES(:firstname, :lastname, :username, :email, :password)"; $stmt = $con->prepare( $sql ); $stmt->bindValue( "firstname", $this->firstname, PDO::PARAM_STR ); $stmt->bindValue( "lastname", $this->lastname, PDO::PARAM_STR ); $stmt->bindValue( "username", $this->username, PDO::PARAM_STR ); $stmt->bindValue( "email", $this->email, PDO::PARAM_STR ); $stmt->bindValue( "password", hash("sha256", $this->password . $this->salt), PDO::PARAM_STR ); $stmt->execute(); return "Registration Successful <br/> <a href='index.php'>Login Now</a>"; }catch( PDOException $e ) { return $e->getMessage(); } } } ?> My database layout is as follows Field Type Null Default Comments user_id int(11) No firstname varchar(50) No lastname varchar(50) No username varchar(50) No email varchar(50) No password var(250) No Indexes: Keyname Type Cardinality Field PRIMARY PRIMARY 0 user_id username UNIQUE 0 username email UNIQUE 0 email
  14. Hello all, I'm having a bit of a problem with my code here. I'm trying to allow the user to enter a number (an office number) from a database, and based on that value, after submitting it, an html table will fill with the appropriate results (lastName, firstName, jobTitle). For whatever reason, though, I keep getting this error: "Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in... <website name> <line number>" It's very weird, because I'm doing this straight from notes / w3 and I'm still getting errors. I'm still new to this, so I'm sorry if I'm sounding completely inexperienced... well I am haha. Anyway, here's the code: <!DOCTYPE html > <html lang ="en"> <head> <title> Homepage </title> </head> <body bgcolor="gray"> <h1 align=middle> Welcome to the Site </h1> <?php DEFINE ('DB_USER', '*******); DEFINE ('DB_PASSWORD', '******'); DEFINE ('DB_HOST','*****'); DEFINE ('DB_NAME','******'); $dbc = @mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME) or die ('Could not connect to MySQL: '.mysqli_connect_error($dbc) ); mysqli_set_charset($dbc, 'utf8'); //$r = @mysqli_query($dbc, $q); ?> <form action ="Homepage.php" method="get"> Enter Office Code: <input type="text" name="oCode" id="OfficeCode" maxlength="15"> <input type="submit" name="formSubmit" value="Submit"> </form> <? $code = $_GET['oCode']; $result = mysqli_query($dbc, "select lastName, firstName, jobTitle from Employees where OfficeCode='$code'"); echo "<table border='1'>"; echo "<tr>"; echo "<th>LastName</th>"; echo "<th>FirstName</th>"; echo "<th>Job Title</th>"; echo "</tr>"; while ($row = mysqli_fetch_array($result)) //this is where I'm getting the error { echo "<tr>"; echo "<td>" . $row['lastName'] . "</td>"; echo "<td>" . $row['firstName']. "</td>"; echo "<td>" . $row['jobTitle'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($dbc); ?> Any help would be great. Thank you!
  15. ok i created this to add a user to follow list if(Params::getParam('follow')!='') { if(osc_logged_user_id()!='') { $fav = $conn->osc_dbFetchResult("SELECT * FROM %st_follow WHERE fk_i_seller_id = %d AND fk_i_user_id = %d", DB_TABLE_PREFIX, Params::getParam('follow'), osc_logged_user_id()); if(!isset($fav['fk_i_user_id'])) { $conn->osc_dbExec("INSERT INTO %st_follow (`fk_i_user_id`, `fk_i_seller_id`) VALUES (%d, %d)", DB_TABLE_PREFIX, osc_logged_user_id(), Params::getParam('follow')); } } } now i need something to remove user from same list, im new to php and mysql so i tried something like this but it doesnt work if(Params::getParam('unfollow')!='') { if(osc_logged_user_id()!='') { if(!isset($fav['fk_i_user_id'])) { $conn->osc_dbExec("DELETE FROM %st_follow fk_i_user_id = %d AND fk_i_seller_id = %d LIMIT 1", DB_TABLE_PREFIX, osc_logged_user_id(), Params::getParam('unfollow')); } } } can someone please help me make it work, thank you so much.
  16. Hi all, Okay, I'll try to explain briefly but thoroughly on what I'm trying to do. FYI I have a general working knowledge of PHP & mySQL, and use Dreamweaver and it's built-in tools regularly. I have a registeration form, which gives the option to register into 4 age groups (via a radio button), which just submits as text into the database. What I am looking to be able to do is "Show If" (I think?) a disabled="true" to disable a radio button, once a certain amount of records have been submitted for a specific group. So I'm assumming the way to do this is to call up the full list from the database (not very many entries) and check if the limit of 15 per age group is reached? Let me know if that makes sense, any if you can give me any guidance. It will be much appreciated! Also, if you have the time to explain your coding to me too, so I can learn from it, that would be great! --EVP
  17. <?php //session status block include "connect_to_mysql.php"; ?> <?php //script error reporting //error reporting error_reporting(E_ALL); ini_set('display_errors','1'); ?> <?php //parse form data to database //parse the form data and add inverntory items to the system //CHANGE ALL VALUES TO SUIT NEEDS OF CURRENT DATABASE //FORM DATA AND ADD BOOK TO THE SYSTEM DATABASE if (isset($_POST['BOOKNAME'])) { $BOOKNAME = mysql_real_escape_string($_POST['BOOKNAME']); $BOOKPRICE = mysql_real_escape_string($_POST['BOOKPRICE']); $CATEGORY = mysql_real_escape_string($_POST['CATEGORY']); $BOOKDESCRIPTION = mysql_real_escape_string($_POST['BOOKDESCRIPTION']); // See if that product name is an identical match to another product in the system $sql = mysql_query("SELECT ID FROM BOOK WHERE BOOKNAME='$BOOKNAME' LIMIT 1"); // Add this product into the database now $sql = mysql_query("INSERT INTO BOOK (BOOKNAME, BOOKPRICE, BOOKDESCRIPTION, CATEGORY, DATE) VALUES('$BOOKNAME','$BOOKPRICE','$BOOKDESCRIPTION','$CATEGORY',now())") or die (mysql_error()); $pid = mysql_insert_id(); // Place image in the folder $newname = "$pid.jpg"; move_uploaded_file( $_FILES['fileField']['tmp_name'], "inventory_images/$newname"); echo 'Book Successfully Uploaded <a href="index.php"><b>Click Here To Go To Home Page</b></a>'; exit(); } ?> <?php //this block grab the whole list for viewing //THIS BLOCKS GRABS THE WHOLE LIST FOR VIEWING $product_list = ""; $sql = mysql_query("SELECT * FROM BOOK ORDER BY date_added DESC"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $ID = $row["ID"]; $BOOKNAME = $row["BOOKNAME"]; $CATEGORY = $row["CATEGORY"]; $BOOKDESCRIPTION = $row["BOOKDESCRIPTION"]; $BOOKPRICE = $row["BOOKPRICE"]; $product_list = "Product ID: $ID - <strong>$BOOKNAME</strong> - $$BOOKPRICE - <em>Added $date_added</em> • <br />"; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); } } else { $product_list = "There are currently no books for sale, check back soon !"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>NTU Book Browser</title> <link rel="stylesheet" href="style.css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> $(function() { $("#text-one").change(function() { $("#text-two").load("textdata/" + $(this).val() + ".txt"); }); }); </script> </head> <body> <div id="wrapper"> <?php include_once("template_header.php");?> <div id="wrapper_content"> <div id="headers"> <h2> Books </h2> </div> <div id="main"> <div id="add_item"> <p><i> <a href="books.php#bookForm">+Sell Book</a></i></p> </div> <?php echo $product_list; ?> <a name="bookForm" id="bookForm"></a> <h3> Add New Book Form </h3> <form action="books.php" enctype="multipart/form-data" name="myForm" id="myform" method="post"> <table width="90%" border="0" cellspacing="0" cellpadding="6"> <td align="right">Book Name</td> <td><select name="CATEGORY" id="text-one"> <option selected value="base">Select Book Category</option> <option value="biomedicalscience">Biomedical Science</option> <option value="history">History</option> <option value="spanish">Spanish</option> <option value="economics">Economics</option> <option value="sportsscience">Sports Science</option> <option value="forensicsscience">Forensics Science</option> <option value="computersystems">Computer Systems</option> <option value="english">English</option> <option value="psychologyandeducation">Psychology and Education</option> </select> </td> <br /> <td align="right"></td> <td> <select name="BOOKNAME" id="text-two"> <option>Select Book</option> </select> </td> </tr> <tr> <td align="right">Book Price</td> <td><label> £ <input name="BOOKPRICE" type="text" id="BOOKPRICE" size="12" /> </label></td> </tr> <tr> <tr> <tr> <td align="right">Book Description</td> <td><label> <textarea name="BOOKDESCRIPTION" id="description" cols="64" rows="5"></textarea> </label></td> </tr> <tr> <td align="right">Book Image</td> <td><label> <input type="file" name="fileField" id="fileField" /> </label></td> </tr> <tr> <td> </td> <td><label> <input type="submit" name="button" id="button" value="Add Book" /> </label></td> </tr> </table> </form> </div> <div id="footer"> <?php include_once("template_footer.php");?> </div> </div> </div> <div class="clear"></div> </body> </html>
  18. I have the query below which works great. Alls I want to do is all the projects from the query grouped by the description. $query_rs_installs = "SELECT Calls.Call_Ref, Calls.Link_to_Contract_Header, Calls.Order_No, Calls.Date_Received, Calls.Scheduled_Date_Time, Clients.Co_Name, Clients.Post_Code, LU_Call_Types.Call_Type_Description, LU_Call_Types.Type_Band, LU_Call_Status.Call_Status_Description, LU_Company_Types.Company_Type_DescriptionFROM { oj (((Siclops_Dispense.dbo.Calls Calls INNER JOIN Siclops_Dispense.dbo.LU_Call_Types LU_Call_Types ON Calls.Call_Type = LU_Call_Types.Call_Type_Code) INNER JOIN Siclops_Dispense.dbo.LU_Call_Status LU_Call_Status ON Calls.Last_Event_Status = LU_Call_Status.Call_Status_Code) INNER JOIN Siclops_Dispense.dbo.Clients Clients ON Calls.Link_to_Client = Clients.Client_Ref) LEFT OUTER JOIN Siclops_Dispense.dbo.LU_Company_Types LU_Company_Types ON Clients.Company_Type = LU_Company_Types.Company_Type_Code}WHERE Calls.Link_to_Contract_Header = '".$row_rs_member['companyident']."' AND (LU_Call_Types.Type_Band = 'Project' OR LU_Call_Types.Type_Band = 'Project Complete' OR LU_Call_Types.Type_Band = 'Project Invoiced') AND (LU_Call_Status.Call_Status_Description = 'Reported Done' OR LU_Call_Status.Call_Status_Description = 'PTF Rep Done' OR LU_Call_Status.Call_Status_Description = 'Proforma Sent' OR LU_Call_Status.Call_Status_Description = 'Paperwork Recvd' OR LU_Call_Status.Call_Status_Description = 'In Query' OR LU_Call_Status.Call_Status_Description = 'Cryo PW Sent' OR LU_Call_Status.Call_Status_Description = 'Complete' OR LU_Call_Status.Call_Status_Description = 'Awaiting P/work' OR LU_Call_Status.Call_Status_Description = 'Awaiting Invoic' OR LU_Call_Status.Call_Status_Description = 'Await TB Return' OR LU_Call_Status.Call_Status_Description = 'ApplicationSent')GROUP BY LU_Call_Status.Call_Status_Description"; Now before the group by the query works fine. As soon as i write it in the query fails completely. I have also tried selecting distinct and unique on the same field but each time I write them in it fails. I believe this maybe because this is an MS SQL query and as such I may have the syntax wrong. Any ideas? Thanks guys
  19. Hi, I'm just wondering but how would I go about making a query so that I can fetch two valid pieces of information and display them? So In this case I would like to query my database to find the correct Firstname and Lastname of that use through their session? Here's something I made, it works! But it only fetches the first result and doesn't return the correct name for the correct user. <?php if ($stmt = $mysqli->prepare("SELECT id, firstname, lastname FROM users WHERE id LIMIT 1")) { $stmt->execute(); $stmt->store_result(); $stmt->bind_result($user_id, $firstname, $lastname); $stmt->fetch(); if($stmt->num_rows == 1) { $_SESSION['user_id'] = $user_id; $_SESSION['firstname'] = $firstname; $_SESSION['lastname'] = $lastname; echo $firstname; echo ' '; echo $lastname; } } ?> So at this point it's displaying two names but they are the first record in my database and it's not displaying the correct name for the correct user so for example.: I'm user 6 in the database with the name John Doe but it's displaying record 1 in the database which is Luke Void, basically I want it so when John Doe logs into his account, it says on the screen 'John Doe', so it matches the correct client. Help on this one please, I'm kind of newish to databases... thanks
  20. Im developing a site a that has login function, i have about 5 users with different user id. The problem is the code im using logs all the users as the first user in my database table, this means im essentially logged in as a another user. // function that gets users id from table users function user_id_from_username( $username ){ $username = sanitize( $username ); // do the query first $result = mysql_query( "SELECT user_id FROM users WHERE username = '$username'" )or die("Could not perform select query - " . mysql_error());;;; // if there was an error, or no results, $result will be FALSE. // if $result is not false, then you know there was a row returned $num_rows = mysql_num_rows($result); if($num_rows == 1) { return true; } else { return false; } } // function that checks the credentials and should return the correct user_id. function login($username, $password) { $user_id = user_id_from_username($username); $username = sanitize($username); $password = ($password); $query = mysql_query("SELECT COUNT(`user_id`) FROM guys WHERE username='$username' AND password='$password'"); return (mysql_result($query, 0) == 1) ? $user_id : false; } // finally logging the user and redirecting $login = login($username, $password); if ($login == false) { $errors[] = 'This username and password combination is incorrect'; }else { $_SESSION ['user_id'] = $login; header ('Location: index.php'); exit(); } function logged_in() { return (isset($_SESSION['user_id'])) ? true : false; } How can i log in the others users with the correct user id, and not just the first user ?
  21. I have a variable called $sqlCommand , variable is listed twice with two different values. the first $sqlCommand is holding a value of creating a table called page the second $sqlCommand is holding a value of create a table called blog As you can see in the code below : // Create the table 1 for storing pages $sqlCommand = "CREATE TABLE pages ( id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, page_title VARCHAR(255), page_body TEXT, page_views INT NOT NULL default '0', FULLTEXT (page_title,page_body) ) ENGINE=MyISAM"; $query = mysql_query($sqlCommand) or die(mysql_error()); echo "<h3>Success creating Pages table</h3>"; // Create the table 2 for storing Blog entries $sqlCommand = "CREATE TABLE blog ( id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, blog_title VARCHAR(255), blog_body TEXT, blog_views INT NOT NULL default '0', FULLTEXT (blog_title,blog_body) ) ENGINE=MyISAM"; $query = mysql_query($sqlCommand) or die(mysql_error()); echo "<h3>Success creating Blog table</h3>"; My question is how is php reading this as two separate values ?? they both seem to be declared in a global fashion , yet when they are inputted into the $query function they both are produced separately ? anybody know the reason for this ? thanks.
  22. Hi, I'm just wondering but if my webhost has SQL version 5.1, what are the syntax of that for PHP login & register forms? So like $q = "INSERT INTO `Table1` (`username`,`password`,`email`) " ."VALUES ('".$_POST["username"]."', " ."PASSWORD('".$_POST["password"]."'), " ."'".$_POST["email"]."')"; Would this be the right use of syntax? I'm having a few problems with making a clean and safe php login and register form. Thanks.
  23. suppose i've one starting data(1/12/2013) and final date (26/12/2013). What i want is that to update the database with the difference between the dates every day... means start data | Final Data | Days Left 1/12/2012 | 26/12/2012 | 25 <-------------- automatically done every day and updated in the database over writing the original values Means after 2 days it will show start data | Final Data | Days Left 1/12/2012 | 26/12/2012 | 23 Any help will be greately appreciated.....
  24. im trying to make a script where the user can update there details, (in this case the email) but when the script is running it comes up sucess to say its worked and updated. however when i open up my database in notepad or sql workbench the email has not changed its still the same. any ideas what it could be? or maybe im reading my database info wrong? CODE: <?php session_start(); $user_name = "root"; $password = ""; $database = "fixandrun"; $server = "localhost"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); $currentemail = $_POST['currentemail']; $newemail = $_POST['newemail']; $confirmnew = $_POST['confirmemail']; $user = $_SESSION["username"]; if ($db_found) { $dbemail =mysql_query("SELECT email FROM staff WHERE username= '$user'"); //echo "$currentemail"; //echo "$newemail"; //echo "$confirmnew"; //echo "$dbemail"; if($currentemail == $dbemail || $newemail == $confirmnew) { $query = "UPDATE staff SET email = '$confirmnew' WHERE username = '$user'"; if(mysql_query($query)){ echo "updated";} else{ echo "fail";} } else { echo" some of your details are incorrect please try again. check that your current email is entered correctly and the new email matches."; } } else { print "Database NOT Found."; mysql_close($db_handle); } ?>
  25. Hi. im new to the site and i need a bit of help. im coding a website for my coursework and ive created a log in script. the script works but once the user has logged in i want to get a message saying welcome "firstname" instead of welcome "username" i have managed to get it to say welcome and there username but its not very formal i would like there name they use when they register. here is the code ive got so far. any help would be greatly appriciated. <?php session_start(); $user_name = "root"; $password = ""; $database = "fixandrun"; $server = "localhost"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); $username = $_POST["username"]; $password = $_POST["password"]; echo"$password"; echo"$username"; if ($db_found) { $result =mysql_query("SELECT 1 FROM staff WHERE username= '$username' and password= '$password'"); if ($result && mysql_num_rows($result) == 1) { $sqlq = mysql_query("SELECT firstname FROM staff WHERE username = '$username'"); $_SESSION['name']=$sqlq; session_register("username"); header("location:homelogged.php"); } else { Echo "Username or Password is incorrect. Click <a href='home.php'>Here</a> to be taken back to the home page."; } } else { print "Database NOT Found."; mysql_close($db_handle); } ?> and on my home page i have : <?php echo "Welcome " . $_SESSION["name"] . "<br>"; echo "last logged in at " . date("l, F d, h:i" ,time())."<br>"; ?> this works but i get welcome and 0 instead of welcome and a name
×
×
  • 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.