Jump to content

Trouble with update command


andrew_biggart

Recommended Posts

Ok i have literally been trying to get this to work since i have came out of the womb, well it feels like that..... But im just trying to get a simple update your profile page working. So i have this form which echo's the current info to the text boxes and then you can change what you want.

 

Editprofile.php

 

<table class="myprofile_change">
<tr><td class="myprofile_changesh">Edit Profile</td></tr>
<tr><td class="myprofile_subtext2">Scroll down, complete the fields, then click Save Changes to update your profile. All of the following questions are optional, but you must answer a minimum of 5 to appear in our search results.</td></tr>
<tr><td></td></tr>
</table>
<br />
<table>
<tr><td class="myprofile_changesh">General Info ...</td></tr>
</table>
<form method="post" action="my_profile_edit_submit.php">
<?php

include("config.php");

// Retrieve data from database 
$sql="SELECT * FROM User_infoT WHERE Username='".$_SESSION["myusername"].  "'";
$result=mysql_query($sql);

// Start looping rows in mysql database.
while($rows=mysql_fetch_array($result)){
?>
<table class="myprofile_change">
<tr><td class="myprofile_subtext">Your Status :</td><td>
	<input name="status" id="status" type="text" value="<? echo $rows['Status']; ?>" style="width: 417px" /></td></tr>
</table>
<br />

<table class="myprofile_change">
<tr><td class="myprofile_subtext">Location :</td><td><input name="Location" id="Location" type="text" value="<? echo $rows['Location']; ?>" /></td></tr>
<tr><td class="myprofile_subtext">Favourite smoking method :</td>
<td><select name="Fav" id="Fav"style="width: 126px">
	<option>Choose</option>
	<option>Joint</option>
	<option>Blunt</option>
	<option>Tulip</option>
	<option>Bong</option>
	<option>Lung</option>
	<option>Bucket</option></select></td></tr>
<tr><td class="myprofile_subtext">Favourite quote :</td><td><input name="Quote" id="Quote"type="text" style="width: 246px" maxlength="50 "value="<? echo $rows['Quote']; ?>" /></td><td class="myprofile_max">Max 50 characters</td></tr>
<tr><td></td></tr>
</table>
<br />
<table>
<tr><td class="myprofile_changesh">About me ...</td></tr>
</table>
<br />
<table>
<tr><td class="myprofile_subtext">About Yourself :</td><td rowspan="2"><textarea name="Aboutme" id="Aboutme" style="width: 415px; height: 135px"><? echo $rows['Aboutme']; ?></textarea></td></tr>
<tr><td class="myprofile_max2">Use <br /> to separate paragraphs instead 
	of using the return button</td></tr>
</table>
<br />
<table class="myprofile_change">
<tr><td class="myprofile_subtext">Why do you love weed? :</td>
	<td rowspan="2"><textarea name="Whywe" id="Whywe" style="width: 415px; height: 135px" ><? echo $rows['Whywe']; ?></textarea></td></tr>
<tr><td class="myprofile_max2">Use <br /> to separate paragraphs instead 
	of using the return button</td></tr>
<tr><td></td></tr>
</table>
<br />
<table>
<tr><td class="myprofile_changesh">Personal info ...</td></tr>
</table>
<br />
<table class="myprofile_change">
<tr><td class="myprofile_subtext">Interests :</td><td><input name="Interests" id="Interests" type="text" style="width: 246px" value="<? echo $rows['Interests']; ?>" /></td><td class="myprofile_max">Max 50 characters</td></tr>
<tr><td class="myprofile_subtext">Makes me happy :</td><td><input name="Happy" id="Happy"type="text" style="width: 246px" value="<? echo $rows['Happy']; ?>"/></td><td class="myprofile_max">Max 70 characters</td></tr>
<tr><td class="myprofile_subtext">Makes me sad :</td><td><input name="Sad" id="Sad"type="text" style="width: 246px" value="<? echo $rows['Sad']; ?>" /></td><td class="myprofile_max">Max 70 characters</td></tr>
<tr><td class="myprofile_subtext">Bad habits :</td><td><input name="Habits" id="Habits"type="text" style="width: 246px" value="<? echo $rows['Habits']; ?>" /></td><td class="myprofile_max">Max 60 characters</td></tr>
<tr><td></td></tr>
</table>
<br />
<table>
<tr><td class="myprofile_changesh">Favourite things ...</td></tr>
</table>
<br />
<table class="myprofile_change">
<tr><td class="myprofile_subtext">Music :</td><td><select id="Music"name="Music" style="width: 126px">
<option>Choose</option>
<option>Dance</option>
<option>RnB</option>
<option>Funky House</option>
<option>Indie</option>
<option>Rock</option>
<option>Electro</option>
<option>Chillout</option>
</select></td></tr>
<tr><td class="myprofile_subtext">Movies :</td><td><input name="Movie" id="Movie"type="text" style="width: 246px" value="<? echo $rows['Movie']; ?>" /></td><td class="myprofile_max">Max 100 characters</td></tr>
<tr><td class="myprofile_subtext">Website :</td><td><input name="Website" id="Website"type="text" style="width: 246px" value="<? echo $rows['Website']; ?>"/></td><td class="myprofile_max">No spamming</td></tr>
<tr><td></td></tr>
</table>
<?
// close while loop 
}

// close connection 
mysql_close();
?>
<br />
<table>
<tr><td class="myprofile_changesh">Save the changes to your profile ...</td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
</table>
<br />
<table class="myprofile_change">
<tr><td><input name="Submit1" type="submit" value="Change that shit !" /></td></tr>
</table>
<br />
<br />
<br />
<br />
<br />
<br />
</form>

 

and then i have the following code for the php but i cant get it to work at all it either deletes all the information for that user or else gives me a blank page please can someone help? i have my session start at the top of the page so it isnt that.

 

editprofilesubmit.php

 

<?php
session_start();
if(isset($_SESSION['myusername'])) {
}
else{
header("location:login.php");
}
// Check the user is logged in
?>
<?php

include("config.php");

$username=$_SESSION['myusername']; 
$Location = ($_POST['Location']);
$Fav = ($_POST['Fav']);
$Quote = ($_POST['Quote']);
$Interests = ($_POST['Interests']);
$Happy = ($_POST['Happy']);
$Sad = ($_POST['Sad']);
$Habits = ($_POST['Habits']);
$Music = ($_POST['Music']);
$Movie = ($_POST['Movie']);
$Website = ($_POST['Website']);
$Aboutme = ($_POST['Aboutme']);
$Whywe = ($_POST['Whywe']);
$Status = ($_POST['status']);



$sql = "UPDATE User_infoT ( Location, Fav, Quote, Interests, Happy, Sad, Habits, Music, Movie, Website, Aboutme, Whywe, Status) VALUES( '$Location', '$Fav', '$Quote', '$Interests', '$Happy', '$Sad', '$Habits' , '$Music', '$Movie', '$Website', '$Aboutme', '$Whywe', '$Status' ) WHERE Username='$username' ;
$result=mysql_query($sql) or die(mysql_error().": $sql");
if($result){
     
header("my_profile.php");
}
else {
header("profile_edit.php");
}
// close connection
mysql_close();
?>

Link to comment
Share on other sites

Don't know where it would be deleting all of your data, there are no delete statements.

 

The blank page is probably caused by (need and ending double quote):

 

$sql = "UPDATE User_infoT ( Location, Fav, Quote, Interests, Happy, Sad, Habits, Music, Movie, Website, Aboutme, Whywe, Status) VALUES( '$Location', '$Fav', '$Quote', '$Interests', '$Happy', '$Sad', '$Habits' , '$Music', '$Movie', '$Website', '$Aboutme', '$Whywe', '$Status' ) WHERE Username='$username'";

Link to comment
Share on other sites

this is the error i am now getting on screen !!

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '( Location, Fav, Quote, Interests, Happy, Sad, Habits, Music, Movie, Website, Ab' at line 1: UPDATE User_infoT ( Location, Fav, Quote, Interests, Happy, Sad, Habits, Music, Movie, Website, Aboutme, Whywe, Status) VALUES( 'Manchester, UK', 'Choose', 'I like a blunt or a big fat cone, but this double barelled bong is getting me stoned!', 'Webdesigning, Numbing myself & dressing up like a hotdog', 'When this site runs smothly & i can just chillax', 'Spammers, cheap skates & hackers', 'Sitting up all night smoking and sleeping all day' , 'Choose', 'Half Baked & Pineapple express', 'http://www.andrewbiggart.co.uk', 'I\'m about as random as a banana boat on steroids!

Yes i am Irish, and yes I will drink & smoke with you until I pass out!

I love piercings and tattoo\'s, they really tickle my pickle!

Couldn\'t really give a shit if people like me on hear, if you dont like it dont fucking use the site, im not gaining anything or losing anything by you being hear or not ! Cant be bothered with game players, knob ends and stuck up people! so don\'t bother messaging me  And also if u have to pull your head out of your own ass to talk to me don\'t bother Ive got no time for people who love their self more than they could ever love anyone else 

Ive been smoking the sweet stuff for far far far to long now, but im now a part time smoker instead of an every minute of every hour or every second smoker. I realised if u want to get anything done in life u need to lay off the web abit to be honest otherwise you will never get out of your boxers & never stop playing xbox.

Loving the new kings of leon album 

P.S Kayne West-Heartless is the shinizzle ', 'Because i like to be numb!

I like to smoke this shit as it makes me cretive as fuck, i mean look at this site for an example! Would a non-pothead have had the patients to crete this shit i dont think so lol It is always a very good way to chil a mother fucker out if he is stressed to the eyeballs, girlfriends on his back, boss is trying to hump his leg etc etc!

Im so feed up with this bullshit the government has put on the news about weed and had it raised to a class B drug again, did someone say scare tactics? This world needs to wake up and realise we are being controlled far to fucking much, free will & freedom of spek my fucking ass.

As Bill Hicks once said, Why is marijuana against the law? It grows naturally upon our planet. Doesn\'t the idea of making nature against the law seem to you a bit . . . unnatural', 'Is sitting in his boxers playing xbox smoking lungs! 222222' ) WHERE Username='AdMiN'

Link to comment
Share on other sites

This is the php code i am using now! can anyone spot an error?

 

<?php
session_start();
if(isset($_SESSION['myusername'])) {
}
else{
header("location:login.php");
}
// Check the user is logged in
?>
<?php

include("config.php");

$username=$_SESSION['myusername']; 
$Location = ($_POST['Location']);
$Fav = ($_POST['Fav']);
$Quote = ($_POST['Quote']);
$Interests = ($_POST['Interests']);
$Happy = ($_POST['Happy']);
$Sad = ($_POST['Sad']);
$Habits = ($_POST['Habits']);
$Music = ($_POST['Music']);
$Movie = ($_POST['Movie']);
$Website = ($_POST['Website']);
$Aboutme = ($_POST['Aboutme']);
$Whywe = ($_POST['Whywe']);
$Status = ($_POST['status']);



$sql = "UPDATE User_infoT ( Location, Fav, Quote, Interests, Happy, Sad, Habits, Music, Movie, Website, Aboutme, Whywe, Status) VALUES( '$Location', '$Fav', '$Quote', '$Interests', '$Happy', '$Sad', '$Habits' , '$Music', '$Movie', '$Website', '$Aboutme', '$Whywe', '$Status' ) WHERE Username='$username'";
$result=mysql_query($sql);
if($result){
     
header("my_profile.php");
}
else {
header("profile_edit.php");
}
// close connection
mysql_close();
?>

Link to comment
Share on other sites

I have never seen an update statement work like that. I am not saying that it cannot or does not.

 

But here are some spots you might want to read over and reform your query:

 

http://dev.mysql.com/doc/refman/5.0/en/update.html

and or

http://dev.mysql.com/doc/refman/5.1/en/replace.html

 

Not sure if replace is right for you, but it maybe.

Link to comment
Share on other sites

I have also tried doing this way but im having no success i just cannot see what i am doing wrong!!!

 


<?php
session_start();
if(isset($_SESSION['myusername'])) {
}
else{
header("location:login.php");
}
// Check the user is logged in
?>
<?php

include("config.php");

$Username=$_SESSION['myusername']; 
$Location = ($_POST['Location']);
$Fav = ($_POST['Fav']);
$Quote = ($_POST['Quote']);
$Interests = ($_POST['Interests']);
$Happy = ($_POST['Happy']);
$Sad = ($_POST['Sad']);
$Habits = ($_POST['Habits']);
$Music = ($_POST['Music']);
$Movie = ($_POST['Movie']);
$Website = ($_POST['Website']);
$Aboutme = ($_POST['Aboutme']);
$Whywe = ($_POST['Whywe']);
$Status = ($_POST['status']);

$sql = "UPDATE User_infoT  SET Location='$Location', Fav='$Fav', Quote='$Quote', Interests='$Interests', Happy='$Happy', Sad='$Sad', Habits='$Habits', Music='$Music', Movie='$Movie', Website='$Website', Aboutme='$Aboutme', Whywe='$Whywe', Status='$Status' WHERE Username='$Username'";
$result=mysql_query($sql) or die(mysql_error().": $sql");
if($result){
     
header("my_profile.php");
}
else {
header("profile_edit.php");
}
// close connection
mysql_close();
?>

Link to comment
Share on other sites

its saying this now! with the above code!!

 

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, root@server.microlite20.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Link to comment
Share on other sites

if you're performing a redirect then these need to be header('Location: path/to/page.php');

 

header("my_profile.php");
}
else {
header("profile_edit.php");

 

Also check your servers error logs for why you're getting a 500 Internal Server Error.

Link to comment
Share on other sites

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.