Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have two queries in my PHP file:
$q1 = " INSERT INTO team_password ( team_name, password ) VALUES ( '". $team_name."', '". $password."' )";
$result = mysqli_query($con,$q1);
it is working fine.
$q2 = " INSERT INTO all_users ( user_name, team_name ) VALUES ('". $user_name."', '". $team_name."')";
$all_users_var = $mysqli_query($con,$q2);
But this query is not responding.
all_users have four columns user_name, team_name, longitude and latitude.
longitude and latitude have default have values NULL.
Any help will be appreciated.
I think the guilty here is the $ sign before your mysqli_query().
When you have a doubt, you should check your php_error.log :)
It is the $ sign before mysqli_query() which is creating problems, remove $ sign and execute the code
Try this:
$q2 = " INSERT INTO all_users ( user_name, team_name ) VALUES ('$user_name','$team_name')";
$all_users_var = mysqli_query($con,$q2);
or this one
$q2 = mysqli_query("INSERT INTO all_users(user_name, team_name) VALUES('$user_name','$team_name')") or die(mysqli_error());
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to show all user information held in a db.
SELECT * FROM member
However i do not want it to select the current user (find by personID)
Is there a way to say select all but not personID XXXX?
Thanks
Use <> or != as an not equal to operator.
SELECT * FROM member WHERE personID <> 123;
SELECT * FROM member WHERE personID != 123;
If you want to exclude multiple IDs:
SELECT * FROM member WHERE personID NOT IN (1,2,3);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
How should I make a sql update query only IF a value of the table is equal to "something"?
I would not want to use case because I don't have any "else" statement and it is regulated by another simple value of the table, so there are no more cases.
EDIT: Since there is so much need to see one single line of code because certainly my question has no answer this way, I'll leave it here:
$query = "IF seen=1 UPDATE something SET other_thing = 100 WHERE yet_another_thing= 'outro' ";
You use a where statement:
update t
set foo = bar
where value = 'something';
Looking at everyone's answers, here is the code for YOU.
$query = "UPDATE something SET other_thing = 100 WHERE yet_another_thing= 'outro' AND seen = 1";
This is where use use a WHERE clause:
UPDATE
SomeTable
SET
field = 1234
WHERE
anotherField = 5678
UPDATE tablename SET updatevalue = 'value' WHERE avalue = 'something'
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to replace the first instance of a NULl or ' ' value in a column with another value. But only the first instance and nothing else.
So far I've put this together:
UPDATE table_name SET column = CONCAT(REPLACE(LEFT(column , INSTR(column , '')), '', 'new_value'), SUBSTRING(column , INSTR(column , '') +1))
I could replace all the values but I don't want that:
UPDATE table_name SET column = REPLACE (column , 'old_value', 'new_value')
Just try using limit 1
UPDATE table_name SET column='new_value' WHERE column='' limit 1
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm using the below query to insert data into a MySQL database. But this not working.
I'm also using this type query in my other page and that's working fine.
This is the SQL query:
$query="INSERT INTO `add7ras_work`.`movies` (`url`, `title`, 'description')
VALUES ('$url','$title', '$desc');";
$result=mysql_query($query);
You used single quotes around description instead of backticks:
$query="INSERT INTO `add7ras_work`.`movies` (`url`, `title`, `description`) VALUES ('$url','$title', '$desc');";
Standard disclaimer: Read up on PDO and MySQLi as mysql_x functions are deprecated.
Bad quoting:
$query="INSERT INTO `add7ras_work`.`movies` (`url`, `title`, 'description')
^-- ^---
' quotes in SQL turn the quoted data into a string. This means you're using a string in a fieldname context, which does not work.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to let users insert a subject to an image. I know I can't use a WHERE clause in combination with an INSERT INTO statement, and I know that I should use SELECT. I am very new to mysql and I didn't understand the results I tried to search on google. So I needed a more specific answer;)
$classed = mysql_query("INSERT INTO images (subject) VALUES ('$_POST[subject]') WHERE image_id='$_POST[id]'");
You can't use WHERE in your INSERT statement. Consider trying UPDATE if you want to update existing rows, or INSERT without the WHERE to insert new rows.
Don't use the mysql_query function, as it deprecated. Try using PDO or mysqli_query instead.
Don't ever use unfiltered input in your query.
if you already have image_id value then you should UPDATE your table not INSERT.
you should escape your variables before inserting them in your table. by
mysql_real_escape_string()
try this:
$subject = mysql_real_escape_string($_POST['subject']) ;
$id =mysql_real_escape_string($_POST['id'] ) ;
$classed = mysql_query("UPDATE images
SET subject = '".$subject."'
WHERE image_id='".$id."' ");
You cannot use INSERT in existing rows, try UPDATE the SQL will be something like
UPDATE images SET subject = '...' WHERE id=x;