teongkia Posted November 28, 2006 Share Posted November 28, 2006 <?phpmysql_connect("localhost","root","")or die(mysql_error());mysql_select_db("pnecnew")or die(mysql_error());$result = mysql_query("UPDATE example1 SET name='<a href="a1.php">a1</a>' WHERE id='1'") or die(mysql_error()); $result = mysql_query("SELECT * FROM example1 WHERE id='1'") or die(mysql_error()); // get the first (and hopefully only) entry from the result$row = mysql_fetch_array( $result );echo $row['name']." - ".$row['age']. "<br />";?>I tried on this code but error in line 5.What i wanted is to rename the column 'name' to <a href="a1.php">a1</a> which has the id=1.I have other rows which holds different ids and i wish to specify to update specific row which i like.Another question is how to delete data in specific row and insert data in specific row.For exampel row 3.Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/28700-databse-update-and-delete/ Share on other sites More sharing options...
btherl Posted November 29, 2006 Share Posted November 29, 2006 Rows in SQL do not have "numbers", like row 3. The only way to address them is by their columns, such as id. If you want to deal with the row with id 3, use [code=php:0]WHERE id = 3[/code]Regarding the error, try[code=php:0]$name = '<a href="a2.php">a2[/url]';$result = mysql_query("UPDATE example1 SET name='" . mysql_real_escape_string($name) . "' WHERE id='1'")[/code]mysql_real_escape_string() will do all the proper escaping for a mysql query. The problem you were having was because you have double quotes within your query, but you are also using double quotes to indicate the start and end of your query. Quote Link to comment https://forums.phpfreaks.com/topic/28700-databse-update-and-delete/#findComment-131988 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.