unexpected T_VARIABLE error using implode
02-07-2008, 07:45 PM
|
unexpected T_VARIABLE error using implode
|
Posts: 115
Name: Sharon
Location: Leicester, uk
|
Hiya everyone
can someone tell me whats wrong with this cause its giving me the error
Parse error: syntax error, unexpected T_VARIABLE in ........
PHP Code:
$lookingfor = array("$la", "$lb", "$lc", "$ld", "$le", "$lf", "$lg", "$lh", "$li", "$lj", "$lj", "$lk", "$ll", "$lm", "$ln");
$joinlookingfor = implode("-", $lookingfor);
for($i = 0; $i < count($joinlookingfor); $i++){echo "Piece #$i = $joinlookingfor[$i] <br/>";}
echo "joined together = $joinlookingfor";
it seems to work ok like this..
$lookingfor = array("hello", "there",.........
but not when i add variables instead of words :-(
thanks!
Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Last edited by Sharon_leic; 02-07-2008 at 09:18 PM..
|
|
|
|
02-07-2008, 10:58 PM
|
Re: unexpected T_VARIABLE error using implode
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
Try this:
PHP Code:
$lookingfor = array($la, $lb, $lc, $ld, $le, $lf, $lg, $lh, $li, $lj, $lj, $lk, $ll, $lm, $ln);
$joinlookingfor = implode("-", $lookingfor);
for($i = 0; $i < count($joinlookingfor); $i++)
{
echo "Piece #$i = $joinlookingfor[$i] <br/>";
}
echo "joined together = $joinlookingfor";
Did you get a line number with that error? unexpected T_WHATEVER usually occurs when you forget a semicolon but it looks like yours are all in the right places. Also... I cleaned up your for loop a bit. Its much easier to read when it isnt on one line.
|
|
|
|
02-09-2008, 08:18 PM
|
Re: unexpected T_VARIABLE error using implode
|
Posts: 115
Name: Sharon
Location: Leicester, uk
|
Thanks NullPointer
i figured it out last night then forgot to post again oops
i had some "'s that i didn't need and also got some variables wrong in my pre html form oops! lol
this code now works fine..(( messy i know )) but works cool
Shaz x
process_join.php
PHP Code:
<?
include( "inc/db.php" );
$name = $_POST['name']; $name = mysql_real_escape_string($name);
$password = $_POST['password']; $password = mysql_real_escape_string($password);
$email = $_POST['email']; $email = mysql_real_escape_string($email);
$country = $_POST['country']; $country = mysql_real_escape_string($country);
$city = $_POST['city']; $city = mysql_real_escape_string($city);
$anickname = $_POST['anickname']; $anickname = mysql_real_escape_string($anickname);
$asex = $_POST['asex'];
$aage = $_POST['aage'];
$asexuality = $_POST['asexuality'];
$asmoke = $_POST['asmoke'];
$adrink = $_POST['adrink'];
$arace = $_POST['arace'];
$abody = $_POST['abody'];
$aassets = $_POST['aassets'];
$aaboutme = $_POST['aaboutme']; $aaboutme = mysql_real_escape_string($aaboutme);
$bnickname = $_POST['bnickname']; $bnickname = mysql_real_escape_string($bnickname);
$bsex = $_POST['bsex'];
$bage = $_POST['bage'];
$bsexuality = $_POST['bsexuality'];
$bsmoke = $_POST['bsmoke'];
$bdrink = $_POST['bdrink'];
$brace = $_POST['brace'];
$bbody = $_POST['bbody'];
$bassets = $_POST['bassets'];
$baboutme = $_POST['baboutme']; $baboutme = mysql_real_escape_string($baboutme);
$la = $_POST['lookingfora'];
$lb = $_POST['lookingforb'];
$lc = $_POST['lookingforc'];
$ld = $_POST['lookingford'];
$le = $_POST['lookingfore'];
$lf = $_POST['lookingforf'];
$lg = $_POST['lookingforg'];
$lh = $_POST['lookingforh'];
$li = $_POST['lookingfori'];
$lj = $_POST['lookingforj'];
$lk = $_POST['lookingfork'];
$ll = $_POST['lookingforl'];
$lm = $_POST['lookingform'];
$ln = $_POST['lookingforn'];
$aa = $_POST['activitiesa'];
$ab = $_POST['activitiesb'];
$ac = $_POST['activitiesc'];
$ad = $_POST['activitiesd'];
$ae = $_POST['activitiese'];
$af = $_POST['activitiesf'];
$ag = $_POST['activitiesg'];
$ah = $_POST['activitiesh'];
$ai = $_POST['activitiesi'];
$aj = $_POST['activitiesj'];
$ak = $_POST['activitiesk'];
$al = $_POST['activitiesl'];
$am = $_POST['activitiesm'];
$an = $_POST['activitiesn'];
$ao = $_POST['activitieso'];
$ap = $_POST['activitiesp'];
$aq = $_POST['activitiesq'];
$ar = $_POST['activitiesr'];
$as = $_POST['activitiess'];
$at = $_POST['activitiest'];
$oa = $_POST['onsitefora'];
$ob = $_POST['onsiteforb'];
$oc = $_POST['onsiteforc'];
$od = $_POST['onsiteford'];
$oe = $_POST['onsitefore'];
$of = $_POST['onsiteforf'];
$og = $_POST['onsiteforg'];
$oh = $_POST['onsiteforh'];
$oi = $_POST['onsitefori'];
$meetfromage = $_POST['meetfromage']; echo "<br>";
$meettoage = $_POST['meettoage']; echo "<br>";
$willmeetsmokers = $_POST['willmeetsmokers']; echo "<br>";
$lookingfor = array($la,$lb,$lc,$ld,$le,$lf,$lg,$lh,$li,$lj,$lj,$lk,$ll,$lm,$ln);
$joinlookingfor = implode("|", $lookingfor);
$activities = array($aa,$ab,$ac,$ad,$ae,$af,$ag,$ah,$ai,$aj,$aj,$ak,$al,$am,$an,$ao,$ap,$aq,$ar,$as,$at);
$joinactivities = implode("|", $activities);
$onsitefor = array($oa,$ob,$oc,$od,$oe,$of,$og,$oh,$oi);
$joinonsitefor = implode("|", $onsitefor);
mysql_query("INSERT INTO Profiles (login, password, email, country, city, anickname, asex, aage, asexuality, asmoke, adrink, arace, abodytype, aassets, aaboutme, bnickname, bsex, bage, bsexuality, bsmoke, bdrink, brace, bbodytype, bassets, baboutme, lookingfor, activities, onsitefor, agefrom, ageto, meetsmokers) VALUES ('$name', '$password', '$email', '$country', '$city', '$anickname', '$asex', '$aage', '$asexuality', '$asmoke', '$adrink','$arace', '$abody', '$aassets', '$aaboutme', '$bnickname', '$bsex', '$bage', '$bsexuality', '$bsmoke', '$bdrink','$brace', '$bbody', '$bassets', '$baboutme', '$joinlookingfor', '$joinactivities', '$joinonsitefor', '$meetfromage', '$meettoage', '$willmeetsmokers') ") or die(mysql_error());
echo "<center><h2>Your profile has now been created</2></center><br>";
echo "<center><h2>and you may now log in.</2></center><br><br>";
echo "<center><h3>Your username is </h3>$name<br></center>";
echo "<center><h3>Your password is </h3>$password<br></center>";
echo "<center><h3>Your email is </h3>$email<br><br><br></center>";
echo "<center><h4>Please write down your information before you forget!</h4><br></center>";
cho "<center><a href='index.php'>Click here to continue</a><br></center>";
?>
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Last edited by Sharon_leic; 02-10-2008 at 02:13 AM..
|
|
|
|
|
« Reply to unexpected T_VARIABLE error using implode
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|