Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I want to write some Data in my MySQL database but it seems to not work.
All the variables are filled, tested it by echoing them. Now I want to insert them into my sip table but it just doesnt do it.
Where did I go wrong on this?
echo $a_dw.$a_name.$a_an.$a_pw."<br>";
$sql = "INSERT INTO sip VALUES ('".$a_dw."','".$a_name."', '".$a_an."', '".$a_pw."')";
mysql_query($sql);
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
You forgot the column names.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I want to Select one record from a table Named 'sms_students' by using Student Id or Student Telephone
Here is My Code
$student_rand_id=$_GET['std_rand'];
$std_tell=$_GET['std_tell'];
$view_student = $config->prepare("SELECT * FROM sms_students WHERE st_rand = :random_id || st_tel =: st_tel");
$view_student->execute(['random_id' => $student_rand_id]);
$view_student->execute(['st_tel' => $std_tell]);
$row = $view_student->fetch();
Since you call execute twice, this executes twice, both times with an incomplete set of arguments. It's an easy fix though:
$view_student = $config->prepare("SELECT * FROM sms_students WHERE st_rand = :random_id OR st_tel = :st_tel");
$view_student->execute(['random_id' => $_GET['std_rand'], 'st_tel' => $_GET['std_tell'] ]);
$row = $view_student->fetch();
Try and get rid of single-use variables, they're almost always unnecessary, and do try and steer towards having names that match precisely. Seeing st_tel and std_tell together is a sign something's not quite right. Get your code to agree on names and stick with them.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I want to update next table named 'book' but this UPDATE code is not working
"UPDATE books SET Quantity=Quantity-1 Where Book_ID='$Book_ID'";
this code should update the books table by decreasing the value of Quantity by 1
You need to decrease from column value, not PHP variable. Remove the dollar sign and quotes, of you have there integers.
UPDATE books SET Quantity = Quantity - 1 Where Book_ID = '$Book_ID'
Don't forget that you are vulnerable to SQL injection in WHERE clause.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm having problems with a query that should "rank an user to 3" but instead in the MySQL it gives to the user X rank 0.
Here is the code
if($_POST['rank'] == '3')
{
mysql_query("UPDATE users SET rank='3' AND LPT='1' where username='".$_post['u_name']."' LIMIT 1")or die(mysql_error());
$query = true;
}
Waiting for answers
Use comma instead of AND when updating multiple columns:
UPDATE users
SET rank='3',
LPT='1'
where username= ?
You should:
Use parametrized query instead of concatenating SQL string
$_post is a superglobal and must be in uppercase $_POST
Reference: http://php.net/manual/en/language.variables.superglobals.php
Additional reference:
UPDATE http://dev.mysql.com/doc/refman/5.7/en/update.html
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
SOLVED
Rows 1, 4, and 10 have a field with a single quote character in them, so I was SQL injecting myself. More reason to switch to prepared statements!
I have a very simple bulk UPDATE query sent from my PHP form which, oddly enough, only affects certain rows. Rows 1, 4, and 10 doesn't get updated; but all other rows get updated.
Here is the query:
$query = "SELECT * FROM SkillDescriptions";
$result = mysql_query($query);
for ($i=1; $i<=mysql_num_rows($result); $i++){
$skillKey = 'Skill' . (string)$i;
$categoryKey = 'Category' . (string)$i;
$descriptionKey = 'Description' . (string)$i;
$sql="UPDATE SkillDescriptions SET
Skill='$_POST[$skillKey]',
Category='$_POST[$categoryKey]',
Description='$_POST[$descriptionKey]'
WHERE id='$i'
";
$result2=mysql_query($sql);
}
I've got a parallel form that does the exact same PHP form processing as this one but has a different database table, which works properly: so the problem most likely lies in the database table (configuration?) and not the code.
Why do only certain rows get updated, in a seemingly random pattern?
UPDATE
Before:
http://i.stack.imgur.com/2hk2l.png
After: (I appended test to the columns)
http://i.stack.imgur.com/ObMn5.png
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I would like to subtract one column of data from another, namely gdded from gppy; both are stored in a MySQL database.
Here is my code but it seems there is something wrong. I've searched anywhere but I cannot find the right answer.
My script below
INSERT INTO denmrk
(EMPID, NAME, DATE_FR, DATE_TO, Tangkay, Alis, gppy, gdded , NET_PAY, SSS_comboE, IBG_EMPLYE, PROCESSED_DATE)
VALUES
(6666, 'JUAN DELACRUZ', '2014-02-01 00:00:00', '2014-02-01 00:00:00', 'BBBB CO', 'DRIVER', 3383.04, 300, gppy- gdded , 150, 150, GETDATE() );
With the given code and implied database structure, how can I can achieve this?
BTW there is no need to store the manipulated result in the database. You can do this when you are select the data from the database. SO it would be better to drop that col and the idea to store the calc result in the database as well.