Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert // url string 2

Status
Not open for further replies.

ignored1

Programmer
Nov 17, 2005
10
ZA
--------------------------------------------------------------------------------

Hi there,

can anyone help i seem to be a little stuck.

i wish to use a url eg) to update an entry in my MySQL dbase WHERE nws_id = 2.

ie) whatever the value in the string // insert_text=xxxxxx will be entered into my table

any suggestions?

thnks a lot
Dave (za)
"former asp bunny
 
correction

updater.php?text=yip&nws_id=1

<!-- on this code -->

<?php
// check for text AND id to update
if(isset($_GET['text']) && isset($_GET['nws_id']))
{
$newtext=trim($_GET['text']);
$nws_id=trim($_GET['nws_id']);

// do our thang, we have a value
if(!empty($newtext))
{
$sql="UPDATE network_status SET nws_scroll='".$newtext."' where nws_id='".$nws_id."'";
mysql_query($sql) or die ("error blah"); // fix this if you really want to know
$check=mysql_affected_rows();
if($check < 1)
{
echo "error failed to update";
}else{
echo "updated $check rows";
}
}
}
?>

//////////

No error now - but record remains unchanged :(
 
you have taken the time to add a mysql_connect() statement, and a mysql_select_db() statement?

I didn't, I presumed you knew this much already.

<?php
mysql_connect('host','username','password');
mysql_select_db(databasename);

// check for text AND id to update
if(isset($_GET['text']) && isset($_GET['id']))



______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
you are a legend you guys ....

thanks vacunita // Vragabond // KarveR its working legendary ...

i was an asp programmer for 3 years and moved over to LAMP ab out 3 months ago so im still green :) but im getting there ....

thanks for all your help ....

For reference final code looks like this
///////////////////

http;//url/updater.php?text=yip&nws_id=2

<!-- code in updater.php file ->

<?php
// connection
mysql_connect('localhost','yr_user','yr_pass');
mysql_select_db('yr_mysql_db');

// check for text AND id to update
if(isset($_GET['text']) && isset($_GET['nws_id']))
{
$newtext=trim($_GET['text']);
$nws_id=trim($_GET['nws_id']);

// do our thang, we have a value
if(!empty($newtext))
{
$sql="UPDATE network_status SET nws_scroll='".$newtext."' where nws_id='".$nws_id."'";
mysql_query($sql) or die ("error blah"); // fix this if you really want to know
$check=mysql_affected_rows();
if($check < 1)
{
echo "error failed to update";
}else{
echo "updated $check rows";
}
}
}
?>

//////////////////////

Thanks again

D
















 
Finally , it's ALIVE!!!! [bigglasses]

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
yeah like i only dreampt ... heehee

added one more line

///

updater.php?text=All%20Systems%20Stable&nws_id=1&image=no

<!-- code -->

if(isset($_GET['text']) && isset($_GET['nws_id']) && isset($_GET['image']))
{
$newtext=trim($_GET['text']);
$nws_id=trim($_GET['nws_id']);
$newimage=trim($_GET['image']);

// do our thang, we have a value
if(!empty($newtext))
{
$sql="UPDATE network_status SET nws_scroll='".$newtext."' && SET nws_image='".$newimage"' where nws_id='".$nws_id."'";
mysql_query($sql) or die ("error blah"); // fix this if you really want to know
$check=mysql_affected_rows();
if($check < 1)
{
echo "error failed to update";
}else{
echo "updated $check rows";
}
}
}
?>

///////////

error somewhere on this line ::

$sql="UPDATE network_status SET nws_scroll='".$newtext."' && SET nws_image='".$newimage"' where nws_id='".$nws_id."'";

//////////



 
missed a dot
='".$newimage." <---

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top