...

View Full Version : MySQL SELECT Wont Run?!!?



the-dream
08-13-2008, 11:29 AM
<?php
$url = $_SERVER['REQUEST_URI'];
$split = preg_split('/\//', $url);

mysql_connect("mysql.xxxxxxxxx.com", "xxxxxxxxx", "xxxxxxxxx");
mysql_select_db("branchr");

$user = mysql_query("SELECT * FROM social_trees WHERE username = '$split[1]'");
$branches = mysql_query("SELECT * FROM network_branches WHERE user = '$split[1]'");

$row = mysql_fetch_array($user);

$u = $split[1];
?>


<?php echo $row['username']; ?> >>

<?php
while($row1 = mysql_fetch_array($branches)) {

$brnch = $row1['id'];
$url = $row1['network_feed'];
$net = $row1['network'];

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);

$data = curl_exec($ch);
curl_close($ch);

$doc = new SimpleXmlElement($data, LIBXML_NOCDATA);
function parseRSS($xml, $u, $net, $brnch)
{

$cnt = count($xml->channel->item);
for($i=0; $i<$cnt; $i++)
{
$url = $xml->channel->item[$i]->link;
$title = $xml->channel->item[$i]->title;
$desc = $xml->channel->item[$i]->description;
$date = $xml->channel->item[$i]->pubDate;

// But this doesnt
$isitthere = mysql_query("SELECT * FROM `data` WHERE data.title = '$title' AND data.date = '$date' AND data.user = '$u'");
$counter = 0;

while($isrow = mysql_fetch_array($isitthere)) {
$counter ++;
}

if($counter == '0') {
// The code below runs!
mysql_query("INSERT INTO data VALUES ( NULL, '$title', '$desc', '$date', '$u', '$net', '$brnch' )");

}
}
}


if(isset($doc->channel))
{
parseRSS($doc, $u, $net, $brnch);
}


}
?>

See code comments for where it is, basically the bottom SQL executes but the top one doesn't. I get the following error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/.zusa/christianowens/branchr.com/user.php on line 50

hinch
08-13-2008, 11:31 AM
$user = mysql_query("SELECT * FROM social_trees WHERE username = '".$split[1]."' ");
$branches = mysql_query("SELECT * FROM network_branches WHERE user = '".$split[1]."' ");

$isitthere = mysql_query("SELECT * FROM `data` WHERE data.title = '".$title."' AND data.date = '".$date."' AND data.user = '".$u."'");


try that

the-dream
08-13-2008, 11:35 AM
Same errors,

Here is the updated code with your suggestion:


<?php
$url = $_SERVER['REQUEST_URI'];
$split = preg_split('/\//', $url);

mysql_connect("xxxxxxxxxxxxxxxxxx", "xxxxxx", "xxxxxx");
mysql_select_db("branchr");

$user = mysql_query("SELECT * FROM social_trees WHERE username = '".$split[1]."' ");
$branches = mysql_query("SELECT * FROM network_branches WHERE user = '".$split[1]."' ");

$row = mysql_fetch_array($user);

$u = $split[1];
?>


<?php echo $row['username']; ?> >>

<?php
while($row1 = mysql_fetch_array($branches)) {

$brnch = $row1['id'];
$url = $row1['network_feed'];
$net = $row1['network'];

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);

$data = curl_exec($ch);
curl_close($ch);

$doc = new SimpleXmlElement($data, LIBXML_NOCDATA);
function parseRSS($xml, $u, $net, $brnch)
{

$cnt = count($xml->channel->item);
for($i=0; $i<$cnt; $i++)
{
$url = $xml->channel->item[$i]->link;
$title = $xml->channel->item[$i]->title;
$desc = $xml->channel->item[$i]->description;
$date = $xml->channel->item[$i]->pubDate;

$isitthere = mysql_query("SELECT * FROM `data` WHERE data.title = '".$title."' AND data.date = '".$date."' AND data.user = '".$u."'");
$counter = 0;

while($isrow = mysql_fetch_array($isitthere)) {
$counter ++;
}

if($counter == '0') {

mysql_query("INSERT INTO data VALUES ( NULL, '$title', '$desc', '$date', '$u', '$net', '$brnch' )");

}
}
}


if(isset($doc->channel))
{
parseRSS($doc, $u, $net, $brnch);
}


}
?>

Could it be that it's inside a function? I don't see how, because the one below is working...

CFMaBiSmAd
08-13-2008, 12:02 PM
None of your mysql_ statements have any error checking logic to get them to tell you if they failed or not and why they failed.

hinch
08-13-2008, 12:06 PM
move the function out side of the while loop too surprised it isn't erroring on redeclaring function

the-dream
08-13-2008, 12:16 PM
Oh my god, I am an idiot.

addslashes();

CFMaBiSmAd
08-13-2008, 12:26 PM
If your least post is referring to escaping data put into a query, addslashes() does not escape all the special characters that can break a query. Use mysql_real_escape_string()



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum