Question

Write the query string that will delete the user record from the "user" table having user_nameequal...

Write the query string that will delete the user record from the "user" table having user_nameequal to the string value stored in variable $username.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Write the query string that will delete the user record from the "user" table having user_nameequal to the string value stored in variable $username.

MySql Query using PHP:

$query=mysql_query("DELETE FROM user WHERE user_name='%s'",mysql_real_escape_string($username)); // using mysql_query

Syntax:
   mixed mysql_query(string query,sql_connection);


using mysql_query() function executes a query on a MySql database
mysql_real_escape_string() function is used to escapes special characters in a string for use in an sql statement

Example in PHP Code:

<?php

$con=mysql_connect("localhost","user","password"); // create database connection with $con object

if (!$con) // check connection is failed
{
die('Connection Failed...'.mysql_error()); // exit from database
}

$_username=mysql_real_escape_string($username); // escape special characters in a string in $username
$query="DELETE FROM user WHERE user_name='$_username'"; // create a query with query object $query
mysql_select_db('test_db'); // set the current active database
$uname=mysql_query($query,$con); // using mysql_query() function execute query and assign $username variable
if ($uname) //check $username exist then,

{
echo "Record is Successfully Deleted...."; // display this message
}
else
{
echo "Record is not avaialable" .mysql_error(); // else, display this message
}
?>

Add a comment
Know the answer?
Add Answer to:
Write the query string that will delete the user record from the "user" table having user_nameequal...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write the query string that will insert into the "user" table the field values stored in...

    Write the query string that will insert into the "user" table the field values stored in the variables $username and $password. The field names of the "user" table are user_name and user_password.

  • Write a SQL query that outputs the grade level from the job grades table for which...

    Write a SQL query that outputs the grade level from the job grades table for which the inputted salary is between the lowest salary and the highest salary column values. The salary value will be inputted by the user after the query is run. This should be done with a substitution variable. Keep the column names as - Job's Grade.

  • a. Run a query to delete from the Order_details any rows that are in the Order_Details_Archive...

    a. Run a query to delete from the Order_details any rows that are in the Order_Details_Archive table. b. Run a query to delete from the Orders any rows that are in the Orders_Archive table. orders Modify Database sales CUSTOMERS CustStreetAddress CustCity ORDERS OrderNumber PK OrderDate ShipDate CustomeriD FK EmployeelD FK OrderTotal CustPhoneNumber EMPLOYEES EmployeelD PK EmplastName EmpCity ORDER DETAILS PRODUCTS OrderNumber CPK ProductNumber CPKO QuotedPrice QuantityOrdered EmpState EmpPhoneNumber CategorylDFK CATEGORIES CategorylD PK PRODUCT VENDORS VendoriD CPK DaysToDeliver ORDERS ARCHIVE ShipDate...

  • What happens when you try to compile and run the following code? String query = "INSERT...

    What happens when you try to compile and run the following code? String query = "INSERT INTO Invoices (InvoiceDate InvoiceTotal) "              + "VALUES ('2/10/01', '443.55')"; Statement statement = connection.createStatement(); statement.executeUpdate(query); a. A SQLException is thrown at runtime because the executeUpdate method can’t accept a String object. b. A SQLException is thrown at runtime because the SQL statement is coded incorrectly. c. An error occurs at compile time because the SQL statement is coded incorrectly. d. This code compiles and...

  • Write a robust ADO.NET connectIon-oriented code snippet which inserts a record (with parameters coming from the...

    Write a robust ADO.NET connectIon-oriented code snippet which inserts a record (with parameters coming from the user, assume these are already stored in some variables) into the following table: StudentID, Name, YearOfBirth). Make sure you avoid SQL injection type attacks by using a parameterized SQL query. StudentID is an automatically generated column, provided by the database.

  • how to delete first word and last word in a string of user input ex: int...

    how to delete first word and last word in a string of user input ex: int main) string fullname; cout << "Enter Full Name ex: Rob John Smith" << endl; cin >fullname; //Some code that will delete the first and /last name to get middle name cout < "Your middle name is:" midname;

  • Write a program in MIPS to accept a string from a user, reverse that string and...

    Write a program in MIPS to accept a string from a user, reverse that string and print it out to the user. You must write a procedure that performs the reversal task. Example: Please Enter a String: Hello How Are You Reversed String: uoY erA woH olleH

  • Write a program that prompts the user for a string and stores the user's string into...

    Write a program that prompts the user for a string and stores the user's string into a variable using getline(). After receiving the string, the program counts and displays the number of vowels in the string. Then, the program should prompt the user if they would like to enter another string.

  • Write a C Program that asks the user to input a string and then the user...

    Write a C Program that asks the user to input a string and then the user is prompted back whether the input string is a “Palindrome Word” or not. (A Palindrome Word reads the same backward or forward, eg. madam, racecar, etc.) Your program should contain a function that accepts the input string from the main function and returns a value indicating whether the input string is a Palindrome or not. Use Pointers to traverse the string.

  • Create a python script to manage a user list that can be modified and saved to...

    Create a python script to manage a user list that can be modified and saved to a text file. Input text file consisting of pairs of usernames and passwords, separated by a colon (:) without any spaces User choice: (‘n’-new user account, ‘e’-edit existing user account, ‘d’- delete existing user account, ‘l’- list user accounts, ‘q’-quit) List of user accounts, error messages when appropriate Output text file consisting of pairs of username and passwords, separated by a colon (:) without...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT