Accurax Posted December 11, 2006 Share Posted December 11, 2006 Im trying to insert dtaa into an established database, and i want the data to go into the correct place for each user, I am trying to get the following to work, but im starting to worry that im off the mark a little.... any tips please?[code]$query = "INSERT INTO members WHERE user_name='$username'(picture) VALUES ('$filepath')";$result = mysql_query($query) or die ("could not add picture.");[/code] Link to comment https://forums.phpfreaks.com/topic/30234-is-theis-syntax-completely-wrong/ Share on other sites More sharing options...
mansuang Posted December 11, 2006 Share Posted December 11, 2006 [code]$query = "INSERT INTO members (user_name, picture) VALUES ('$username', '$filepath')";$result = mysql_query($query) or die ("could not add picture.");[/code] Link to comment https://forums.phpfreaks.com/topic/30234-is-theis-syntax-completely-wrong/#findComment-139026 Share on other sites More sharing options...
craygo Posted December 11, 2006 Share Posted December 11, 2006 yes[code]$query = "INSERT INTO members ('picture') Values ('$filepath') WHERE user_name='$username'";[/code]Or I like to use the set function[code]$query = "INSERT INTO members SET picture = '$filepath' WHERE user_name='$username'";[/code]Either will doRay Link to comment https://forums.phpfreaks.com/topic/30234-is-theis-syntax-completely-wrong/#findComment-139027 Share on other sites More sharing options...
Accurax Posted December 11, 2006 Author Share Posted December 11, 2006 that looks like its going to insert the Username again........ i dont want to do that... i just want to add the picture to a given users row in the table Link to comment https://forums.phpfreaks.com/topic/30234-is-theis-syntax-completely-wrong/#findComment-139028 Share on other sites More sharing options...
Accurax Posted December 11, 2006 Author Share Posted December 11, 2006 thanks craygo... ill give it a go :) Link to comment https://forums.phpfreaks.com/topic/30234-is-theis-syntax-completely-wrong/#findComment-139029 Share on other sites More sharing options...
Accurax Posted December 11, 2006 Author Share Posted December 11, 2006 It doesnt work mate.... file uploads correctly, but the $filepath variable doesnt go to the database, heres the code, can u see the problem?[code]<?phpsession_start();include("conection.inc");if ( $_SESSION['login'] != "true" ) { header("location: hacker.php"); }else { $filepath = "/pictures/".$_FILES['filename']['name']; echo $filepath; $source = "pictures"; move_uploaded_file($_FILES['filename']['tmp_name'], "../mysite/$source/".$_FILES['filename']['name']); } $connection=mysql_connect($host, $user, $passwd) or die ("Could not connect !"); $db = mysql_select_db($database, $connection) or die ("Could not connect to Database"); $query = "INSERT INTO members ('picture') VALUES ('$filepath') WHERE user_name='$username'";$result = mysql_query($query) or die ("could not add picture.");?>[/code] Link to comment https://forums.phpfreaks.com/topic/30234-is-theis-syntax-completely-wrong/#findComment-139036 Share on other sites More sharing options...
mansuang Posted December 11, 2006 Share Posted December 11, 2006 Try UPDATE instead of INSERT[code]$query = "UPDATE members SET picture = '$filepath' WHERE user_name='$username'";[/code]I am not sure this is help or not Link to comment https://forums.phpfreaks.com/topic/30234-is-theis-syntax-completely-wrong/#findComment-139038 Share on other sites More sharing options...
Accurax Posted December 11, 2006 Author Share Posted December 11, 2006 i think thats may have helped.......... its stopped going through to the or die staement at least......... but the picture still isnt turning up in the database .... i have the field 'picture' set to varchar 200 in mysql if that helps? Link to comment https://forums.phpfreaks.com/topic/30234-is-theis-syntax-completely-wrong/#findComment-139040 Share on other sites More sharing options...
Accurax Posted December 11, 2006 Author Share Posted December 11, 2006 sok i got it..... i needed to put$username = $_SESSION['username'];before the querythanks guys :) Link to comment https://forums.phpfreaks.com/topic/30234-is-theis-syntax-completely-wrong/#findComment-139041 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.