Replace Field Data

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
chriswheat
Forum Newbie
Posts: 8
Joined: Fri Oct 03, 2003 12:11 pm

Replace Field Data

Post by chriswheat »

Hello,

This I am sure is a rookie question but here goes.

I have a varuable $btn

I want to take what ever data that is currently in the field "news" in table "scrape_btn" and replace it with $btn
I am using php and MYSQL
how do I do it?

Many Many Thanks!
Chris W.
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

mysql_query("update scrape_btn set news='".$btn."'") or exit();
chriswheat
Forum Newbie
Posts: 8
Joined: Fri Oct 03, 2003 12:11 pm

Post by chriswheat »

Paddy wrote:mysql_query("update scrape_btn set news='".$btn."'") or exit();
Thank you for the response, I could not make it work.
Here is all of the code... I used or die() statements at the end of my mysql statements then used a print mysql success to determine were the problem is. It appears to connect to the db and the table however it seams to die at the update command.

Code: Select all

<html>
<head>
<title>test</title>
<SCRIPT LANGUAGE="JAVASCRIPT">
  function New(window) &#123;
  	OpenWin = this.open(window, "independent", "width=600,height=400,toolbar=1,menubar=0,location=1,scrollbars=1,resizable=1,screenX=1,screenY=1,status=0,titlebar=0"); 
  	&#125;
 </SCRIPT>
</head>
<body>
<?php
mysql_connect ('localhost', 'myuser', 'mypassword')or die();
print "connect success";
mysql_select_db ('mydatabase')or die();
print "<br>select db success";
$open = fopen("http://www.someserver.com/headlines/index.jsp", "r"); 

// the above statement opens up the page using the socket libraries and reads it,
// fopen takes the pages as the 1st arguement and type of opening (r in this case) as the 2nd 

$read = fread($open, 45000); 

// fread scours to the 15000th byte and captures all the encountered bytes into $read 

fclose($open); 

$search = eregi("<IMG SRC="/images/tab_headlines.gif" WIDTH="147" HEIGHT="17" BORDER="0"><BR>(.*)<TD valign="top" ALIGN="center">", $read, $printing); 

// Case insensitive search on the data
 

$printing&#1111;1] = str_replace("<TABLE cellspacing="2" cellpadding="2" border="0" width="100%">", "", $printing&#1111;1]);
$printing&#1111;1] = str_replace("<TR>", "", $printing&#1111;1]);
$printing&#1111;1] = str_replace("<TD>", "", $printing&#1111;1]);
$printing&#1111;1] = str_replace("<IMG BORDER="0" HEIGHT="12" WIDTH="10" SRC="/images/arrow.gif"><font size="1" face="arial, helvetica, sans-serif">", "", $printing&#1111;1]);
$printing&#1111;1] = str_replace("</font>", "", $printing&#1111;1]);
$printing&#1111;1] = str_replace("</TD>", "", $printing&#1111;1]);
$printing&#1111;1] = str_replace("</TR>", "", $printing&#1111;1]);
$printing&#1111;1] = str_replace("</TABLE>", "", $printing&#1111;1]);
$printing&#1111;1] = str_replace("<BR CLEAR="none">", "", $printing&#1111;1]);
$printing&#1111;1] = str_replace("HREF="", "href="javascript:New('http://www.someserver.com", $printing&#1111;1]);
$printing&#1111;1] = str_replace("">", "');">", $printing&#1111;1]);
$printing&#1111;1] = str_replace("</A>", "</A><br><br>", $printing&#1111;1]);


// Striping and replacing data 

$content = $printing&#1111;1];
$content = explode("·", $content); 

// well this is also a common cancellation or rather the place where the shifting headlines into
// elements actually takes place with the help of "?" and explode(); 

$headlines = sizeof($content); 

// counting the array elements 

for ($i = 0; $i < $headlines; $i++) &#123; 

$btn = $content&#1111;$i];

// If I use print "$btn"; instead of the below two statements it prints.

mysql_query("UPDATE scrape_btn SET news='".$btn."'")or die();

print "<br>Databes Update Success";

&#125; 



?>
Thank You,
Chris W.
chriswheat
Forum Newbie
Posts: 8
Joined: Fri Oct 03, 2003 12:11 pm

Post by chriswheat »

For any one following this thread it was single quotes in the text that was throwing it off. It now works! one really rookie question how do I ge the info back out and display it.?

thanks
Chris W
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

Which info did you want back?
chriswheat
Forum Newbie
Posts: 8
Joined: Fri Oct 03, 2003 12:11 pm

Post by chriswheat »

The news field info. I figured it out.
Post Reply