Jump to content

jtorral

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Everything posted by jtorral

  1. I figured out how to fix the problem but it still does not answer my question why almost two identical queries have different results in execution. Anyway, I fixed it by setting mysqli.recoonect = On in php.ini I still need to know why I lose connection. Any idea how to determine that?
  2. Oh yea. Did that. I get MySQL server has gone away.
  3. if ($stmt = mysqli_prepare($connectstring, $query)) { mysqli_stmt_bind_param($stmt, 'sississsssiisissiis', $title,$userid,$bigname,$smlname,$newfilesize,$camera,$cameramodel, $focallength,$exposure,$aperture, $iso,$photocategoryid,$path,$active,$datetaken,$resolution,$autoexif,$lens,$medname); if( ! mysqli_stmt_execute($stmt) ) { $x = mysqli_error ( $connectstring ); mysqli_stmt_close($stmt); error_message($x); } else { $newphotoid = mysqli_insert_id($connectstring); mysqli_stmt_close($stmt); } } else { echo "Oh no!"; } I get an error "the prepared failed" I don't know why it errors out.
  4. This is driving me NUTS!!!! and I can't figure it out or I am just burnt out. In a nut shell, I have a process that uploads a photo and inserts data into a table. Every single query on my site is prepared for security reasons. My issue is as follows. I have two versions of a photograph. The 2nd version is just a cropped version of the original and save to be smaller in size. That is the only difference and using jhead confirms this. So my prepared code looks like this $query = "INSERT INTO photos VALUES (0, ?,?, unix_timestamp(),?,?,?,?,?,?,?,?,?,?,?,?,0,?,?,?,?,?,NULL,NULL)"; $stmt = mysqli_prepare($connectstring, $query); mysqli_stmt_bind_param($stmt, 'sississsssiisissiis', $title,$userid,$bigname,$smlname,$newfilesize,$camera,$cameramodel, $focallength,$exposure,$aperture, $iso,$photocategoryid,$path,$active,$datetaken,$resolution,$autoexif,$lens,$medname); So far so good. If I upload the smaller of the two files, everything is fine. I echo the bind statement so I can see what goes on and here is what is going into the database just fine. ('sississsssiisissiis', ,4,U4I1306951247.SEQ.0.jpg,sml_U4I1306951247.SEQ.0.jpg,1594629,SONY,DSLR-A850,35mm, 0.0080 s (1/125),f/8, 200,9,gallery/4/,1, 2011:05:28 06:31:35, 2000 x 900,0,-1,med_U4I1306951247.SEQ.0.jpg) Keep in mind no quotes around values because its prepared. So I try the larger file with these values ('sississsssiisissiis', ,4,U4I1306951156.SEQ.0.jpg,sml_U4I1306951156.SEQ.0.jpg,3241103,SONY,DSLR-A850,35mm, 0.0080 s (1/125),f/8, 200,9,gallery/4/,1, 2011:05:28 06:31:35, 2000 x 1333,0,-1,med_U4I1306951156.SEQ.0.jpg) And it bombs with these messages Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in ... Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in ... Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in ... Keep in mind, the file actually uploaded without any issues. it only fails on the prepared statement insert. Any idea what is going on here? I have increased my max packet size in my.cnf as well but that does not help. Is it so obvious that I am missing it? Thanks JT
  5. Tried that mysqli_stmt_execute($stmt); mysqli_stmt_bind_result($stmt, $nextphotoid); mysqli_stmt_store_result($stmt); //mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); Does not work. Very strange.
  6. I looked in the database and the value was stored with the \'s However, prior to inserting it was sanitized with $thisval = strip_tags($thisval); $thisval = mysql_real_escape_string($thisval); I re ran it without calling those functions and it worked. Stupid question. But, now that I use prepared statements, does that mean I no longer need to call these functions? Thanks
  7. Ok. So I just started using prepared statements. One issue I ran into is that after inserting say "abc's" into the table with a prepared statement when I read that row and display it, it shows as abc\'s I have to use stripslashes on the variable before displaying it. I thought that with magic quotes. off this would not be a problem. Am I going to have to strip slashes on all fields now? Is there another way around it? here is my phpinfo for reference magic_quotes_gpc Off Off magic_quotes_runtime Off Off magic_quotes_sybase Off Off And compile options Configure Command './configure' '--host=i686-redhat-linux-gnu' '--build=i686-redhat-linux-gnu' '--target=i386-redhat-linux' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-curl' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-pspell' '--with-expat-dir=/usr' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--with-kerberos' '--enable-ucd-snmp-hack' '--with-unixODBC=shared,/usr' '--enable-memory-limit' '--enable-shmop' '--enable-calendar' '--enable-dbx' '--enable-dio' '--without-mime-magic' '--without-sqlite' '--with-libxml-dir=/usr' '--with-xml' '--with-mhash=shared' '--with-mcrypt=shared' '--with-apxs2=/usr/sbin/apxs' '--without-mysql' '--without-gd' '--without-odbc' '--disable-dom' '--disable-dba' '--without-unixODBC' '--disable-pdo' '--disable-xmlreader' '--disable-xmlwriter' '--disable-json' Thanks JT
  8. I have this code that uses mysqli_stmt_store_result and mysqli_stmt_fetch This code does NOT work: $query = "SELECT userid FROM customer LIMIT 1"; $stmt = mysqli_prepare($connectstring, $query); mysqli_stmt_execute($stmt); mysqli_stmt_store_result($stmt); mysqli_stmt_bind_result($stmt, $returnedval); mysqli_stmt_close($stmt); This code DOES work: $query = "SELECT userid FROM customer LIMIT 1"; $stmt = mysqli_prepare($connectstring, $query); mysqli_stmt_execute($stmt); mysqli_stmt_bind_result($stmt, $returnedval); mysqli_stmt_fetch($stmt); mysqli_stmt_close($stmt); I have some other code where the mysqli_stmt_store_result($stmt); does work and I thought that was a way of storing the result of the execute. Can someone explain the difference between the two statements. PHP says to always use the store but it does not work. Thanks JT
  9. Figured it out. Was hoping it would be an easy thing but I guess you have to code sometimes Here is what I did. As I check every field, if it is one that needs updating I create the following array $binddata[col1]["type"] = "s"; $binddata[col1]["varname"] = "varval1"; . and so on for all my fields .... . $binddata[col9]["type"] = "i"; $binddata[col9]["varname"] = "varval9"; I have also created a small function which takes the array and builds my bind command. Here is the actual function that you pass the array to. I added 2 more parameters to the function incase you need to add one extra parameter to build with. function buildbind($binddata, $addthistype, $addthisvar) { $bindstring = "mysqli_stmt_bind_param(\$stmt, '"; foreach ($binddata as $key) { $bindstring = $bindstring . $key[type]; } $bindstring = $bindstring . "$addthistype' "; foreach ($binddata as $key) { $bindstring = $bindstring . ",\${$key[varname]} "; } $bindstring = $bindstring . " $addthisvar );"; return $bindstring; } So, whenever I have one of these dynamic queries, I build up my array and call the function buildbind($binddata, "", "") It returns a string like so. mysqli_stmt_bind_param($stmt, 'ssi', $ipaddr, $username, $lastactivity); 1. define $thequery with a bunch of ?'s in it. 2. prepare the statement with the query: $stmt = mysqli_prepare($link, $thequery); 3. create the bindcmd string with: $bindcmd = buildbind($binddata, "", "" ); 4. turn the string into an actual php line of code: eval($bindcmd); do some logic and execute the command: if( ! mysqli_stmt_execute($stmt) ) {error_message("Failed to execute statement"); } And it works !!!
  10. I have a dilemma. Maybe it's an easy fix but i just cant see the solution. My code already works without preparing the sql. The problem is preparing the sql and building the dynamic query. In a nut shell, I have a form with 10 different fields. And depending on which field gets data, I build my query so that it only works on the fields the user typed something into. let me summarize .... I have a basic query that starts off like this $updatestring = ""; $query = "UPDATE table a SET "; if field1 set then $updatestring = $updatestring . " field1 = field1val " if field2 set then $updatestring = $updatestring . " field2 = field1val " if field3 set then $updatestring = $updatestring . " field3 = field1val " if field4 set then $updatestring = $updatestring . " field4 = field1val " and so on .... Finally $query = $query . $updatestring which can end up looking like: UPDATE table a SET field1 = field1val, field3 = field1val .... depending on which fields were set. I take care of commas and so on. Like I said this works. However, to prepare the statement really complicates things because if it looks like this: UPDATE table a SET field1 = ? , field3 = ? how do I know which variable to bind to the param out of the 10 possible fields ? How do I build the string types and place them in the right order? Do you see my dilemma? mysqli_stmt_bind_param($stmt, 'ii', $field1val, $field3val); Any help would be appreciated. I will also post this in the mysql section. Thanks, JT then
  11. i have javascript that sets a cookie when I click on a link. I then call the function below to check the value of the cookie. I am trying to use variable $div because I have 20 cookies withe the name xxx_div1 through xxx_div20 therefor I try to create the cookie name in the call so ai can minimize code. If i take the function below and replace $divcn with the actual cookie name it works as expected. If I use the variable, it always goes to the else. function checkdivsettings($div) { $divcn = "xxx_" . $div; if(isset($_COOKIE[$divcn])) { $div = $_COOKIE[$divcn]; } else { $div = "block"; } return $div; }
  12. Normally, I would check for a cookie something like this $_COOKIE['cookie_name'] But how can I do this ... $cn = "cookie_name"; $_COOKIE['$cn']; I can't get it to work. Is there a special way of assigning a variable to a global predefined? Thanks
  13. What in tarnation is going on here? This is driving me NUTS !!!!!! None This code is in between some other code. Whatever I do, it still does not redirect using header or javascript. What am I missing here????? FYI, I have output_buffering turned on in my php configuration file. the function mymonitor just return the num rows returned from a query. Everything works except the redirect. I have header commented out because I was also trying a java redirect. if ( isset($_REQUEST['reset']) ) { $reset = $_REQUEST['reset']; if( mymonitor($reset) == 0 ) { error_message("You cannot edit a monitor you do not own"); } resetsendmessages($reset); resetattempts($reset); resetnotified($reset); //header("Location http://www.icameradb.com"); ?> <script language="JavaScript" type="text/javascript"> <!-- window.location.href = "http://www.icameradb.com" //--> </script> <? } Thanks for looking.
  14. Thank you all. Much appreciated. seems to work now.
  15. I set some cookies with the following syntax: setcookie("cookie_name", $username, time()+2592000); this works on my site fine when yo traverse using http://www.registeryourcamera.com but when you traverse with http://registeryourcamera.com omitting the www the cookies are not read. How can I resolve this? Thanks
  16. I have done most of my coding using nothing but php and then echoing the html tags like so .. echo "<p>HELLO WORLD</p>"; this is fine. But now I am using a tool that generates a lot of html and I would like to just include the tidbits of php within the code as follows: html code ... ... ... <?php insert some php code then close php tag ?> ... ... ... more html code ... ... done with html My problem is that if I have a really big chunk of html code I may include a php tag near the top and declare a variable inside of that tag the close the tag. Then, later on in the html code I will insert another php tag, try to reference the variable declared in the earlier php tag above but the value is not retained. How can I keep the value and use it again ? Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.