Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to use a quote as a variable?
Old 06-11-2005, 08:45 AM How to use a quote as a variable?
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
I need to make a quote sign " into a variable to use with this code which im making, because I can't put the quote into this code can I?

PHP Code:
<?
function tags($tutorial) {
$quote '"';
    
$tutorial str_replace("<?""&lt;?"$tutorial);
    
$tutorial str_replace("<?php""&lt;?php"$tutorial);
    
$tutorial str_replace("?>""?&gt;?"$tutorial);
    
$tutorial str_replace("".$quote."""&quot;"$tutorial);

    return(
$tutorial);
}
?>
feraira is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-11-2005, 09:19 AM
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
When declaring the variable 'cancel out' the quote with a '\' so it reads it as a character as opposed to some part of the php code.

i.e.

$quote = "\"";

Hope this helps
stoot
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 06-11-2005, 10:39 AM
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Yeah thanks mate, that's sorted the problem, I knew I would have to do that, but I tried it a few different ways and I couldn't do it lol... Just one of those things I guess Thanks anyway

Don't suppose you could help with this though could you?

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/xingeh/public_html/test/insert.php on line 32

PHP Code:
<?

include("tags.php");

$tname $_GET['tname'];
$ttype $_GET['ttype'];
$caption $_GET['caption'];
$tutorial $_GET['tutorial'];
$author $_GET['author'];

if(!
$tname) {
exit(
"You need to input a title for the tutorial");
}
if(!
$ttype) {
exit(
"You need to input a type of tutorial");
}
if(!
$caption) {
exit(
"You need to input a caption");
}
if(!
$author) {
exit(
"You need to input an author for the tutorial!");
} else {

$tname addslashes($tname);
$caption addslashes($caption);
$tutorial addslashes($tutorial);
$tutorial tags($tutorial);

mysql_connect("localhost""lalala""lalalala") or die("Could not connect to DB because: ".mysql_error());
mysql_select_db("lalala") or die("Could not select the DB because: ".mysql_error());

$query "INSERT INTO tutorials VALUES ('', '".$tname."', '".$ttype."', '".$caption"', '".$tutorial."', '".$author."')";
mysql_query($query) or die("Could not complete query because: ".mysql_error());

?>
feraira is offline
Reply With Quote
View Public Profile
 
Old 06-11-2005, 11:42 AM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
PHP Code:
$quote '"'
This is completely valid and should work, did you have problems with it? Anything inside single quotes is taken as a literal string so php does not parse variables or spechial characters within the singe quotes.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 06-11-2005, 03:38 PM
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
When you're adding the info to the database i dont think you need the double quotes and the full stop - when your adding this the single quote with a variable should work fine and take the variable rather than the string. Also the way i do it (may work other ways) but i have the field your adding the variable into there too, as below.

PHP Code:
$query "INSERT INTO tutorials ( id, title, body)
                                                values( '
$id, '$title, '$body)"
Hope this helps.
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 06-11-2005, 09:32 PM
ccp
ccp's Avatar
Average Talker

Posts: 28
Trades: 0
Dude, stoot98 is completely right. You are inserting values without saying where to insert them.

and you don't need the double quotes inside the single qoutes and the periods also aren't going to give you the results you want.

Here is the basic syntax courtesy of HTML Kit...
Code:
INSERT INTO tablename (col1, col2, ...) VALUES ('val1', 'val2', ...)
ccp is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to use a quote as a variable?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23511 seconds with 12 queries