I am trying to enter data in MySQL table using PHP. Below is my code. What am I missing? The reason is, no data is inserted.  Database connection.  &lt;?php class Dbh{     private $servername = "localhost";     private $username = "username";     private $password = "password";     private $dbname = "oop";     protected function connect(){         $conn = new mysqli($this-&gt;servername, $this-&gt;username, $this-&gt;password, $this-&gt;dbname);         return $conn;     } } ?&gt;   Insert class for inserting the data into MySql table  &lt;?php include_once 'Dbh.php'; class Insert{     public function insertData(){         $uid = $_POST['uid'];         $pwd = $_POST['pwd'];          $sql = "INSERT INTO user(uid, pwd) VALUES ('uid', 'pwd')";         mysqli_query($sql);         header("Location: ../index.php?data=inserted");     } } ?&gt;   HTML form for inputting the data.  &lt;?php include_once('Insert.php'); $data = new Insert(); ?&gt;  &lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt;     &lt;meta charset="UTF-8"&gt;     &lt;title&gt;Insert data into database&lt;/title&gt; &lt;/head&gt;  &lt;body&gt; &lt;form action="classes/Insert.php" method="POST"&gt;     &lt;input type="text" name="uid" placeholder="user name"&gt;     &lt;br&gt;     &lt;input type="password" name="pwd" placeholder="password"&gt;     &lt;br&gt;     &lt;button type="submit" name="submit"&gt;Insert data&lt;/button&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;
73
If user input is inserted without modification into an SQL query, then the application becomes vulnerable to , like in the following example:  $unsafe_variable = $_POST['user_input'];   mysql_query("INSERT INTO `table` (`column`) VALUES ('$unsafe_variable')");   That's because the user can input something like value'); DROP TABLE table;--, and the query becomes:  INSERT INTO `table` (`column`) VALUES('value'); DROP TABLE table;--')   What can be done to prevent this from happening?
41779
I m trying to understand where we use following Database.Methods. I know if we want to insert a record to an object we use DML Statement. What i want to know is why/where we use Database. methods. It might be silly question. Database.saveResults Database.insert Database.query Database.Query Database.error   really appreciate the inputs. Thanks a ton in advance.
92236
I have an xml file which I would like to create a form/table around to add, edit and delete records using PHP.  Currently I use simpleXML to load the XML file, and display its content on various pages.  Is there any way I can create a table that shows all results, and allows me to either edit or delete that particular row of the table which represents a full record within the XML file.    When clicking edit I would like the details from the record to appear in a form which the user can change and then save out, updating the XML file and the corresponding web page.  I need this done in PHP, preferably using SimpleXML, though open to suggestions of other ways to do this with PHP.  Cheers
102819
I am doing a School Management System in php using Mysql DB. I am stuck in my Project. Please anybody suggest what I am doing wrong.  I have two tables in my database; one is to store Students records another one is to store their attendance day wise  Now I want to display a report of all students in particular class for the current month whether they were present or absent. But I am capturing only Absent students details only in attendance table.  I have written sql query to display the result here is:  SELECT tab.class, attend, DATE, ta.rollno, ta.StdNm  FROM tbl_absentees tab, tbl_admission ta WHERE ta.Cls = class   AND ta.rollno = tab.rollno   AND class =22   AND attend =  'A'   AND DATE =  '2013-06-07';   The result is:  Class Attend RollNo StudentName   But I want to display in 31 days table manner by taking only Date in attendance table if attend=A display A for absent Days otherwise Display 'P' for remaining days  How can I do this in mysql? Can anyone suggest/give me an idea to achieve this.  Sorry for misclarification in my question. Actually I want to display an attendance report for a particular month where data comes from two tables:   the first table consists of StudentName, RollNo, Class the second table consists of Date, Status, RollNo, Class   Now I want to display report like .
91212
I am trying to create a form that will allow users to update their information on the front end.  I am just starting to learn PHP (I know C# very well).  If I use this code to create a form on a WordPress page, how do I get the information from the user when they press the 'Update' button and then update the database?  function Insert_AccountTable_1() {     $current_user = wp_get_current_user();      if ($current_user-&gt;ID != 0)     {         return &lt;&lt;&lt;HTML             &lt;form class="AlumniForm" method="post"&gt;             &lt;h3&gt;Name&lt;/h3&gt;             &lt;br&gt;             &lt;table&gt;                 &lt;tbody&gt;                     &lt;tr&gt;                         &lt;th&gt;&lt;label for="Username"&gt;Username&lt;/label&gt;&lt;/th&gt;                         &lt;td&gt;&lt;span&gt;$current_user-&gt;user_login&lt;/span&gt;&lt;/td&gt;                         &lt;td&gt;&lt;span class="description"&gt;Usernames cannot be changed.&lt;/span&gt;&lt;/td&gt;                     &lt;/tr&gt;                     &lt;tr&gt;                         &lt;th&gt;&lt;label for="current_user_firstname"&gt;First Name&lt;/label&gt;&lt;/th&gt;                         &lt;td&gt;&lt;input id="current_user_firstname" type="text" name="current_user_firstname" value="$current_user-&gt;user_firstname"/&gt;&lt;/td&gt;                     &lt;/tr&gt;                     &lt;tr&gt;                         &lt;th&gt;&lt;label for="current_user_lastname"&gt;Last Name&lt;/label&gt;&lt;/th&gt;                         &lt;td&gt;&lt;input id="current_user_lastname" name="current_user_lastname" type="text" value="$current_user-&gt;user_lastname"/&gt;&lt;/td&gt;                     &lt;/tr&gt;                     &lt;tr&gt;                         &lt;th&gt;&lt;label for="current_user_displayname"&gt;Display Name&lt;span class="description"&gt;(required)&lt;/span&gt;&lt;/label&gt;&lt;/th&gt;                         &lt;td&gt;&lt;input id="current_user_displayname" type="text" value="$current_user-&gt;display_name"/&gt;&lt;/td&gt;                     &lt;/tr&gt;                 &lt;/tbody&gt;             &lt;/table&gt;              &lt;h3&gt;Contact Info&lt;/h3&gt;             &lt;br&gt;             &lt;table&gt;                 &lt;tbody&gt;                     &lt;tr&gt;                         &lt;th&gt;&lt;label for="current_user_email"&gt;E-mail&lt;span class="description"&gt;(Required)&lt;/span&gt;&lt;/label&gt;&lt;/th&gt;                         &lt;td&gt;&lt;input id="current_user_email" type="text" value="$current_user-&gt;user_email"/&gt;&lt;/td&gt;                     &lt;/tr&gt;                     &lt;tr&gt;                         &lt;th&gt;&lt;label for="current_user_url"&gt;Website&lt;/label&gt;&lt;/th&gt;                         &lt;td&gt;&lt;input id="current_user_email" type="text" value="$current_user-&gt;user_url"/&gt;&lt;/td&gt;                     &lt;/tr&gt;                 &lt;/tbody&gt;             &lt;/table&gt;             &lt;input type="submit" name="current_user_submitupdates"&gt;Update&lt;/input&gt;             &lt;/form&gt; HTML;     }     else     {         return &lt;&lt;&lt;HTML         &lt;h3&gt;Error - User not logged in&lt;/h3&gt; HTML;     } }  add_shortcode('InsertAccountTableI', 'Insert_AccountTable_1');
111744
Say I have a table called User_FriendList, which has the following characteristics:  CREATE TABLE User_FriendList (     ID ...,     User_ID...,     FriendList_IDs...,     CONSTRAINT User_Friendlist_PK PRIMARY KEY (ID) );   And let us suppose that said table holds the following data:    +----+---------+---------------------------+  | ID | User_ID | Friendlist_IDs            |  +----+---------+---------------------------+  | 1  | 102     | 2:15:66:35:26:17:         |  +----+---------+---------------------------+  | 2  | 114     | 1:12:63:33:24:16:102      |  +----+---------+---------------------------+  | 3  | 117     | 6:24:52:61:23:90:97:118   |  +----+---------+---------------------------+   Note: The “:” (colon) is the delimiter when exploding in PHP into an array.  Questions  So:   Is this a convenient way to “store” the IDs of a FriendList? Or, instead, should I have individual rows with only one single FriendId value in each of them and, when I need to retrieve all the rows of a given list, simply perform a query like SELECT * FROM UserFriendList WHERE UserId = 1?
74983
I'm writing a php app to access a MySQL database, and on a tutorial, it says something of the form  mysql_connect($host, $user, $pass) or die("could not connect");   How does PHP know that the function failed so that it runs the die part? I guess I'm asking how the "or" part of it works. I don't think I've seen it before.
90347
How do i dynamically assign a name to a php object?  for example how would i assign a object to a var that is the id of the db row that i am using to create objects.  for example   $&lt;idnum&gt;= new object();   where idnum is the id from my database.
86521
I just can't seem to figure this one out.  I want to use the command line to connect to a MySQL database residing on another server.  I went ahead and created the username and password for the user.  I have also granted all privileges on that user for that database.  When using the command: mysql -h &lt;hostname&gt; -u &lt;username&gt; -p, I get the following error:  ERROR 1045 (28000): Access denied for user '&lt;username&gt;'@'&lt;local_machine_hostname&gt;' (using password: YES)   The problem is that it keeps appending the current machine's hostname into the username.  Obviously, that user@&lt;local_machine_hostname&gt; is not correct.  It doesn't matter what I type.  For instance, if I type:  mysql -h &lt;hostname&gt; -u '&lt;username&gt;'@'&lt;hostname&gt;' -p   It does the same, only in the error output, it says:  Access denied for user '&lt;username&gt;@&lt;hostname&gt;'@'&lt;local_machine_hostname&gt;'   Is there a setting in a configuration file which is allowing this to happen?  It's really quite annoying.  I need to set up a tikiwiki server, and it cannot connect because during the step where you set up mysql, it keeps appending the local machine's hostname to the mysql login name.
81200
Im having a VF page it has some text fields and one button . On clicking the button , the values in the text field should be passed to the controller class to save in the database . Can this be achieved . If yes , direct me .
30396
I'm programmatically creating a user with the following code.  $newUser = array(   'name' =&gt; $mail,    'pass' =&gt; 'password',  // note: do not md5 the password   'mail' =&gt; $mail,    'status' =&gt; 1,    'init' =&gt; $mail,   'roles' =&gt; array(5) ); $user = user_save(null, $newUser);   I have got a role with the role ID equal to 5; when I create the user, in the table "users_roles" there is only a row with the value 0 for the role ID, but if I print the user object with var_dump(), it looks like the roles are created.  What am I doing wrong?
64553
Does anyone know of a simple way for a C++ program to communicate directly with a MySQL database?  I have looked at MySQL++ and found it to be very confusing.  If anyone knows of a very simple way of doing this, please let me know.  Thanks  P.S. I am developing on a Windows machine.  PHP and MySQL web web application setup.  C++ setup to talk to the serial port.  Thus why I need a way for C++ to talk to the MySQL database directly.
7387
Can someone explain SQL injection?  How does it cause vulnerabilities?  Where exactly is the point where SQL is injected?
8186
is there an alternative for mysql_insert_id() php function for PostgreSQL? Most of the frameworks are solving the problem partially by finding the current value of the sequence used in the ID. However, there are times that the primary key is not a serial column....
16882
I am trying to write a WordPress plug-in. In my project I have three PHP files.   My plug-in file Widget for the plug-in Data installation   I need to install data table on plug-in activation. For that sake I wrote code to create table for my plug-in in data installation file. But I am not able to create data table using this file.  My code for include data installation file and widget file in my plug-in file is  define ( 'OTHER_FILES_PATH', plugin_dir_path( __FILE__ ) ); require_once( OTHER_FILES_PATH . '/data_installation.php' ); require_once( OTHER_FILES_PATH . '/plugin_widget.php' );   My problem is when I put my data installation code in my plug-in file it's working fine but when I put it in separate file (data installation) I am unable to create tables for my plug-in.  Please let me know if I am making any mistake.
68629
I am using PHP on my server to create a latex table from a database, which is working fine.  The problem I have now is getting that into my latex document.  I thought that giving it the path would allow it to get the file from the web and input it like normal but that doesn't work and I've been unable to find anything online about doing this sort of thing.  Here is an example of what I'm trying to accomplish:  \documentclass{article} \begin{document} \input{http://example.com/generated-latex.php} \end{document}
51549
What's wrong with this query: INSERT INTO Users( weight, desiredWeight ) VALUES ( 160, 145 ) WHERE id = 1;  It works without the WHERE clause. I've seemed to have forgot my SQL.