copy a link to sql via php script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Adiefallguy
Forum Newbie
Posts: 5
Joined: Thu Nov 11, 2010 7:05 am

copy a link to sql via php script

Post by Adiefallguy »

Hi All,

Im trying to store a link in my sql database and for some reason it just will not update the Update field where the link should be.
Below is the code im using and I cannot figure out what I have done wrong for it not to update the sql database.

Code: Select all

<?

$Number=$_GET['ID'];

$username="username";
$password="password";
$database="database";

mysql_connect(Localhost,$username,$password);
@mysql_select_db($database) or die("Unable to select database");

$query="UPDATE nmbcdiary SET Update='http://nottinghammodelboatclub.freehostia.com/Admin/Editevent.php?ID=$Number' WHERE Number='$Number' ";
echo $query;
mysql_query($query);

echo "Link Updated";

?>
when it echo's the query it looks perfect to me but it will not update and im pulling my hair out, I Just know its going to be something silly that I have overlooked for the past hour.

Thanks
Adie
User avatar
saltwine
Forum Newbie
Posts: 16
Joined: Tue Nov 09, 2010 7:05 am
Location: London

Re: copy a link to sql via php script

Post by saltwine »

It could be this line

Code: Select all

mysql_connect(Localhost,$username,$password);

// localhost should be a string
mysql_connect('localhost',$username,$password);
It might be obvious... but is there a row in your table where Number = $Number?
Adiefallguy
Forum Newbie
Posts: 5
Joined: Thu Nov 11, 2010 7:05 am

Re: copy a link to sql via php script

Post by Adiefallguy »

Hi All,

The localhost was changed in the script to the proper address and the connection works as its the same in all my other scripts i have working.

$number is the variable holding the unique id number that was obtained at the start from the url.

Number is the name of the field in the table that holds the unique id's.

Thanks
Adie
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: copy a link to sql via php script

Post by Celauran »

Update is a reserved word in SQL, so that might be the problem. You could try enclosing the field name in backticks.

Code: Select all

$query="UPDATE nmbcdiary SET `Update`='http://nottinghammodelboatclub.freehostia.com/Admin/Editevent.php?ID=$Number' WHERE Number='$Number' ";
Adiefallguy
Forum Newbie
Posts: 5
Joined: Thu Nov 11, 2010 7:05 am

Re: copy a link to sql via php script

Post by Adiefallguy »

Thanks very much Celaruan that was just the ticket, although quotes or brackets didnt help changing the field name to Link has worked.

Cheers
Adie
Post Reply