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.
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'");?>
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
patrik20
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?
StraySod
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:
<?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'");}?>
I have got error
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\dating\dating\run.php on line 6
line :
while ($rowimage=mysql_fetch_assoc($result)){