Alex2k15 Posted August 6, 2015 Share Posted August 6, 2015 Yeah idk what's wrong and i want some help. Let's start with edit.php <?php session_start(); include_once 'dbconnect.php'; if(!isset($_SESSION['user'])) { header("Location: index.php"); } $res=mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']); $userRow=mysql_fetch_array($res); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Home - <?php echo $userRow['username']; ?></title> <link rel="stylesheet" href="css/style.css" type="text/css" /> </head> <body> <div id="header"> <div id="left"> <label>Chillz</label> </div> <div id="right"> <div id="content"> Welcome, <?php echo $userRow['username']; ?> <a href="logout.php?logout">Sign Out</a> </div> </div> </div> <div id="body"> <b>Edit your Profile</b> <br><br> Please enter your details below to update your profile. <br><br> <form method="post" action="editprofile.php" name="editform" id="editform"> <table width=700px border=0 cellspacing=10><tr><td valign=top><table border=0> <b>Required Information:</b><br><br> <tr><td> <b>Username:</b> </td><td> <?php echo $username; ?> </td></tr><tr><td> <b>Email Address:</b> </td><td> <input type="text" name="email" id="email" value="<?php echo $email; ?>"> </td></tr></table></td><td valign=top> <table border=0> <b>Optional Information:</b><br><br> <tr><td> <b>Location:</b> </td><td> <input type="text" name="location" id="location" value="<?php echo $location; ?>"> </td></tr><tr><td> <b>Your Website:</b> </td><td> <input type="text" name="website" id="website" value="<?php echo $website; ?>"> </tr></td><tr><td valign=top> <b>Short About:</b> </td><td> <textarea name="about" id="about" rows="10" cols="20"><?php echo $about; ?></textarea> </td></tr></td> </table> </td></tr> </table> <input type="submit" name="register" id="register" value="Update" class=btn /> </form> </div> <?php $editquery = mysql_query("Update users (email, location, website, about) VALUES('".$email."', '".$location."', '".$website."', '".$about."')"); if($editquery ==) { echo "<b>Success!</b>"; echo "Your profile was successfully updated. Please click<a href=\"viewprofile.php\"> here </a>to view."; } else { echo "<b>Error</b>"; echo "<p>Sorry, your profile update failed. Please go back and try again.</p>"; } ?> </div> </body> </html> I can't upload an image but here is the urls: http://i.imgur.com/ZkHMM4a.jpg http://i.imgur.com/HsAhfiM.jpg I want to remove the error part. Plus i was hoping someone can help me work on the profile part Quote Link to comment Share on other sites More sharing options...
NomadicJosh Posted August 6, 2015 Share Posted August 6, 2015 (edited) You are using INSERT syntax instead of UPDATE syntax. Your UPDATE query should follow this syntax: UPDATE table_name SET field1=new-value1, field2=new-value2 WHERE field = value; Edited August 6, 2015 by parkerj Quote Link to comment Share on other sites More sharing options...
Alex2k15 Posted August 7, 2015 Author Share Posted August 7, 2015 You are using INSERT syntax instead of UPDATE syntax. Your UPDATE query should follow this syntax: UPDATE table_name SET field1=new-value1, field2=new-value2 WHERE field = value; It does say update Quote Link to comment Share on other sites More sharing options...
scootstah Posted August 7, 2015 Share Posted August 7, 2015 Yes but it's using the INSERT syntax, not UPDATE syntax. Look at his example compared to your code. Quote Link to comment Share on other sites More sharing options...
Alex2k15 Posted August 7, 2015 Author Share Posted August 7, 2015 so pretty much like this $editquery = mysql_query("UPDATE users SET email=$email, password=$password, location=$location, picture=$picture, website=$website, about=$about WHERE user_id=._SESSION['user']); Quote Link to comment Share on other sites More sharing options...
NomadicJosh Posted August 8, 2015 Share Posted August 8, 2015 Yes, that is the correct syntax, but in your example, you're missing the closing quotation, so you have to be careful of that. Quote Link to comment Share on other sites More sharing options...
Alex2k15 Posted August 8, 2015 Author Share Posted August 8, 2015 (edited) Yes, that is the correct syntax, but in your example, you're missing the closing quotation, so you have to be careful of that. This is how it looks: <?php session_start(); include_once 'dbconnect.php'; if(!isset($_SESSION['user'])) { header("Location: index.php"); } $res=mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']); $userRow=mysql_fetch_array($res); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Home - <?php echo $userRow['username']; ?></title> <link rel="stylesheet" href="css/style.css" type="text/css" /> </head> <body> <div id="header"> <div id="left"> <label>Chillz</label> </div> <div id="right"> <div id="content"> Welcome, <?php echo $userRow['username']; ?> <a href="logout.php?logout">Sign Out</a> </div> </div> </div> <div id="body"> <b>Edit your Profile</b> <br><br> Please enter your details below to update your profile. <br><br> <form method="post" action="editprofile.php" name="editform" id="editform"> <table width=700px border=0 cellspacing=10><tr><td valign=top><table border=0> <b>Required Information:</b><br><br> <tr><td> <b>Username:</b> </td><td> <?php echo $username; ?> </td></tr><tr><td> <b>Email Address:</b> </td><td> <input type="text" name="email" id="email" value="<?php echo $email; ?>"> </td></tr></table></td><td valign=top> <table border=0> <b>Optional Information:</b><br><br> <tr><td> <b>Location:</b> </td><td> <input type="text" name="location" id="location" value="<?php echo $location; ?>"> </td></tr><tr><td> <b>Your Website:</b> </td><td> <input type="text" name="website" id="website" value="<?php echo $website; ?>"> </tr></td><tr><td valign=top> <b>Short About:</b> </td><td> <textarea name="about" id="about" rows="10" cols="20"><?php echo $about; ?></textarea> </td></tr></td> </table> </td></tr> </table> <input type="submit" name="register" id="register" value="Update" class=btn /> </form> <?php $editquery = mysql_query("UPDATE users SET email=$email, password=$password, location=$location, picture=$picture, website=$website, about=$about WHERE user_id=._$SESSION['user']); if($editquery) { echo "<b>Success!</b>"; echo "Your profile was successfully updated. Please click<a href=\"profile.php\"> here </a>to view."; } else { echo "<b>Error</b>"; echo "<p>Sorry, your profile update failed. Please go back and try again.</p>"; } ?> </div> </body> </html> i feel like i did the WHERE part wrong. Plus i get this error. Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/u890091543/public_html/login/edit.php on line 68 Edited August 8, 2015 by Alex2k15 Quote Link to comment Share on other sites More sharing options...
NomadicJosh Posted August 8, 2015 Share Posted August 8, 2015 Just like I said, you are missing the ending quotation at the end of the where clause. It should look something like this: <?php $editquery = mysql_query("UPDATE users SET email=$email, password=$password, location=$location, picture=$picture, website=$website, about=$about WHERE user_id='" ._$SESSION['user'] . "'"); ?> Quote Link to comment Share on other sites More sharing options...
Alex2k15 Posted August 8, 2015 Author Share Posted August 8, 2015 http://i.imgur.com/rkCyozv.jpg Look at the botom part. That is suppose to show only after i edit the profile. Can we fix that? 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.