Page 1 of 1

copy a link to sql via php script

Posted: Thu Nov 11, 2010 7:16 am
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

Re: copy a link to sql via php script

Posted: Thu Nov 11, 2010 7:51 am
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?

Re: copy a link to sql via php script

Posted: Thu Nov 11, 2010 8:03 am
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

Re: copy a link to sql via php script

Posted: Thu Nov 11, 2010 9:46 am
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' ";

Re: copy a link to sql via php script

Posted: Thu Nov 11, 2010 12:21 pm
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