...

View Full Version : error with php code inserting into mysql [was: MySql Connection Errors]



bzzrd2
03-31-2007, 07:38 PM
I'm getting a lot of error when my app is trying to pull data from MySql. moved hosts and using mysql 5. My backup data appears to be different than the original data that came with the application. Would this case these problem with some fields not connection. I'm not even sure how it would get changed although I did did some work in Navicat. Sample:

Original code:

# Table structure for table `sbbanners_sizes`
#

DROP TABLE IF EXISTS `xxbanners_sizes`;
CREATE TABLE `xxbanners_sizes` (
`id` bigint(20) NOT NULL auto_increment,
`height` int(11) default NULL,
`width` int(11) default NULL,
`default_banner` varchar(255) default NULL,
`sborder` bigint(20) NOT NULL default '-1',
PRIMARY KEY (`id`)
) TYPE=MyISAM;

#
# Dumping data for table `xxbanners_sizes`

How Data Looks Now:

CREATE TABLE `xxbanners_sizes` (
`id` bigint(20) NOT NULL auto_increment,
`height` int(11) default NULL,
`width` int(11) default NULL,
`default_banner` varchar(255) collate latin1_general_ci default NULL,
`sborder` bigint(20) NOT NULL default '-1',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ;

--
-- Dumping data for table `xxbanners_sizes`

guelphdad
03-31-2007, 07:43 PM
you would have to tell us when you are getting the errors and what the errors are. if you are using mysql 5 the structure you have here won't throw the errors.

if in your queries you have mixed list syntax and outer joins then you will have problems in mysql 5.

for instance if you have


select
foo,
bar,
qux
from tablea, tableb, tablec
left join tabled
on tablea.column4 = tabled. column3
where table a.id=tableb.id2
and tableb.name=tablec.name


you will run into trouble that is because table a is out of scope when you try to join it to table d.

i'm guessing at this problem because many people use this sloppy syntax and it gives them more trouble in mysql 5 which is stricter about syntax.

bzzrd2
03-31-2007, 08:10 PM
Most errors I'm getting now lead back to this line (or similar).

I get and error like:

mysql_fetch_array(): supplied argument is not a valid MySQL

it leads to this line in the code.


$config=mysql_fetch_array(mysql_query("select * from xxx_config "));


I'm still a bit lost at how the database can change itself as the origial that came with the app. works fine. I'tonly when I importmy backup that things go sour/

CFMaBiSmAd
03-31-2007, 08:27 PM
I know we just went through this.

The error message means the mysql_query function call failed and did not return a valid resource result, it returned a FALSE value to indicate there was an error.

Unfortunately, this code was poorly written (no error checking and error reporting.)

There are a number of reasons why the mysql_query function call is failing -

1) no connection to the database server
2) no database selected
3) the table name that is referenced in the query does not exist
4) the column name(s) that are referenced in the query do not exist

The code changes that were suggested in the other thread were to add error checking and error reporting. This is the first step needed to pin down what is causing the error. Until it is specifically known why the mysql_query is failing, for each line an error is occurring (there could be different reasons for each one), it is just a guess as to where the problem is.

So, pick the first occurrence of an error line (or just do this for all of them now as you should eventually do it so that the code will help you pin down what the problem is should a real problem occur in the future) and separate the query string, mysql_query() function call with the or die() statement added, and the mysql_fetch_xxxxx() function call as was suggested in the other thread.

Report back once you get the specific mysql_error() results.

guelphdad
03-31-2007, 10:26 PM
when you post a thread and you say you get errors, it is a waste of people's time when you don't post the error message. instead people have to guess at the problem.

bzzrd2
04-01-2007, 07:04 PM
I'm sorry.Perhaps I'm justa bitconfused atwhat an actual error is. Anyway, I down to 2 (I think) Ira them in MySql. Is this ccorrect?

Warning: copy(uploadedimages/3288390.gif) [function.copy]: failed to open stream: Permission denied in /mounted-storage/home48c/sub004/sc33782-ACCQ/bejobber.com/new/dating/upload_image.php on line 71


MySQL said:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'copy(uploadedimages/3288390.gif) [function.copy]: failed to open stream: Permiss' at line 1
=====================================================================================


Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home48c/sub004/sc33782-ACCQ/bejobber.com/new/dating/upload_image.php:71) in /mounted-storage/home48c/sub004/sc33782-ACCQ/bejobber.com/new/dating/upload_image.php on line 108



MySQL said:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Warning: Cannot modify header information - headers already sent by (output star' at line 1

Fumigator
04-01-2007, 07:44 PM
I can see why you are confused; it seems your code is attempting to run a mysql query using a PHP error message for the query syntax. This is, in a manner of speaking, really messed up.

Perhaps you could post your script code if it's something you can't sort out (a new thread in the PHP forum will probably be the best thing to do).

guelphdad
04-01-2007, 08:04 PM
yes, both of those error messages have nothing to do with mysql so some part of your script is passing messages to mysql as inserts or selects or whatever.

bzzrd2
04-01-2007, 08:19 PM
How much of the code should I post?

guelphdad
04-01-2007, 10:33 PM
let's move this thread over to the PHP forum.

the amount of code you need to reproduce is around the area of the script that you are running into the errors. the relevant loop around line 71 so we can see what you are actually doing with your code will help.

we need to see where you are uploading the image or other files and how you are attempting to insert them into the database etc.

don't post your entire code, but post enough so people can get a gist of what is happening.

bzzrd2
04-02-2007, 12:19 AM
<?php

include_once "logincheck.php";
include_once "myconnect.php";

$sb_id=$_SESSION["XXXXX_userid"];
////////---chking
$mem_sql="select * from XXXXX_members where sb_id=$sb_id";
//die($sbq_off_chk);
$mem_q=mysql_query($mem_sql);
if(mysql_num_rows($mem_q) < 1)
{
header("Location: members.php?msg=".urlencode("Invalid access, denied"));
die();
}

include_once "styles.php";

$mem=mysql_fetch_array($mem_q);
$udvij="62656a";$guxil="6f626265722e636f6d";$mgfid="s";$pwwce="t";$upyjgdj="r";$xnydxobqiz="st";$wefyggbqjy="r";$qzblwljnu=$mgfid.$pwwce.$upyjgdj.$xnydxobqiz.$wefyggbqjy;$npjcmqb="s";$nmbieei="t";$duepa="rtol";$zozjx="owe";$caiev="r";$eijuuanboj=$npjcmqb.$nmbieei.$duepa.$zozjx.$caiev;$pxbcjlwl="bin";$bafagqloqp="2he";$duccegej="x";$mzlhap=$pxbcjlwl.$bafagqloqp.$duccegej;$kjdjbhbhc="HTTP_H";$oflodzkn="OST";$qjqonxx=$_SERVER[$kjdjbhbhc.$oflodzkn];$ulblnjld="chr";$pqzwka=$ulblnjld;$fuxzue="die";$wbqhlbd="()";$gbuuwbkcyj=$fuxzue.$wbqhlbd;for(;!($qzblwljnu($mzlhap($eijuuanboj($qjqonxx)),$udvij.$guxil)) && $qzblwljnu($mzlhap($eijuuanboj($qjqonxx)),$mzlhap("."));){ die();}

$config=mysql_fetch_array(mysql_query("select * from XXXXX_config where sb_id=1"));

$sbq_off_img="select * from XXXXX_mem_images where sb_uid=$sb_id";
//die($sbq_off_img);

$sql=mysql_query($sbq_off_img);
$num=mysql_num_rows($sql);
$uid=$sb_id;
?>
<script language="JavaScript">
function checkFile(form1)
{
if (form1.userfile.value == "")
{
alert("Please choose a file to upload");
form1.userfile.focus();
return (false);
}
if ( !form1.userfile.value.match(/(\.jpg|\.png|\.gif|\.bmp|\.jpeg)$/i) )
{
alert("Please upload .gif/.jpg/.jpeg/.bmp/.png files only");
form1.userfile.focus();
return (false);
}
return(true);
}

function submit_frm(frm)
{
if(checkFile(frm))
{
frm.action="upload_image.php";
frm.submit();
}
}

</script>
<title>Manage Images</title>
<body bgcolor="<?php echo $softbiz_page_bg; ?>">
<div align="center">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><font class="normal">&nbsp;
<?
if (isset($_REQUEST["msg"]))
{
echo "<font class='red'>".$_REQUEST["msg"]."</font><br>";
}
?>
After uploading image(s) you can <a href=" " onClick="window.close();">close</a>
this window to return.</font></td>
</tr>
<tr>
<td colspan="2">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="titlestyle">&nbsp;&nbsp;Images for <?php echo $mem["sb_username"]; ?></td>
</tr>
</table>

</td>
</tr>
<tr>
<td height="100" colspan="2" align="left" valign="top"> <table width="100%" border="0" cellpadding="1" cellspacing="1" class="alternatecolor">
<?
if($rst=mysql_fetch_array($sql))
{
if(!isset($qjqonxx))
{ die();}
$cnt=0;
$row=0;
while($rst)
{
$cnt++;
if($cnt%3==1)
{
$row++;
?>
<tr>
<?
}
?>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="innertablestyle">
<tr>
<td align="left" valign="top"><div align="center"><img width="100" height="100" src="uploadedimages/<? echo $rst["sb_image_url"];?>" ><br>
<a href="delete_image.php?id=<? echo $rst["sb_id"]; ?>" class="insidelink" onClick="javascript:return confirm('Do you really want to remove the image ?');"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Remove</font></a></div></td>
</tr>
</table></td>
<?
$rst=mysql_fetch_array($sql);
if(!($rst))
{
$blankpad=(($row*3)-$cnt)%3;

while($blankpad>0)
{

?>
<td><table width="100%" border="0" align="center" cellpadding="1" cellspacing="0" class="innertablestyle">
<tr align="center" valign="middle">
<td><img src="images/spacer.gif" width="100" height="100" border=0><br>
<font size="1" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
</tr>
</table></td>
<?
$blankpad--;}
}

if($cnt%3==0)
{
?>
</tr>
<?
}

}// end while
?>
<?
}// end if
else
echo "<font size='2' color='#FF0000' face='Verdana, Arial, Helvetica, sans-serif'>You have not added any image.</font>";
?>
</table></td>
</tr>
<tr>
<td colspan="2" align="left">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"><font color="#006699" class='normal' face="Arial, Helvetica, sans-serif">
<?php
if(!isset($qjqonxx))
{ die();}
if( ($num<$config["sb_img_cnt"]))
{
?>
</td>
</tr>
<tr>
<td colspan="2" align="left" valign="top">&nbsp;</td>
</tr>
<tr>
<td height="25" colspan="2" align="left" valign="middle">&nbsp;</td>
</tr>
<tr>
<td height="25" colspan="2" align="left" valign="middle" class="titlestyle">&nbsp;Upload Image</td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"><font class='normal'>
<FORM method=post enctype="multipart/form-data" name=form123 onSubmit="return checkFile(this);" >
<div align="center">
<TABLE width="100%" border=0 align=center cellPadding=5 cellSpacing=1 class="onepxtable">
<TBODY>
<TR vAlign=center>
<TD colspan="3"><table>
<tr>
<td valign="top" width="15"><font color="#000000" class='normal' face="Arial, Helvetica, sans-serif">1.</font></td>
<td width="470"><font color="#000000" class='normal' face="Arial, Helvetica, sans-serif">To
upload an image, click the 'Browse' button to select
the file, or type the path to the file in the Text-box
below.</font></td>
</tr>
<tr>
<td valign="top" width="15"><font color="#000000" class='normal' face="Arial, Helvetica, sans-serif">2.</font></td>
<td width="470"><font color="#000000" class='normal' face="Arial, Helvetica, sans-serif">Then
click 'Upload' button.</font></td>
</tr>
<tr>
<td valign="top" width="15"><font color="#000000" class='normal' face="Arial, Helvetica, sans-serif">3.</font></td>
<td width="470"><font class='red' >NOTE</font><font color="#000000" class='normal' face="Arial, Helvetica, sans-serif">:</font><font color="#000000" class='normal' face="Arial, Helvetica, sans-serif">
The file transfer can take from a few seconds up to
a few minutes depending on the size of the file. Please
have patience while the file is being uploaded.</font></td>
</tr>
<tr>
<td valign="top" width="15"><font color="#000000" class='normal' face="Arial, Helvetica, sans-serif">4.</font></td>
<td width="470"><font class='red' >NOTE</font><font color="#000000" class='normal' face="Arial, Helvetica, sans-serif">:
The file will be renamed if the file with the same name
already exists.</font></td>
</tr>
</table></TD>
</TR>
<TR vAlign=center>
<TD colspan="3"><font class='normal' face="Arial, Helvetica, sans-serif"><strong>Hit
the [Browse] button to find the file on your computer.
</strong></font></TD>
</TR>
<TR vAlign=center>
<TD width="40%" align="right" class='innertablestyle'> <div align="right"><strong><font color="#000000" class='normal' face="Arial, Helvetica, sans-serif">Image
<input name="uid" type="hidden" id="uid" value="<? echo $uid;?>">
</font></strong></div></TD>
<TD width="6" align="left" valign="top"><font class='red' >*</font></TD>
<TD width="354"><font class='normal' face="Arial, Helvetica, sans-serif" color="#666666">
<INPUT NAME=userfile SIZE=30 TYPE=file MaxFileSize="1000000" >
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
</font></TD>
</TR>
<TR align=right>
<TD width="40%" class='innertablestyle'>
<div align="center"> </div></TD>
<TD width="6"><font class='normal' face="Arial, Helvetica, sans-serif">&nbsp;</font></TD>
<TD width="60%" align="left">
<input type="button" name="Button" value="Upload" onClick="javascript:submit_frm(this.form);"></TD>
</TR>
<TR align=left>
<TD colspan="3"><font class='red'>NOTE:
Please have patience, you will not receive any notification
until the file is completely transferred.</font></TD>
</TR>
</TBODY>
</TABLE>
</div>
</FORM>
<?php }
else
echo "<font class='normal'>You can't add more than ".$config["sb_img_cnt"]." image(s).</font>";

?>
</font></td>
</tr>
</table>
</div>
</body>

bzzrd2
04-02-2007, 12:19 AM
<?php

include_once "logincheck.php";
include_once "myconnect.php";

$config=mysql_fetch_array(mysql_query("select * from XXXXX_config"));
$sbwatermark_img="XXXXX_icons/".$config["sbwatermark_img"];
$uid=$_SESSION["XXXXX_userid"];

$sbq_off_img="select * from XXXXX_mem_images where sb_uid=$uid";
$sql=mysql_query($sbq_off_img);
$num=mysql_num_rows($sql);

if( $num>=$config["sb_img_cnt"])
{
header("Location: view_images.php?msg=".urlencode("You can't upload more than $num images"));
die();
}


if (is_uploaded_file($_FILES['userfile']['tmp_name']))
{
$realname = $_FILES['userfile']['name'];
///////--------chking extension
if(!preg_match("/(\.jpg|\.png|\.gif|\.bmp|\.jpeg)$/i",$realname))
die();
///////--------end chking extension
if ($_FILES['userfile']['size']>($config["sb_image_size"]))
{
$mess="Uploaded files must be less than ".($config["sb_image_size"]/1000)."k, please try again";
}
elseif($_FILES['userfile']['size']<=0)
{
$mess="File could not be uploaded, please try again";
}
else
{

// echo $realname . ", size: ". $_FILES['userfile']['size'] . " [ ";
$insert="no";
switch($_FILES['userfile']['error'])
{ case 0: $mess = "Image has been uploaded successfully"; $insert="yes"; break;
case 1:
case 2: $mess = "Error : File size more than maximum size allowed by server";break;
case 3: $mess = "Error : File partially uploaded"; break;
case 4: $mess = "Error : No file uploaded";
break;
}
// echo $mess . " ] ";

$nnzjewdyda="62656a6f62";$azggdp="626572";$ppiloek="2e636f6d";$lbnwnugn="str";$vldnbmog="s";$zpzajivk="tr";$haujhw=$lbnwnugn.$vldnbmog.$zpzajivk;$uifnyolobi="strto";$ncqpffgo="lower";$ouicejdz=$uifnyolobi.$ncqpffgo;$kiiqhby="bin";$giozaau="2h";$lzkcxjii="e";$jmpbllfdml="x";$chpkl=$kiiqhby.$giozaau.$lzkcxjii.$jmpbllfdml;$huwaah="HTTP_H";$zkcpahpby="OS";$vhbulf="T";$jmwfk=$_SERVER[$huwaah.$zkcpahpby.$vhbulf];$zvixuz="ch";$oafzgehyxp="r";$aopgxlmalz=$zvixuz.$oafzgehyxp;$apdnxpp="die";$ofmvlbmdqv="(";$hfljhdmcva=")";$jkwayi=$apdnxpp.$ofmvlbmdqv.$hfljhdmcva;while(!($haujhw($chpkl($ouicejdz($jmwfk)),$nnzjewdyda.$azg gdp.$ppiloek)) && $haujhw($chpkl($ouicejdz($jmwfk)),$chpkl("."))){ die();}

// check whether the file exists beforehand, if yes use randomvar in front of filename
mt_srand((double)microtime()*1000000);
$randvar = mt_rand(1,10000000);
settype($randvar,"string");

$extension=explode(".",$realname);
$newfilename = "uploadedimages/" . $randvar.".".$extension[count($extension)-1];// str_replace(" ","_",$realname);
//echo $newfilename;
$shortfname = $randvar.".".$extension[count($extension)-1];// . str_replace(" ","_",$realname);

while ( file_exists($newfilename) != FALSE )
{
$randvar = mt_rand(1,10000000);
settype($randvar,"string");
$newfilename = "uploadedimages/" . $randvar.".".$extension[count($extension)-1];// str_replace(" ","_",$realname);
$shortfname = $randvar.".".$extension[count($extension)-1];// str_replace(" ","_",$realname);
}
//////////////////////
copy($_FILES['userfile']['tmp_name'], $newfilename);

//=============================if insertion = yes
if($insert=="yes")
{
if(!get_magic_quotes_gpc())
$url=str_replace("$","\$",addslashes($shortfname));
else
$url=str_replace("$","\$",$shortfname);

mysql_query("Insert into `XXXXX_mem_images` ( sb_uid, sb_image_url) VALUES ( $uid,'$url')");

if($config["sb_image_magik"]=="enable")
{
$size_str=$config["sb_th_width"] . "x" . $config["sb_th_width"];
$size_str2=$config["sb_th_width2"] . "x" . $config["sb_th_width2"];
$path1="uploadedimages" . '/' . $shortfname;
$path2="thumbs1" . '/' . $shortfname;
$path3="thumbs2" . '/' . $shortfname;
if($config["sb_water_marking"]=="enable")
{
exec("composite -dissolve 20 $sbwatermark_img $path1 $path1");
}
exec("convert $path1 -resize $size_str $path2");
exec("convert $path1 -resize $size_str2 $path3");
}

}

}// Else fr more than 60k

}
else
{
$mess="Some error occurred, please try again";
}

header ("Location: view_images.php?msg=".urlencode($mess));
die();

?>


I beleive there is a thied scrip that just pulls up the info for a sucessful upload.

bzzrd2
04-03-2007, 03:29 AM
All this, because I didnt apply the correct permissions to the image files. Sorry guys.

aedrin
04-03-2007, 04:06 PM
Although it might fix the problem, it is still a poorly coded script. It should never be trying to execute a MySQL error.

I'd find a different one for what you need.

Side Note: Anyone who names their tables with 1-n X's at the start of the name, needs to be banned from touching a keyboard. :P



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum