Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I did something wrong because the last lane do not add anything to database.
Could someone experienced take a look please?
EDIT: I just deleted all unnecessary lanes
mysql_query('INSERT INTO votes (voter, photoid, photoowner, vote) VALUES ($voter, $photoid, $photoowner, "yes")');
Variable values are not evaluated within a string with single quotes:
mysql_query("INSERT INTO votes (voter, photoid, photoowner, vote) VALUES ('$voter', '$photoid', '$photoowner', 'yes')");
put double quotes around your select statement or use concatenation and don't forget to put quotes around your string values
Also use use mysql_error() to retrieve the error text
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I save some images in my database. Each images have a "tags" property.
I'm gonna show "search by tags" result to users, but there is a problem.For example, "IMAGE1" has "c#, programming, scripting" tags and I'm gonna show every images which have "programming" and "scripting" tags. So If I do that, "IMAGE1" will be duplicated.
So how can I prevent this duplicating ?!
Thanks !!
You can use DISTINCT operator of MySQL to retrieve non-duplicates
SELECT DISTINCT `imagename`
FROM `images`
WHERE (`tags` = 'programming') OR (`tags` = 'scripting')
The conditions for WHERE may be different depending on your PHP code.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to use PHP to find a value in a string and replace it with another value, the value may be (for example) £x on one line and £x.xx on the next, but will always be replaced by a value of £x.xx. Hope that makes sense? TIA.
Use this regex to match the prices: £[0-9]+\.?[0-9]{0,2}
You can perform the replace with this by using this function:
preg_replace("/£[0-9]+\.?[0-9]{0,2}/", " ** REPLACEMENT ** ", $input_lines);
The nice thing about preg_replace is that if you feed it a single line you'll get a single value back, but if you feed it an array of strings with the values you want changed it will return an array with those values replaces. Nice and tidy if you need to make a lot of replacements.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
This...
header("Location: fichaTorneioFinSub.php?id=" . $_GET['id'] . "");
The value of the GET is 1. But I always end up in this page:
fichaTorneioFin.php?id=%271%27
The id value gets these %27 around it. I know that means it's an encoded single quote but it shouldn't be there.
It would be a good idea to track down what's giving you the lone ', but this will ensure you're only working with digits:
$id = preg_replace('/\D/', '', $_GET['id']);
header("Location: fichaTorneioFinSub.php?id=".$id);
This will sound as stating the obvious: if it shouldnt be there, make sure it isnt. This means sanitizing your input ($_get data) into data you expect. Somehow the get variable already contains a single quote so i would suggest checking that first. To get it out you could for example
trim($_get ['id'], "'")
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to clean my entries that look like
“If you think adventure is dangerous, try routine; it is lethal.”
<p>Life isn't about finding yourself it's about creating yourself. </p>
I need to remove HTML tags and double quotes and single quotes if they are in the beginning or the end of the string.
There was a function, but I don't remember what it was or something like a class...
You can remove everything with ^[“"'‘]|[”"'’]$|^<[^>]*?>|<[^>]*?>$
Here is a demo.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
mysql_query("insert into user_info(Name,Id,Password,Email,Gender,Date_of_birth) values('".$name."','".$iden."','".$pass1."','".$email."','".$gender."','STR_TO_DATE('$date','%d,%m,%Y')')");
Can anyone tell which part of this code is incorrect, as it is not entering anything in the database.....
Unquote the 'STR_TO_DATE('$date','%d,%m,%Y')' call. I also cleaned up the rest of the code a bit. As a result you get:
mysql_query("insert into user_info(Name,Id,Password,Email,Gender,Date_of_birth) values('$name','$iden','$pass1','$email','$gender',STR_TO_DATE('$date','%d,%m,%Y'))");
On this part:
'STR_TO_DATE('$date','%d,%m,%Y')'
There are single quotes inside single quotes, causing an error. To fix this, replace the single quotes on the arguments to escaped double quotes, like this:
'STR_TO_DATE(\"$date\",\"%d,%m,%Y\")'
However, since you probably want to use the function and not post it literally, you should just remove the outside quotes, like this:
STR_TO_DATE('$date','%d,%m,%Y')