Jump to content

Databse update and delete..


teongkia

Recommended Posts

<?php
mysql_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.
Link to comment
https://forums.phpfreaks.com/topic/28700-databse-update-and-delete/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.