Page 1 of 2
[56K WARN]sql UPDATE not working on localhost
Posted: Mon Jul 02, 2007 10:31 pm
by invisibled
Hey everybody,
So I recently reinstalled my OS (OS X) and reinstalled php, mysql, phpmyadmin etc etc.
when i go to run update queries from php, it never works. My code is all right cause it works on my webserver, just not on my localhost.
i went into PHP myAdmin privliges and set all the users too ALL PRIVILEGES and still nothing.
could anybody throw some ideas out there as to why its doing this?
Posted: Mon Jul 02, 2007 10:38 pm
by John Cartwright
We need to see the code if you want us to provide any feedback
Posted: Mon Jul 02, 2007 11:41 pm
by s.dot
also wouldn't hurt posting your phpmyadmin config
Posted: Tue Jul 03, 2007 12:20 pm
by RobertGonzalez
It would also help us if you posted some error messages that you are getting.
reply
Posted: Wed Jul 04, 2007 8:46 pm
by invisibled
well there is no code is question or any error msg's so there is nothing to show for that.
here are the privileges for phpmyadmin.

Re: reply
Posted: Wed Jul 04, 2007 8:56 pm
by Zoxive
invisibled wrote:well there is no code is question or any error msg's so there is nothing to show for that.
here are the privileges for phpmyadmin.

...
This pic gives us 0 information, because you did not tell us what user you are using, and it most likely is a code problem.
So please if you want some help, give us some real information.
First thing I would do is
on top of the page in question, and then start adding "dies".
Code: Select all
mysql_select_db('my_database') or die('Could not select database');
$result = mysql_query($query) or die('Query failed: <br>' . $query . '<br>' . mysql_error());
...
Posted: Thu Jul 05, 2007 1:22 am
by invisibled
no
there is nothing wrong with my code. Im not sure why you think you know the situation better than me. the code is fine. there is nothing wrong with the code. read my original post, its an issue with my local host. and error reporting is on.
I am using the user invisibled
Posted: Thu Jul 05, 2007 7:32 am
by feyd
Post your code.
Re: [56K WARN]sql UPDATE not working on localhost
Posted: Thu Jul 05, 2007 10:55 am
by RobertGonzalez
invisibled wrote:when i go to run update queries from php, it never works. My code is all right cause it works on my webserver, just not on my localhost.
Your web server and local host are two different machines, with two potentially different set ups. What works on one and not on the other suggests the code is is not compatible with your local environment. What are your local setting and your server settings? Run the following in a new file on each server and tell us the results please.
Code: Select all
<?php
$neg = array('off', 0, false, '', null);
$flags = array(
'Register Globals' => 'register_globals',
'Short Tags' => 'short_open_tag',
'Display Errors' => 'display_errors',
'Magic Quotes GPC' => 'magic_quotes_gpc',
'Magic Quotes Runtime' => 'magic_quotes_runtime',
'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$flags['Config file'] = get_cfg_var('cfg_file_path');
if (empty($flags['Config file']))
{
$flags['Config file'] = '-';
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";
$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
$le .= ' ' . implode(' ', array_slice($gle, $i, $wide)) . $eol;
}
$ec = array(
'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);
$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
if (($t & $v) == $v)
{
$e[] = $n;
$t ^= $v;
}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
$e2 = array();
foreach ($ec as $n => $v)
{
if (!in_array($n, $e) and $n != 'E_ALL')
{
$e2[] = $n;
}
}
$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
$er = $er . ' (' . implode(' | ', $e) . ')';
}
if (!$cli)
{
echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}
echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;
if (!$cli)
{
echo '</pre></body></html>', $eol;
}
?>
results
Posted: Thu Jul 05, 2007 2:06 pm
by invisibled
ok i got the results for both servers, thats a nifty little code, thanks!
localhost
Code: Select all
PHP Version: 5.2.1
PHP OS: Darwin
Error Reporting: 6135 ((E_ALL | E_STRICT) ^ E_STRICT ^ E_NOTICE))
Register Globals: Off
Short Tags: Off
Display Errors: On
Magic Quotes GPC: Off
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Config file: /usr/local/php5/lib/php.ini
Loaded Extensions:
zip xmlwriter libxml xmlrpc
dom xmlreader xml wddx
tokenizer session pcre SimpleXML
SPL PDO sockets soap
snmp SQLite standard Reflection
posix pdo_sqlite OpenBase Module memcache
mbstring ldap imap iconv
hash gd ftp filter
exif dbase date ctype
calendar bz2 bcmath zlib
openssl apache curl fbsql
gettext json mcrypt mhash
ming mssql mysql mysqli
oci8 odbc pdf pdo_mysql
PDO_OCI pdo_pgsql pgsql xsl
webserver
Code: Select all
PHP Version: 5.2.2
PHP OS: Linux
Error Reporting: 6135 ((E_ALL | E_STRICT) ^ E_STRICT ^ E_NOTICE))
Register Globals: Off
Short Tags: On
Display Errors: On
Magic Quotes GPC: On
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Config file: /home/14678/etc/php.ini
Loaded Extensions:
libxml xmlwriter xmlrpc xmlreader
xml wddx tokenizer session
SimpleXML SPL sockets soap
PDO standard Reflection pspell
posix pgsql pdo_sqlite pdo_pgsql
pdo_mysql SQLite mysqli mysql
mime_magic mhash mcrypt mbstring
ldap json imap iconv
hash gettext gd ftp
filter exif dom dba
date curl ctype calendar
bz2 bcmath zlib pcre
openssl xsl cgi-fcgi
Posted: Thu Jul 05, 2007 3:10 pm
by RobertGonzalez
Ok, now its time to show some code for the UPDATE. There is something I need to see. Please post it exactly as it appears in your app, including opening and closing PHP tags.
reply
Posted: Fri Jul 13, 2007 2:26 am
by invisibled
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
ok here is my update function
Code: Select all
//UPDATE REORD FUNCTION
if (isset ($_POST["updateID"])):
$updateID = $_POST["updateID"];
$client = $_POST["client"];
$projectNum = $_POST["projectNum"];
$owed = $_POST["owed"];
$paid = $_POST["paid"];
$contact = $_POST["contact"];
$client = str_replace( "'", "'", $client);
$query = "UPDATE ida_financial SET client='$client', projectNum='$projectNum', owed='$owed', paid='$paid', contact='$contact' WHERE entryID='$updateID';";
$upd = mysql_query($query);
endif;
//UPDATE RECORD FUNCTION
and here is the update page
Code: Select all
/****************FINANCIAL EDIT PAGE************/
function financialEdit($go){
$updateID = $_GET["updateID"];
$query = "SELECT * FROM ida_financial WHERE entryID='$updateID';";
$sel = mysql_query($query) or die("$query failed");
if($res = mysql_fetch_array($sel)):
$client = $res["client"];
$projectNum = $res["projectNum"];
$owed = $res["owed"];
$paid = $res["paid"];
$contact = $res["contact"];
endif;
?>
<table>
<form action="financial.php" method="POST">
<td><input type="hidden" name="updateID" value="<?=$updateID?>" /></td></tr>
<tr><td align="right"> Client: </td><td> <input type="text" name="client" value="<?php print $client?>" /> </td></tr>
<tr><td align="right"> Record #: </td><td> <input type="text" name="projectNum" value="<?php print $projectNum?>" /> </td></tr>
<tr><td align="right"> Owed: </td><td> <input type="text" name="owed" value="<?php print $owed?>" /> </td></tr>
<tr><td align="right"> Paid: </td><td> <input type="text" name="paid" value="<?php print $paid?>" /> </td></tr>
<tr><td align="right"> Contact: </td><td> <input type="text" name="contact" value="<?php print $contact?>" /> </td></tr>
<tr><td align="right" colspan="2"> <input type="submit" name="update" value="Save" /> </td></tr>
</form>
</table>
<?php
}//END financialEdit($go)
/****************FINANCIAL EDIT PAGE************/
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Fri Jul 13, 2007 10:06 am
by pickle
Magic quotes are enabled on the web server, but not on your localhost. Echo your query & run it manually (through phpmyadmin or command line) - you might get some errors you aren't expecting. Look into
get_magic_quotes_gpc().
Also, this line does absolutely nothing:
Code: Select all
$client = str_replace( "'", "'", $client);
Posted: Fri Jul 13, 2007 10:28 am
by RobertGonzalez
To add a little more to pickle's observation:
Code: Select all
<?php
$updateID = $_POST["updateID"];
$client = $_POST["client"];
$projectNum = $_POST["projectNum"];
$owed = $_POST["owed"];
$paid = $_POST["paid"];
$contact = $_POST["contact"];
$client = str_replace( "'", "'", $client);
?>
If you are not doing something with the raw post data, why are you using resource in assigning them to new vars? Then, you replace all "'" with "'", which does nothing but waste more resource.
Posted: Sat Jul 14, 2007 3:11 am
by invisibled
it will replace a single quote with a hardcoded single quote, when my script is done. Also i do that becuase i like doing it, everybody has there own way of coding and thats my way. but thanks i'll go turn magic quotes on and see if that helps.