Page 1 of 1

MySql Update Query Issues

Posted: Sun Aug 26, 2007 9:41 pm
by invisibled
Hey guys,

ok so mysql update queries are not working on my localhost and i need to figure out why and right now i am completly stuck. I know its not my code becuase, it works on my webserver and it NEVER works on any sites on my localhost.

Here are the versions of my software
Mac OS X 10.4.10
Php 5.2.2
Apache 1.3
MySql 5.0.37

I dont really know what else to say other than i'm completly stuck. If you need me to post somthing tell me and i'll post it.

Thanks to all in advance :)

-Shan

Posted: Sun Aug 26, 2007 9:46 pm
by feyd
Something tells me it actually is your code. Can you post some of it?

Posted: Sun Aug 26, 2007 10:06 pm
by invisibled
feyd | Please use

Code: Select all

,

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]

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 the page with teh form

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/" 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

,

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: Mon Aug 27, 2007 7:28 am
by xpgeek
Hi invisibled

You need to escape special chars in all you parameters.

F.e. $client = mysql_escape_string($client);

Also next string is very interesting, what it is doing ? :wink:

Code: Select all

$client = str_replace( "'", "'", $client);

reply

Posted: Mon Aug 27, 2007 11:11 am
by invisibled
How will using escape string get my update queries working? That function reaplces a single quote with a hardcoded single quote, the forum just changes the ascii code into a single quote

Posted: Mon Aug 27, 2007 11:14 am
by xpgeek
Only one Update qeury don't work or all update queries don't work on the host ?

Posted: Mon Aug 27, 2007 12:12 pm
by miro_igov
Try

Code: Select all

$upd = mysql_query($query) or die(mysql_error());
This will show you if you have error in the query.

Also adding ini_set('display_errors',1); will help you if the script contains errors.

i never seen this if: endif; syntax in php, are you sure it is valid?

Posted: Mon Aug 27, 2007 12:29 pm
by xpgeek
miro_igov wrote:skipped

i never seen this if: endif; syntax in php, are you sure it is valid?
Yeah it is valid, it is best syntax to combine php and html together. :wink:

Posted: Mon Aug 27, 2007 12:31 pm
by miro_igov
I like if() { } because i can mark all the code between {} with my editor ;)

Posted: Mon Aug 27, 2007 1:45 pm
by VladSun
Are you sure you successfully connect to mysql?
Maybe you have not GRANT any users@localhost ...
My suggestion is that it is not a code mistake, but a mysql administration mistake ...