preparing message to keep in bd? mmm

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
User avatar
visonardo
Forum Contributor
Posts: 136
Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.

preparing message to keep in bd? mmm

Post by visonardo »

Im reading db content and keep it again, but exactly like i took it from db´s field. When i try keep it show me error near quotes that i use to delimit the text field, in this case single quotes. how did they to keep it in the db? and the problem: how i must do to keep it without change all?


perhaps you would ask yoursef why i want keep something that didnt change, the answer is that im in a server that dont allow me access to my db from others servers, then i did to php, that pass between the data and in the new server i keep it in the db new. I cant do backup almost because the db is more than 200mb (exactly ~230mb) and when i use system(); sentence to do that it stop in the middle´s task :?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

Hola! Your English is better than my Spanish, but it is still quite difficult for many of us to read. I say that in a friendly way, because we would like to help you with your problem if we can. It would probably help if you include the PHP code that you are using, then we can all speak the same language: PHP! :?
User avatar
visonardo
Forum Contributor
Posts: 136
Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.

Post by visonardo »



PHP file in new server (this request to the old server the data and keep it in the new server)

Code: Select all

include('conection.php');
$link=conectarse();


$tabla=$_GET['tabla'];
$cmp=$_GET['cmp'];
if(!isset($_GET['cmp']) || !isset($_GET['tabla'])){
	echo 'faltan parametros por url';
	exit;
}

set_time_limit(300);
$a=file('http://[somesite].com/control/bd.php?tabla='.$tabla.'&cmp='.$cmp);
if(is_numeric(strpos('@',$a[0]))){
	echo $a[0];
	echo '<br>#18';
	exit;
}
echo '<b>TOTAL: <font color=#ff0000>'.$a[0].'</font></b><p>';
$a=explode(' ',trim($a[1]));

echo '<div align=center>';
for($i=0;$i<10;$i++)
{
	global $link,$tabla,$cmp;
	set_time_limit(300);
	$show='';
	$b=file('http://[somesite].com/control/bd.php?id='.$a[$i].'&tabla='.$tabla.'&cmp='.$cmp);
	$show=trim(implode("\n",$b));
	mysql_query($show,$link) or die(mysql_error().'<p>'.$show);
	echo '<img src="http://pirata777.com/phpBB2/images/bot/ok.jpg" border=0>';
}
echo '<h1>JOYA!</h1>';



PHP from the old server

Code: Select all

<?

include('conection.php');
$link=conectarse();

if(!isset($_GET['cmp']) || !isset($_GET['tabla'])){
	echo '@ERROR #1';
	exit;
}

$tabla=$_GET['tabla'];
$g=$_GET['cmp'];

if(!isset($_GET['id']))
{
	global $tabla,$g;
	$hola='SELECT '.$g.' FROM phpbb_'.$tabla;
	$sql=mysql_query($hola,$link) or die('@mysql =>'.mysql_error());
	echo mysql_num_rows($sql);
	echo "\n";
	while($res=mysql_fetch_assoc($sql))
		echo $res['post_id'].' ';
	exit;
}

$sql2='SELECT * FROM phpbb_'.$tabla.' WHERE '.$g.'='.$_GET['id'];
$sql=mysql_query($sql2,$link);
if(!$sql){
	echo '@ERROR <b>'.$sql2.'</b>';
	exit;
}	
$veo=mysql_fetch_assoc($sql);
$mem=count($veo)-1;
echo 'INSERT INTO phpbb_'.$tabla.' (';
$guia=0;
foreach($veo as $k => $veo_)
{
	echo $k;
	if($guia!=$mem)
		echo ', ';
	else
		echo ') VALUES (';
	$guia++;
}
$guia=0;
foreach($veo as $k => $veo_)
{
	global $mem, $guia;
	echo ' ';
	$com=(is_numeric($veo[$k]))?'':'\'';
	echo $com.$veo[$k].$com;
	$proximo=($guia==$mem)?')':', ';
	echo $proximo;
	$guia++;
}
User avatar
visonardo
Forum Contributor
Posts: 136
Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.

Post by visonardo »

obiously that the problem is not in the script really, the task is keep it in the db exactly like is in old db. i tried puting single quotes to alphanumeric values show me error, tried with ` and nothing too, show me error, that (for example)

$query='insert into table (field_number,field_alph) VALUES (9, `abcdef`)';

when i do this query, using `, mysql_error(); say "unknow field 'abcdef' in field list" :?, then if i try with ' (single quote) had problem with their value because i would need scape them before keep in db and i cant change content, i dont sould change that.
User avatar
visonardo
Forum Contributor
Posts: 136
Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.

Post by visonardo »

understand? if i take a data from a table, and (no change did) do an update with this date it should work, ok. dont work. Why, i dunno.
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

Why do you need to update data that hasnt changed?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

visonardo wrote:obiously that the problem is not in the script really, the task is keep it in the db exactly like is in old db. i tried puting single quotes to alphanumeric values show me error, tried with ` and nothing too, show me error, that (for example)

$query='insert into table (field_number,field_alph) VALUES (9, `abcdef`)';

when i do this query, using `, mysql_error(); say "unknow field 'abcdef' in field list" :?, then if i try with ' (single quote) had problem with their value because i would need scape them before keep in db and i cant change content, i dont sould change that.
You are using single-quote (') around entire SQL query, and back-tick (`) around value. Try using double-quote around entire SQL query and single-quote (') around value, like:

Code: Select all

$query="insert into table (field_number,field_alph) values (9,'abcdef')";
Post Reply