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. Im trying to connect to it with this code; <?php mysql_connect("localhost", "root", "root") or die("Error connecting to database: ".mysql_error()); mysql_select_db("playerSearch") or die(mysql_error()); ?> but i get this error; Unknown database 'playersearch' any help?
  2. Hello, I am doing a kind of financial calculator which gives you results about the best alternatives to choose from. I do a sql query to the table having the banks data. After that i create a bunch of variables in php and echo the results. These variables are math operations consisting in sql results variables and user input variables. I know how to order sql results, but the problem is that my criteria of sorting is from the php variables created later (which consist of math oparations between sql and user input variables). I have tried sorting it by sql rows....but the dynamic php variables created later are sometimes negatively related to the sql data....so the result does not always get the same. I have an idea like putting the dynamic php variables in an array/arrays and than sorting them according to one of the php variables. But i have no idea how it can be done. Here is a partial code, just to give you an idea of what i mean. <form method="post" action="calc2.php" /> <input name="ss" class="highlight"/> <input class="highlight" name="nn" size="5" /> </form> <?php if (isset($_POST['ss']) && $_POST['nn']>5) { $target = $_POST['ss']; $result = mysql_query("SELECT * FROM list1 WHERE minimum <= {$target} ORDER BY i_rate DESC LIMIT {$number_result}"); if (mysql_num_rows($result) > 0){ while($row = mysql_fetch_array($result)) { $s = $target-$support+$pu+$pv; // according to this variable i want to sort the results, and $pu, $pv are created from user input, which i don't have it here, $traget is sql output. $s is a mix. } } } ?> PLS HEEELP, i have searched everywhere for this and cennot find nothing about exactly what i want.
  3. Ok, i think this is the best place for this question. I have the following problem that no matter what i do the number doesn't add to the sql variable. $i=interest rate, which is a row in sql database, i need to add 1 to it. The result is 1. Which should have been for example 1.01 if $i=1. Here is the code: $result1 = mysql_query("SELECT interest_rate FROM list1") or die(mysql_error()); $row1 = mysql_fetch_array($result1); $i = $row1['interest_rate']; echo $i . "<br/>"; echo $i+1 . "<br/>"; On echo $i i get the row values. On $i+1 i get only 1 in a column repeated vertically. WHY?? PLSSSSS help!!!!
  4. Hi all, this my first post. I'd like to insert values of checkboxes as a string using a comma as a delimiter. So I have these checkboxes: <input type="checkbox" class="checkbox" name="box[]" value="1">One</input> <input type="checkbox" class="checkbox" name="box[]" value="2">Two</input> <input type="checkbox" class="checkbox" name="box[]" value="3">Three</input> Then I'd have a code like this, which is obviously wrong hence I wrote it for illustration only, it should also have an explode function for the delimiter: if (isset($_POST['box'])) { $newbox = array(); foreach($_POST['box'] as $boxArr){ array_push($newbox, $boxArr); } $query="INSERT INTO boxesTable (boxes) VALUES ('$newbox')"; } Any help would be much appreciated.
  5. Hello i am getting this error message, please help me to correct it : Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table (id, name, description, linkdown, pubsite, category, image, os) VALUES ('' at line 1 The code is as follows : <?php /// In order /// you /// information in this file: /// Copyright 2012 /// All rights reserved. include("connect.php"); $name = trim(mysql_real_escape_string($_POST["name"])); $description = trim(mysql_real_escape_string($_POST["description"])); $linkdown = trim(mysql_real_escape_string($_POST["linkdown"])); $pubsite = trim(mysql_real_escape_string($_POST["pubsite"])); $category = trim(mysql_real_escape_string($_POST["category"])); $image = trim(mysql_real_escape_string($_POST["image"])); $os = trim(mysql_real_escape_string($_POST["os"])); $results = mysql_query("INSERT INTO table (id, name, description, linkdown, pubsite, category, image, os) VALUES ('', '$name', '$description', '$linkdown', '$pubsite', '$category', '$image', '$os')"); if($results) { echo "Successfully Added"; } else { die('Invalid query: '.mysql_error()); } ?> <a href="index.php">Back to index</a>
  6. I need help with this php survey script. It's supposed to check and see if there are any usernames that are already in the system and if there are then it just adds the values "voted" and "total" to the existing values that are there. If the username is not in the database it will insert that name and add the values. What I have right now is this: $workerusername=$_POST['workerusername']; $q1=$_POST['question1']; $q2=$_POST['question2']; $q3=$_POST['question3']; $values = $q1 + $q2 + $q3; mysql_query("INSERT INTO survey (username, voted, total) VALUES ($workerusername, $values, '30') ON DUPLICATE KEY UPDATE `voted` = $values + VALUES(`voted`), `total` = 30 + VALUES(`total`)"); What am I doing wrong? My primary key in the database is ID and then I have username, voted, and total as varchar.
  7. I've only been learning php for two weeks so please excuse my ignorance, I would like to store an array of data from a mysql table in a variable to be called as and when its needed in my script. i have written this function and used a vardump just to check wether the function was working: function getquestions($id) { $sql =mysql_query("select text FROM questions WHERE quiz_ID =$id "); while($row = mysql_fetch_array($sql)) { var_dump($row) ; } } ///Actual code $quizid = get_id("quizName", "ID"); $questionid = get_id("questions","quiz_ID"); if ($quizid == $questionid) { $question = getquestions("1"); } BUT my array lists all of my row values twice like this: array(2) { [0]=> string(68) "The ‘Sea Swallow’ is an alternative name for which bird?" ["text"]=> string(68) "The ‘Sea Swallow’ is an alternative name for which bird?" } array(2) { [0]=> string(58) "In which sport would you see a ‘Western Roll’?" ["text"]=> string(58) "In which sport would you see a ‘Western Roll’?" } array(2) { [0]=> string(53) "Who is better known as ‘Herbert Khaury’?" ["text"]=> string(53) "Who is better known as ‘Herbert Khaury’?" } array(2) { [0]=> string(42) "'Diet' is the parliament of which country?" ["text"]=> string(42) "'Diet' is the parliament of which country?" } array(2) { [0]=> string(43) "What is the real first name of Coco Chanel?" ["text"]=> string(43) "What is the real first name of Coco Chanel?" } array(2) { [0]=> string(43) "'The Aztecs' were natives of which country?" ["text"]=> string(43) "'The Aztecs' were natives of which country?" } array(2) { [0]=> string(54) "What was invented by‘O.A. North’ in 1869?" ["text"]=> string(54) "What was invented by‘O.A. North’ in 1869?" } array(2) { [0]=> string(40) "King Zog was the ruler of which country?" ["text"]=> string(40) "King Zog was the ruler of which country?" } I'd appreciate any explanation on how i stop this.
  8. I have an html form that takes a date and send it to an php script: <form action='tupdatecompletiondate.php' method='post'><input type='hidden' name='idtosubmit' value=$id><tr> <td><label>Date:</label></td> <td><input type= 'date' name= 'date' value='Select Date' id='popupDatepicker'></td> </tr><input type='submit' value='Click to Update'></form> I've got it going to this script: $id = $_POST['idtosubmit']; $date = $_POST['date']; $datetoset = date('Y-m-d', strtotime($date)); $sql = "UPDATE needs SET completiondate=$datetoset WHERE ID=$id"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } mysql_close(); Confused as to why it's not working. It takes the date, sends it to the php script, makes it into a format that is accepted by the DATE column, and then puts it in that column....well at least its supposed to.
  9. I have a script that I need some help with. Its a reminder script (posted below). Basically I have a completiondate (which in the database is a varchar...don't know if that makes a difference) that is made up like day, month, year (Ex: 06102012) and I want the script (which is a cron job) to look at todays date and see if it is 2 days before todays date. If it is then I want an email sent. I'm confused on where I'm going wrong. Please help! Thanks. An example would be: Todays date is: 06102012 If completiondate = 2 days before todays date { send email } $todaysdate = date('d/m/Y'); $query = "SELECT completiondate FROM needs WHERE completiondate =($todaysdate, strtotime('-1 days'))"; $result = mysql_query($query); mail('[email protected]', 'Important Stuff', 'Hey there.'); ?>
  10. my question now is everything is working like my template and the content all i want is to include keywods description and title for each page different it is giving me headache i have a database name pages it has 6 columns id,name,title,description,keywords ,status.where name=home,about,contact etc <?php // Set document: include ('config/setup.php'); if(!isset($_GET['page'])) { $pg= 'page'; }else{ $pg= $_GET['page']; } ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>help</title> <meta name="description" content="." /> <meta name="keywords" content=" " /> </head> <body> <!-- Header Start --> <div id="logo"> <a class="logo" =pic"> <div class="right"> <?php include('template/right_logo.php');?> </div> </div> <div id="header"> <?php include('template/header.php');?> </div> <!-- Header End --> <!-- Main Start --> <div id="main"> <!-- ### Main Left Start ### --> <div id="left"> <?php //include('content/'.$pg.'.php'); $q="SELECT*FROM pages WHERE name='$pg' "; $r=mysqli_query($dbc,$q); $page= mysqli_fetch_assoc($r); echo '<div class="content_body">'.$page['body'].'</div>'; ?> </div> <!-- ### Main Left End ### --> <!-- ### Main Rigt Start ### --> <div id="right"> <?php include('template/right.php');?> </div> <!-- ### Main Rigt End ### --> <div class="clear"></div> <div id="footer"> <?php include('template/footer.php');?> </div> </div> </div> <!-- Main End --> </body> </html>
  11. Hi all,,, i have to hide a column(LOCATION) that may not be seen for user level 3 or below i have like this ID Name Location Sex , , , | | | | | | | | how to do it ,,, any one would like to help me please ??? Thank you ,,,
  12. I have a problem in connecting the wampp localhost to sql server , There is a lan network that it`s server is windows server 2008 with sql server 2008 , I want to connect to this sql by php in a client with windows 7 , but when I run mssql_connect function It shows that coudlent connect to this IP , It shows Reply when I ping server IP . Do I have to change anything in wampp or php application in localhost ? It is php 5.3 the latestversion of wampp . Other programmers can connect to this sql by C sharp and Delphi , Only me cant access that by php I use VmWare also , and install windows server 2008 and sql server 2008 , and create network between win7 and windows server by NAT , even in this way I cant access to sql by php , but there is reply in pinging servers IP .
  13. I am creating a scheduling script in PHP from a mySQL database. My problem can be explained with the following example. I have 10 appointment cells in day x (0-9). Each appointment cell has an adjacent corresponding cell to describe whether the appointment is available or not (either 0 or 1...and call this NID). I will need to identify whether appointment t, t+1, t+2 and t+3 are all available. In other words, some appointments will require multiple time slots. How can I filter through the dumped sql data with PHP by looking at the NID and checking whether t, t+1, t+2, t+3 are available? I've tried enumerating the time slots and putting them in arrays but can't figure this one out. Thanks for any ideas
  14. <body> <div class="header"> <?php include('navbar.php'); ?> </div> <div class="container"> <div class="row mt-4"> <div class="col-sm-3"> <p>Patient Name :</p> </div> <div class="col-sm-3"> <p><?php echo $_POST['name']; ?></p> </div> </div> <div class="row" id="fir"> <div class="col-sm-3"> <p>UHID :</p> </div> <div class="col-sm-3"> <p><?php echo $_POST['id']; ?></p> </div> </div> <?php $_SESSION['p_name'] = $_POST['name']; $_SESSION['p_id'] = $_POST['id']; ?> <form action="personal_medical_record_download.php" method="POST"> <div class="form-header mt-4 text-center">Medical Record</div> <div class="card"> <div class="card-header"> <h2>Any Allergies</h2> </div> <div class="card-body"> <?php $uhid = $_SESSION['p_id']; $conn = mysqli_connect("127.0.0.1", "root", "iMpAcTHeaLTH7%", 'threephih'); $query = " Select * from allergies where uhid = '$uhid' "; $query_res = mysqli_query($conn, $query); while ($query_run = mysqli_fetch_array($query_res)) { ?> <div class="form-group"> <label for="1">1. Are you allergic to any substance?</label> <p style="margin-left: 25px"><?php echo $query_run['ques_1']; ?></p> </div> <div class="form-group"> <label for="2">2. What happened to you when you took this substance?</label> <p style="margin-left: 25px"><?php echo $query_run['ques_2']; ?></p> </div> <div class="form-group"> <label for="3">3. When was this reaction?</label> <p style="margin-left: 25px"><?php echo $query_run['ques_3']; ?></p> </div> <div class="form-group"> <label for="4">4. Since when have you taken that substance?</label> <p style="margin-left: 25px"><?php echo $query_run['ques_4']; ?></p> </div> <div class="form-group"> <label for="5">5. Any other kind of allergies?</label> <p style="margin-left: 25px"><?php echo $query_run['ques_5']; ?></p> </div> <?php } ?> </div> </div> <div class="submit-button mt-4 text-center"> <button type="submit" value="Pdf" name="pdf">PDF</button> </div> </form> </div> </body> I'm trying to show that "No records" message when there are no data in sql table but if there is data then go to the pdf page. please help me
  15. Hello I have this error it appears between all pages while I am navigating from one page to another, this error appears and disappears immediately, but it appears and remains present when viewing sales reports page. /*--------------------------------------------------------------*/ /* Function for checking which user level has access to the page /*--------------------------------------------------------------*/ function page_require_level($require_level){ global $session; $current_user = current_user(); $login_level = find_by_groupLevel($current_user['user_level']); //if user not login if (!$session->isUserLoggedIn(true)): $session->msg('d','Please Sign in'); redirect('index.php', false); //if Group status Deactive elseif($login_level['group_status'] === '0'): //Line 195 $session->msg('d','User Banned'); redirect('home.php',false); //checking logged in User level and Require level is Less than or equal to elseif($current_user['user_level'] <= (int)$require_level): return true; else: $session->msg("d", "Error"); redirect('home.php', false); endif; }
  16. Hi, I running a query that groups merge.Description where the StoreId is the same, and replacing the comma with a line break. The problem I'm getting is the string only returns 1023 character's and I need it to return more? Any help would be great Cheers $rows = mysql_query("SELECT REPLACE(GROUP_CONCAT(merge.Description), ',', CHAR(13)) FROM merge GROUP BY merge.StoreId");
  17. I'm trying to show a profile completeness bar on the users account and the progress bar is showing but it's not adding the number values in order to calculate the percentage of completed fields ie: if($row['title'] != '') $completedTitle = 20; My shortened code is as follows: <?php $result = mysql_query("SELECT title,name,surname,identityno,gender FROM cic_candidates WHERE id='$id' LIMIT 1"); while($row = mysql_fetch_assoc($result)) $maximumPoints = 100; { if($row['title'] != '') $completedTitle = 20; if($row['name'] != '') $completedName = 20; if($row['surname'] != '') $completedSurname = 20; if($row['identityno'] != '') $dcompletedIdentityno = 20; if($row['gender'] != '') $completedGender = 20; } $percentage = ($completedTitle+$completedName+$completedSurname+$completedIdentityno+$completedGender)*$maximumPoints/100; echo "".$percentage."%"; ?> The percentage shows in the echo but the total is wrong - it's not taking the values of 20 points for each field that is completed and including them in the "addition" part of the percentage calculation. Please can you tell me where I'm going wrong - I've been trying to figure this out for 4 days and have googled this and read over 2000 forums but can't find the answer. Any help would be greatly appreciated.
  18. <?php //updateemployee.php session_start(); //Resume session if(isset($_SESSION['name'])){// If $_SESSION['name'] not set, force redirect to home page $name = $_SESSION['name']; $status_msg=""; if (isset($_GET['data'])){ $data = $_GET['data']; if(isset($_GET['update'])){ if(isset($_GET['name']) && isset($_GET['email'])&& isset($_GET['gender']) && isset($_GET['faculty'])){ if(!empty($_GET['name']) && !empty($_GET['email'])&& !empty($_GET['gender']) && !empty($_GET['faculty'])){ //$data = $_GET['data']; $new_name = $_GET['name']; $new_email = $_GET['email']; $new_gender = $_GET['gender']; $new_school = $_GET['faculty']; $conn= connectDB(); $status_msg=updateRecord($new_name,$new_school,$new_gender,$conn,$new_email,$data); echo $new_name; echo $new_school; echo $new_gender; echo $new_email; echo $data; }else{ $status_msg="<h2 style='color:red;'>Incomplete Input. Please try again</h2>"; } } } }}else{ header('Location: index.php'); } if(isset($_GET['logout'])){ session_destroy(); header('Location: index.php'); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> </head> <body> <?php if(isset($_GET['data'])){ $data = $_GET['data']; echo $data;//To test if the Id matches the profile that needs to be updated } $status_msg = ""; function connectDB(){//Function to connect to database $servername = "localhost"; $username = "root"; $password = ""; $db= "staff_db"; $conn = mysqli_connect($servername,$username,$password,$db); if(!$conn){ die('Connection Failed: '.mysqli_connect_error()); } return $conn; } //$sql = "SELECT * FROM staff_table WHERE staff_id='$data'"; $conn = connectDB(); function updateRecord($new_name,$new_gender,$new_school,$conn,$new_email,$data){ $sql = "UPDATE staff_table SET name='$new_name',gender='$new_gender',school='$new_school',email='$new_email' WHERE staff_id='$data'"; if (mysqli_query($conn,$sql)){ $status_msg="<h3 style= 'color:green;'>Account details are successfully updated.</h3>"; }else{ $status_msg= "ERROR: Could not execute SQL".mysqli_error($conn); } mysqli_close($conn); return $status_msg; } ?> <h1>Update Staff Profile</h1> <form action="UpdateEmployee.php" method="GET"> <fieldset> <legend>Personal Information</legend> <p><span class="error">* required field</span></p> <label for="name">Full Name: <input type="text" id="name" name="name"><span class="error">*</span></label><br> <label for="sID">Staff ID: <input type="text" id="sID" name="sID" placeholder="<?php echo $data;?>" disabled="disabled"></label><br> <label for="email">Email: <input type="text" id="email" name="email"><span class="error">*</span></label><br> <label for="gender">Gender:</label> <select id="gender" name="gender"> <option value = "-1" selected>[Gender]</option> <option value = "Male">Male</option> <option value = "Female">Female</option> </select><br> <label for="faculty">School/Faculty</label> <select id="faculty" name="faculty"> <option value = "-1" selected>[School/Faculty]</option> <option value = "SFS">SFS</option> <option value = "FBDA">FBDA</option> <option value = "FECS">FECS</option> </select><br> <p><input type="submit" name="update" value="Update Staff"></p> <p><?php echo $status_msg;?></p> </fieldset> </form> <footer> <p><a href="MainMenu.php">Main Menu</a></p> <p><a href="">Logout</a></p> </footer> </body> </html> <?php //displayemployeeinf.php session_start(); //Resume session if(isset($_SESSION['name'])){// If $_SESSION['name'] not set, force redirect to home page $name = $_SESSION['name']; }else{ header('Location: index.php'); } if(isset($_POST['logout'])){ session_destroy(); header('Location: index.php'); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Display Employee Information</title> </head> <body> <h1>Staff Profile</h1> <div class="display"> <fieldset> <legend>Employees Information</legend> <?php function connectDB(){//Function to connect to database $servername = "localhost"; $username = "root"; $password = ""; $db= "staff_db"; $conn = mysqli_connect($servername,$username,$password,$db); if(!$conn){ die('Connection Failed: '.mysqli_connect_error()); } return $conn; } $data = $_GET['data']; $sql = "SELECT * FROM staff_table WHERE name ='$data'"; $conn= connectDB(); $result = mysqli_query($conn,$sql); if($result){ $row = mysqli_fetch_assoc($result); } if(isset($_POST['update'])){ header('Location: UpdateEmployee.php?data='.$row['staff_id'].''); } ?> <form method="POST"> <table class="center"> <tr><td><p><strong>Name:</strong></p></td><td><p><?php echo $row['name'];?></p></td></tr> <tr><td><p><strong>Staff ID:</strong></p></td><td><p><?php echo $row['staff_id'];?></p></td></tr> <tr><td><p><strong>Email</strong></p></td><td><p><?php echo $row['email'];?></p></td></tr> <tr><td><p><strong>Gender</strong></p></td><td><p><?php echo $row['gender'];?></p></td></tr> <tr><td><p><strong>School</strong></p></td><td><p><?php echo $row['school'];?></p></td></tr> </table> <p><input type="submit" name="update" value="Update"></p> <p><input type="submit" name="delete" value="Delete"></p> </form> </fieldset> </div> <footer> <p><a href="MainMenu.php">Main Menu</a></p> <p><a href="">Logout</a></p> </footer> </body> </html>
  19. I am trying to call a stored procedure that accepts parameter inserts. The original query was being run from asp and looked like this: EXEC [SearchForXML6b] @sessionID = 973543, @LineID = 892245, @SortOrder = 'YearPublished DESC, SortTitle ASC', @PageNumber = 1, @RecordsPerPage = 20 I am redesigning the website in PHP, and am using the PDO method for querying the database. I am using a windows server, but have configured php to work on it, and can return simple selects from the db using pdo no problem. From looking around for help for many hours, the accepted way to do what I need seems to be to do something like this: $sql = "{:retval = CALL SearchForXML6b (@sessionID = 973543, @LineID = 892245, @SortOrder = 'YearPublished DESC, SortTitle ASC', @PageNumber = 1, @RecordsPerPage = 20)}"; $stmt = $this->c->prepare( $sql ); $stmt->bindParam('retval', $retval, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 4); However this isn't working. I have tried using EXEC instead of CALL but apparently PDO doesn't accept this. I have heard talk of installing OBDC but it seems to be more of a LINUX focused driver. Does anyone know if it is possible to run stored procedures with my configuration? Note: In SQL Server Management Studio, the SQL executes perfectly when using 'EXEC', but gives an error when trying to use 'CALL' as I don't think it's valid TSQL. Thanks in advance
  20. I'm running: Windows Server 2003 IIS 6.0 Microsoft SQL 2005 PHP 5.3.28 Everything that i have read says, "5.3 got rid of mssql and now uses sqlsrv" so i added extension=php_sqlsrv_53_nts_vc9.dll to my php.ini (and yes it is in the ext folder) and when i run the script $serverName = "localhost\phonebook"; //serverName\instanceName // Since UID and PWD are not specified in the $connectionInfo array, // The connection will be attempted using Windows Authentication. $connectionInfo = array( "Database"=>"XXXXX", "UID"=>"XXXXX", "PWD"=>'XXXXXXXX'); $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)); } i get
  21. I have a database class that uses PDO and it all works until i need to do an update where I increment the value What I have is a table and one of the columns is called 'counter' and I need to update this table every time a page is visited This is the function that handles all the PDO and creates the query /** * update * @param string $table A name of table to insert into * @param string $data An associative array * @param string $where the WHERE query part */ public function update($table, $data, $where) { ksort($data); $fieldDetails = NULL; foreach($data as $key=> $value) { $fieldDetails .= "`$key`=:$key,"; } $fieldDetails = rtrim($fieldDetails, ','); $sth = $this->prepare("UPDATE $table SET $fieldDetails WHERE $where"); foreach ($data as $key => $value) { $sth->bindValue(":$key", $value); } $sth->execute(); } and this is how I call the function by passing parametres to the function $board = ucwords(str_replace('-',' ',$board)); $sql = "SELECT boardid from boards WHERE boardname = :board"; $rows = $this->db->select($sql, array(':board' => $board)); $postData = array( 'counter' => 'counter+1', ); $this->db->update('topics', $postData, "`topicid` = {$topic} AND `boardid` = {$rows[0]['boardid']}"); It fails the update with this error message The counter column is of type INT
  22. 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"); } ?>
  23. update super set `name` = REPLACE(`name`, ',' , ' ') I have the following code that removes the comma in a MySQL database column & replaces it with a blank. In the above example, the database is named super & the column is named name. This code works great but currently I'm running the script each day & changing it to also remove periods, question marks, etc. Is there a way I can edit the above code that will not only find & replace the , with a blank space, but edit it so it will find the periods, commas, question mark, exclamation mark, etc all in one run? Please help as I am currently editing the above code to numerous other things to find & replace daily. Thank
  24. i have put 3 users on my database. If i login with all 3 it works there is no problem(providing correct username and password matches). The problem is that it recognizes all 3 users as the first user. even if i check password it will display all three users password the same(all tho when i log in i have to have correct password and username for each user) as the first user which is user id 1. When i echo username or name or surname it displays the first users name or surname whatever i echo , no matter who i log in with I am not sure whats going on here at all. here is my code for the login functions i think the problems lies here i know this is not the best code but there must be a way to fix this users.php <?php function register_user($register_data){ Global $dbc; array_walk($register_data,'array_sanatize'); $register_data['password']= md5($register_data['password']); $fields='`'.implode('`, `',array_keys( $register_data)).'`'; $data='\''.implode('\', \'', $register_data).'\''; //print_r($register_data); mysqli_query($dbc," INSERT INTO `users` ($fields) VALUES ($data)"); //mysqli_error($dbc); } function user_data($user_id){ Global $dbc; $data=array(); $user_id = (int)$user_id; $func_num_args=func_num_args(); $func_get_args=func_get_args(); if($func_num_args >=1){ unset($func_get_args[0]); $fields='`'.implode('`, `', $func_get_args).'`'; $data=mysqli_query($dbc," SELECT $fields FROM `users` WHERE `user_id` = $user_id "); //mysqli_error($dbc); if ($data === false) { die("error on mysqli_query: ". mysqli_error($dbc)); } $data=mysqli_fetch_assoc($data); //print_r ($data); return $data; } } function logged_in(){ GLOBAL $dbc; return(isset($_SESSION['user_id'])) ? true : false; } function user_exists($username){ GLOBAL $dbc; $username=sanatize($username); $query= mysqli_query($dbc,"SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' "); $check= mysqli_fetch_array( $query , MYSQLI_BOTH); return ($check[0]==1)?true:false; } function email_exists($email){ GLOBAL $dbc; $email=sanatize($email); $query= mysqli_query($dbc,"SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email' "); $check= mysqli_fetch_array( $query , MYSQLI_BOTH); return ($check[0]==1)?true:false; } function user_active($username){ GLOBAL $dbc; $username=sanatize($username); $query= mysqli_query($dbc,"SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `active` = 1 "); $check= mysqli_fetch_array( $query , MYSQLI_BOTH); return ($check[0]==1)?true:false; } function user_id_from_username($username){ GLOBAL $dbc; $username = sanatize($username); $query= mysqli_query($dbc,"SELECT `user_id` FROM `users` WHERE `username` = '$username' "); $check= mysqli_fetch_array( $query , MYSQLI_BOTH); return $check[0]=='user_id'; } function login($username , $password){ GLOBAL $dbc; $user_id = user_id_from_username($username); $username = sanatize($username); $password = md5($password); $query= mysqli_query($dbc,"SELECT `user_id` FROM `users` WHERE `username` = '$username' AND `password` = '$password'"); //$check= mysqli_fetch_array( $query , MYSQLI_BOTH); if(mysqli_num_rows($query) == 1) { return 0 == 1 ? $user_id : true ; } // no results found so return false return false; log.php include("config/init.php"); if(empty($_POST)===false){ $username= $_POST['username']; $password= $_POST['password']; } if(empty($username) ===true || empty($password) ===true){ $errors[] ='Please enter a valid username and password'; } else if (user_exists($username)===false){ $errors[] ='This username does not exist. Please sign up'; } else if (user_active($username)===false) { $errors[]="you have not activated your account via email"; } else { // here errors //testing username passwords ect, if all of the above statemens failed $login=login($username,$password); if($login===false){ //$error[]= echo "That username and password combination is incorrect"; } else { // set username session // redirect user to home //die($login); $_SESSION['user_id']=$login; header('location:index.php'); exit(); } } //print_r($errors); include('templates/header.php'); include('templates/footer.php'); ?> config/init.php <?php session_start(); require('connect.php'); require('functions/general.php'); require('functions/users.php'); // to be accessed by every page to check errors for login if(logged_in()===true){ $session_user_id=$_SESSION['user_id']; $user_data = user_data($session_user_id,'user_id','username','password','name' ,'surname' ,'email'); //echo $user_data['name']; if(user_active($user_data['username'])=== false){ session_destroy(); header('Location:index.php'); exit(); } } //else echo "cannot retreive data"; $errors=array(); ?> this does not echo correct username or id . no errors are displayed <aside id="widgets"> require_once('config/init.php'); require_once('config/functions/users.php'); require_once('config/functions/general.php'); ?> <h4 class="username"> Welcome <?php echo $user_data['name'];?> </h4> <div class="inner"> <ul> <li> <a href="logout.php"> Log out </a> </li> <li> <a href="changepassword.php"> New password </a> </li> </ul> </div> <?php echo mysqli_error($dbc);?> </aside> <?php include('templates/footer.php'); ?> <?php ?>
  25. Hey guys! im currently learning javascript, PHP and SQL. I have a pretty solid understanding of HTML and CSS. I want to make a site similar to facebook (a good facebook). this is going to be a big project and i plan on moving to a bigger server system in a year or so to keep up with demands. Heres how the site will function: 1. Basic registration/splash page. I understand that the finished form is sent to a php file on the server side, correct? (ill change my server name files of course) 2. after the registration page, while the user is logged in with their new account, there are 3 pages after that that explain what the website is all about and how to use it. the last page allows the user to setup their profile information, ask friends to join, and asks what type of things they like. After the last page, it sends the user to their main control panel, where social media feed can be seen, friends and online chats, news, advertisements, links, pages and groups (think facebook and linkedin) 3. the user will have the ability to look at their profile (not the control panel), and of course switch back to their control panel. social media, friends, groups and ads will also be on their individual profile page as well. 4. i want the site to have two views: a standard view and an enhanced view. the enhanced view will reposition divs and all that stuff so they can see a background image (either stock or one they uploaded) this image will eventually change to an animated image of a 3d environment. 5. the site is going to be heavily social media based. This means social media feeds, image uploading, a structured comment system, a friend system, search functions and targeted advertising. This is obviously a lot to ask, but since their is so much to learn related to PHP and SQL, can someone point me to the right tutorials on how to get these things done? I am currently learning javascript, PHP and SQL on lynda.com. Expect me to be on this forum a lot and asking a lot of questions. Thanks for any help.
×
×
  • 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.