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
 
When you insert a variable into a URL it gerts passed as POSt variable.
In your insert file you can access the value from the URL, using the $_POST['insert_text'] variable.

The Value should be in there. the just run the query with the value.

Example:
Code:
$myvar=$_POST['insert_value'];

$qry="SELECT *FROM table WHERE somevalue=" . $myvar;


Hope this Helps

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
<?php
$nws_scroll = $_POST['nws_scroll'];
mysql_query("INSERT into network_status VALUES ('$nws_scroll') WHERE nws_id = '2')");
?>

a)does thislook correct?
b)string is // http:/url/updater.php?nws_scroll=Hello%20World............

c)do i need a record set?

thnks
D
 
Actually, it should be $_GET instead of post:
Code:
$nws_scroll = $_GET['nws_scroll'];
 
Right on the money Vrag. My bad.

You might want to try:
Code:
$sql="INSERT into network_status VALUES ('".$nws_scroll ."') WHERE nws_id = '2')";

mysql_query($sql);

If only for readability.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
:( doesnt wonna work ...

tried

<?php
$sql="INSERT into network_status VALUES ('".$nws_scroll ."') WHERE nws_id = '2')";

mysql_query($sql);
?>
 
INSERT INTO is an SQL command that inserts a new field in the database. How do you expect to insert a new field in the field WHERE nws_id = 2??? Are you trying to update a record in the database (then use UPDATE) or insert a new line (in that case you can't state where to insert it).
 
Ohh man whats Wrong with me today. Right again Vrag.

Insert statements canot be conditioned. I believe Vrag is right, and what you want to do is UPdate the record, not Insert a new one.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
To enter a new record:
INSERT into YOURTABLE set fieldname='value';

to update a record

UPDATE YOURTABLE set fieldname='value' WHERE fieldnamevalue ='something';

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
update a record
> to change a marquee on the frontpage of my site


> the network status will be updated dynamically running a query string ... /update.php?nws_scroll=xxxxxxx

-------------------------
... dudes i use ultradev to build wonderful powerful apps :) but i dont have a clue how to insert without using a form .....

thanks for all the help so far ....

--------------------------

<?php
$sql="UPDATE network_status VALUE ('".$nws_scroll ."') WHERE nws_id = '1')";
mysql_query($sql);
?>
 
Inserting and Updating are not the same thing

Inserting creates a totally new record where there was none there before.

UPdate takes an existing record and changes something in it.

What is it you want to do? Create a new record??? With the new Marquee text in it or Update an existing one to replace the text that it has with new text?




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
from the looks of the very first post:

$sql="UPDATE network_status SET status_text='".$_GET['insert_text']."' WHERE nws_id = '1')";

The above assumes that you have 2 fields in your table, 1 for text and one for status id.

Your scroller then selects the text based on nws_id='x' where x is appropriate(1 2 3 .... 99...1000000000 etc)


table (netwrok_status):
Code:
nws_id	|	status_text
1	|	hello world
2	|	all is well
3	|	its sunny
4	| everything has gone t**s up

in the update above, anything passed in the url (
the status_text wwould be set to yipeeee where id=1 instead of being "hello world"

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
sorry im a clown ... i wasnt thinking ..

update a record
the marquee is coded like this on another page ....

##
<MARQUEE DIRECTION="LEFT" BEHAVIOR="SCROLL" WIDTH="165" BGCOLOR="#cccccc" ALIGN="CENTER" SCROLLAMOUNT="2">
<b><?php echo $row_rsNetworkStatus['nws_scroll']; ?></b>
</MARQUEE>
##

i have only 3 values in that table..

id image text scroll
1 yes.gif All Systems Status xxxxxxxx
2 yes.gif IS ADSL xxxxxxxxx
3 yes.gif CDWeb Servers xxxxxxxxx

i wish to use a page with string

page.php?nws_scroll=yyyyyyyyyyyy
to replace the value in the dbase

##

 
Then it is an update and would be:

Like Vrag said:
Code:
...

$sql="UPDATE network_status SET 
scroll='".$_GET['nws_scroll']."' WHERE nws_id = '1')";

That si going to replace:
1 yes.gif All Systems Status xxxxxx

to

1 yes.gif All Systems Status yyyyyyy
[/code]


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
because I'm here (and not Vrag):

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

	// do our thang, we have a value
	if(!empty($newtext))
	{
		$sql="UPDATE network_status SET text='".$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";
		}
	}
}
?>

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Sorry, Karv, dont know why I called you Vrag.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
/bonk Vac :)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
thanks bro....

Parse error: parse error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in /updater.php on line 3

line 3
if(isset($_GET['insert_text'] && $_GET['nws_id']))
 
bugger :)

if(isset($_GET['insert_text']) && isset($_GET['nws_id']))

sorry [2thumbsup]

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
get error blah


<!-- on this code -->

<?php
// check for text AND id to update
if(isset($_GET['text']) && isset($_GET['id']))
{
$newtext=trim($_GET['text']);
$nws_id=trim($_GET['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";
}
}
}
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top