patrik20
asked on
Copy values from a column and then adding .jpg to this value and paste it to the new column
Hi
I have added a new column to a table and I will copy the values from that a different column ( from the same table ) and then adding .jpg to this values and paste it to the new column.
Can please somebody correct my database query and my phpscript.
I have added a new column to a table and I will copy the values from that a different column ( from the same table ) and then adding .jpg to this values and paste it to the new column.
Can please somebody correct my database query and my phpscript.
SQL query on database not works:
UPDATE `profile_pic` SET `pic1` = `username` + `.jpg`
Even this script not works:
<?php
require_once 'admin/serverdata.php';
$conn = mysql_connect("$dbHost","$dbUser","$dbPass");
$db = mysql_select_db("$dbName");
$result=mysql_query("select * from profile_pic");
$rowimage=mysql_fetch_assoc($result);
$pic1=$rowimage["username"];
$pic1jpg= $pic1.'.jpg';
$result= mysql_query("UPDATE profile_pic SET pic1 = '$pic1jpg'");
?>
UPDATE `profile_pic` SET `pic1` = concat( `username`,`.jpg`)
sorry, need apostrophes for .jpg
UPDATE `profile_pic` SET `pic1` = concat( `username`,'.jpg')
in php script:
you need where clause in select statement to uniquely identify the row.
the way you do it, you always use the first row of result set
you need where clause in select statement to uniquely identify the row.
the way you do it, you always use the first row of result set
and you need the where clause in update statement too, otherwise you'll update all rows in database table profile_pic to have the same value
ASKER
Hi StraySod
Thanks for your reply, Your SQL ouery works fine, thanks.
About thr php script, I have two rows in this table username (uniq) and pic1. How shoud I have where clause in select and uppdate statment to make it works?
Thanks for your reply, Your SQL ouery works fine, thanks.
About thr php script, I have two rows in this table username (uniq) and pic1. How shoud I have where clause in select and uppdate statment to make it works?
you must know the username value in you script. should be sent by a form or something, don't know what exactly your source structure is etc. but if you could determine the username value, then you won't need any select statement.
Or do you want to update all columns? If so, do it like this:
Or do you want to update all columns? If so, do it like this:
<?php
require_once 'admin/serverdata.php';
$conn = mysql_connect("$dbHost","$dbUser","$dbPass");
$db = mysql_select_db("$dbName");
$result=mysql_query("select * from profile_pic");
while ($rowimage=mysql_fetch_assoc($result)){
$pic1=$rowimage["username"];
$pic1jpg= $pic1.'.jpg';
$result= mysql_query("UPDATE profile_pic SET pic1 = '$pic1jpg' WHERE username = '$pic1'");
}
?>
ASKER
I have got error
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\dating\dat ing\run.ph p on line 6
line :
while ($rowimage=mysql_fetch_ass oc($result )){
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\dating\dat
line :
while ($rowimage=mysql_fetch_ass
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
same error:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\dating\dat ing\run.ph p on line 6
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\dating\dat
ASKER
I have changed other query´s name from result to result2, now everything is fine, Thank you