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
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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