ckerr27 Posted April 23, 2012 Share Posted April 23, 2012 Hi everyone, I have been trying to get this code working but no matter what I try it will not work, I am trying to allow a user to update their personal details when they login to my website. I have created a form and submit button, the code is shwn below: <?php echo $_SESSION['myusername']; ?> <br><br> <form action="updated.php" method="post"> Firstname: <input type="text" name="firstname" /><br><br> Surname : <input type="text" name="surname" /><br><br> Date Birth: <input type="text" name="dob" /><br><br> Total Wins: <input type="text" name="wins" /> Total Loses: <input type="text" name="loses" /><br><br> Email Add: <input type="text" name="email" /><br><br> Country : <input type="text" name="born" /><br><br> Other Info: <input type="text" name="other" /><br><br> <input type="submit" name="Submit" value="Update" align="right"></td> </form> The updated.php file <?php mysql_connect ("localhost","root","") or die("Cannot connect to Database"); mysql_select_db ("test"); $sql=mysql_query("UPDATE memberdetails SET firstname='{$_POST['firstname']}', surname='{$_POST['surname']}', dob='{$_POST['dob']}', totalwins='{$_POST['wins']}', totalloses='{$_POST['loses']}', email='{$_POST['email']}', country='{$_POST['born']}', info='{$_POST['other']} WHERE username=$_SESSION['myusername']); if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "Details Updated"; ?> This is the error i recieve: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\website\updated.php on line 45 Line 45 is $sql=mysql_query line If anybody can help it will be very much appreciated! Quote Link to comment Share on other sites More sharing options...
xyph Posted April 23, 2012 Share Posted April 23, 2012 You're missing a closing double quote. Quote Link to comment Share on other sites More sharing options...
ckerr27 Posted April 23, 2012 Author Share Posted April 23, 2012 $sql=mysql_query("UPDATE memberdetails SET firstname='{$_POST['firstname']}', surname='{$_POST['surname']}', dob='{$_POST['dob']}', totalwins='{$_POST['wins']}', totalloses='{$_POST['loses']}', email='{$_POST['email']}', country='{$_POST['born']}', info='{$_POST['other']} WHERE username=$_SESSION['myusername']"); Thanks but it is still giving me the same error. Sorry i am not sure how to use php tags Quote Link to comment Share on other sites More sharing options...
xyph Posted April 23, 2012 Share Posted April 23, 2012 There's something else missing there. It's something you've done to every other similar expression in the string, but missed it on one. Quote Link to comment Share on other sites More sharing options...
ckerr27 Posted April 23, 2012 Author Share Posted April 23, 2012 I tried this code which is similar to code i used elsewhere but it is still giving me a error on the $sql=mysql_query line: <?php session_start(); echo $_SESSION['myusername']; mysql_connect ("localhost","root","") or die("Cannot connect to Database"); mysql_select_db ("test"); $sql = "UPDATE memberdetails WHERE username=$_SESSION['myusername']"; $result = mysql_query ($sql); while ($row = mysql_fetch_array($result)) { $firstname= $row["firstname"]; $surname= $row["surname"]; $dob= $row["dob"]; $wins= $row["totalwins"]; $loses= $row["totalloses"]; $email= $row["email"]; $born= $row["country"]; $other= $row["info"]; echo "<b><u>Firstname:</b></u> $firstname<br>"; echo "<b><u>Surname: </b> </u> $surname<br>"; echo "<b><u>Date of Birth:</b></u> $dob<br>"; echo "<b><u>Total Chess Wins:</b></u> $wins<br>"; echo "<b><u>Total Chess loses:</b></u> $loses<br>"; echo "<b><u>Email Address: </b></u> $email<br>"; echo "<b><u>Born in: </b></u> $born<br>"; echo "<b><u>Other Details:</b></u> $other<br><br><br>"; } ?> I am not sure if am on the correct track or not here?Sorry I am new to PHP Quote Link to comment Share on other sites More sharing options...
xyph Posted April 23, 2012 Share Posted April 23, 2012 We're not your personal debugging team. This is the same reason you were getting errors in reply #2. Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 23, 2012 Share Posted April 23, 2012 This is why I never do strings like that. OP, use an editor with syntax highlighting. Quote Link to comment Share on other sites More sharing options...
Drummin Posted April 23, 2012 Share Posted April 23, 2012 ckerr27 maybe if you take a look at the "info" xyph offered it would shed some light on things. He he. Quote Link to comment Share on other sites More sharing options...
ckerr27 Posted April 23, 2012 Author Share Posted April 23, 2012 Aye somebody is not happy!!!! Quote Link to comment Share on other sites More sharing options...
Drummin Posted April 23, 2012 Share Posted April 23, 2012 Hey sorry man. info='{$_POST['other']} is missing single quote. info='{$_POST['other']}' Quote Link to comment Share on other sites More sharing options...
ckerr27 Posted April 23, 2012 Author Share Posted April 23, 2012 Yes mate, Sorry I had already realised that updated it, $sql="UPDATE $tbl_name SET firstname='{$_POST['firstname']}', surname='{$_POST['surname']}', dob='{$_POST['dob']}', totalwins='{$_POST['wins']}', totalloses='{$_POST['loses']}', email='{$_POST['email']}', country='{$_POST['born']}', info='{$_POST['other']}' WHERE username='$_SESSION['myusername']'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } else { echo "Details Updated"; } ?> Still cannot find what is missing :'( By the way, I am not after people to debug this I am simply looking help as I am new to PHP and have been trying to get this for days. Thanks everyone who is trying to help Quote Link to comment Share on other sites More sharing options...
Danny620 Posted April 23, 2012 Share Posted April 23, 2012 username=$_SESSION['myusername'] should be username={$_SESSION['myusername']} Quote Link to comment Share on other sites More sharing options...
ckerr27 Posted April 23, 2012 Author Share Posted April 23, 2012 Thanks Danny!!Although this is what the page displayed: 1scott1Error: Unknown column '1scott1' in 'where clause' 1scott1 is the username of the logged in member Quote Link to comment Share on other sites More sharing options...
xyph Posted April 24, 2012 Share Posted April 24, 2012 Strings must be quoted in a MySQL query. You need to learn the basic syntax of the language before dealing with database interactions. If you couldn't find the issues with my guidance, you're probably just blankly staring at characters in a text editor. Start with the basics, work your way up. You'll find solving mis-types and inaccuracies in your code much easier. If you can't debug, you're coding beyond your abilities. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.