MySql Update Query Issues

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
invisibled
Forum Contributor
Posts: 112
Joined: Sun Apr 29, 2007 3:35 pm
Location: New Westminster

MySql Update Query Issues

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Something tells me it actually is your code. Can you post some of it?
invisibled
Forum Contributor
Posts: 112
Joined: Sun Apr 29, 2007 3:35 pm
Location: New Westminster

Post 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]
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post 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);
invisibled
Forum Contributor
Posts: 112
Joined: Sun Apr 29, 2007 3:35 pm
Location: New Westminster

reply

Post 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
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post by xpgeek »

Only one Update qeury don't work or all update queries don't work on the host ?
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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?
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post 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:
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

I like if() { } because i can mark all the code between {} with my editor ;)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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 ...
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply