Page 1 of 1

php code help

Posted: Sat Feb 15, 2003 4:16 am
by forgun

Code: Select all

<?php
include("includes/dbs.php");
$lk = mysql_connect($serv,$user,$pass) or die (mysql_error());
mysql_select_db($dbname[0]) or die (mysql_error());
$kay = array(
$_REQUEST['kay1'] ,
$_REQUEST['kay2'] ,
$_REQUEST['kay3'] ,
$_REQUEST['kay4'] ,
$_REQUEST['kay5']
);
$path = array(
$_REQUEST['T1'] ,
$_REQUEST['T2'] ,
$_REQUEST['T3'] ,
$_REQUEST['T4'] ,
$_REQUEST['T5']
);
foreach ($kay as $val => $kays) {
        foreach ($path as $val1 => $paths) {
                if (!empty($kay[$val])  && !empty($path[$val1])) {
                        $qur = "select * from linkssets";
                        $res = mysql_query($qur) or die (mysql_error());
                        while ($row = mysql_fetch_assoc($res)) {
                                if ($kay[$val] != $row['kayword'] && $path[$val1] != $row['path']) {
                                        $type = $_REQUEST['set'];
                                        $ip = $_SERVER['REMOTE_ADDR'];
                                        unset($qur);
                                        $qur = "INSERT INTO linkssets (kayword , path , type , ip) VALUES (";
                                        $qur .= "'" .mysql_escape_string($kay[$val]) . "' , '"  .mysql_escape_string($path[$val1]) . "' , '". $type . "' , '" .$ip ."')";
                                        mysql_query($qur) or die (mysql_error());
                                        echo "done";
                                }
                                else {
                                        echo "Path or kay is on the db";
                                }
                        }
                }
        }
}
?>
i thing the error code some where here

Code: Select all

foreach ($kay as $val =&gt; $kays) &#123;
        foreach ($path as $val1 =&gt; $paths) &#123;
                if (!empty($kay&#1111;$val])  &amp;&amp; !empty($path&#1111;$val1])) &#123;
                        $qur = "select * from linkssets";
                        $res = mysql_query($qur) or die (mysql_error());
                        while ($row = mysql_fetch_assoc($res)) &#123;
                                if ($kay&#1111;$val] != $row&#1111;'kayword'] &amp;&amp; $path&#1111;$val1] != $row&#1111;'path']) &#123;
the prob is the db not get the data

Posted: Sat Feb 15, 2003 11:23 am
by Takuma
What is the error message?

Posted: Sat Feb 15, 2003 11:26 am
by forgun
none just none form the data is going to the db

Posted: Sat Feb 15, 2003 11:29 am
by Takuma
Click 'Post Reply' rather than post a new topic.
Well for those of people who missed the error message it
i get that error
Code:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/virtual/site13/fst/var/www/html/staff/link-add.php on line 38


the code is here http://pastebin.com/3042
And what happens when you echo $qur just before 'echo "done";'?

Posted: Sat Feb 15, 2003 11:32 am
by forgun
mm nothing none of date go to the db even the done msg not show

Posted: Sat Feb 15, 2003 1:35 pm
by Takuma
Change this:-

Code: Select all

<?php
$qur = "INSERT INTO linkssets (kayword , path , type , ip) VALUES ("; 
                                        $qur .= "'" .mysql_escape_string($kay[$val]) . "' , '"  .mysql_escape_string($path[$val1]) . "' , '". $type . "' , '" .$ip ."')"; 
?>
to this...

Code: Select all

<?php
$kay[$val] = mysql_escape_string($kay[$val]);
$path[$val1] = mysql_escape_string($path[$val1]);
$qur = "INSERT INTO linkssets(kayword, path, type, ip) VALUES ('{$kay$val}', '{$path[$val1]}', '$type', '$ip')";
?>
And try echoing $kay[$val1] and $path[$val1] and see whether they have anything in them.