Jump to content

how do i escape double quotes as \\ is not working


Recommended Posts

@thorpe: The curly braces around the variable aren't necessary for simple arrays like that.

 

@madspof: You obviously haven't tried my code because it will work. You're escaping the $ character which means PHP treats it as a normal character rather than the start of a variable.

I think it depends. If you use...

 

echo "<a href='makep.php?p=$row[Picture]'>protect from public</a><br><br></div>";

 

You won't get the notice, but you will get a warning about the undefined constant Picture.

 

If you use...

 

echo "<a href='makep.php?p=$row['Picture']'>protect from public</a><br><br></div>";

 

You should get some notice about using complex variables without braces. To be honest, Ive never tested it. but it is always best to use braces around complex variables. ie; arrays, object calls.

<?php
include("../connect.php");
$cookie_info = explode("-", $_COOKIE['cookie_info']);
$dir = $cookie_info[0];
$pc = $_GET["p"]; 
$query  = "SELECT public FROM userpic WHERE userid = '$dir' AND Picture = '$pc' ";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
echo "{$row['public']}" .
 "$pc";
if($row['public'] == 1){
mysql_query ("UPDATE userpic SET public = '1' WHERE userid = '$dir' AND Picture = '$pc'");
}else{
mysql_query ("UPDATE userpic SET public = '0' WHERE userid = '$dir' AND Picture = '$pc''");
}

?>

You won't get the notice, but you will get a warning about the undefined constant Picture.

Sorry to go off-topic here but actually, no, you don't get a warning about the undefined constant. That would only happen if you used {$row[Picture]}. In that case, {$row['Picture']} would be needed however if no curly braces are used then using $row[Picture] will have the desired effect without generating any level of errors.

 

I have tested this insofar as I always use it when expanding arrays inside strings. I only ever use the curly brace notation when doing object calls as they don't work without curly braces.

i currently use this script but i am getting no errors but the script is not changing the databse

<?php
include("../connect.php");
$cookie_info = explode("-", $_COOKIE['cookie_info']);
$dir = $cookie_info[0];
$pc = $_GET["p"]; 
$query  = "SELECT public FROM userpic WHERE userid = '$dir' AND Picture = '$pc' ";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
echo "{$row['public']}" .
 "$pc";
if($row['public'] == 0){
mysql_query ("UPDATE userpic SET public = '1' WHERE userid = '$dir' AND Picture = '$pc'");
}else{
mysql_query ("UPDATE userpic SET public = '0' WHERE userid = '$dir' AND Picture = '$pc''");
}

?>

Your last SQL query should generate an error because you've got too many quotes:

"UPDATE userpic SET public = '0' WHERE userid = '$dir' AND Picture = '$pc''"

should be:

"UPDATE userpic SET public = '0' WHERE userid = '$dir' AND Picture = '$pc'"

 

You might want to try putting 'or die(mysql_error())' (without the quotes) after your queries. Also, you should echo the values of $dir and $pc to make sure they're what you're expecting.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.