/    Sign up×
Community /Pin to ProfileBookmark

Whats wrong with my update query?

Hi folks, can you help me out here? Below are two pages, when i click submit on index_admin.php i get the message Update sucseful (or something like that…) but it dosent acctualy update the DB itself… Fet

index_admin

[code=php]
<?
require ‘db_connect.php’;

$query=”SELECT * FROM Front_Page WHERE ID=’$ID'”;
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {
$Nav_Bar=mysql_result($result,$i,”Nav_Bar”);
$Next_Meeting=mysql_result($result,$i,”Next_Meeting”);
$Next_Meeting_Text=mysql_result($result,$i,”Next_Meeting_Text”);
$Program_Title=mysql_result($result,$i,”Program_Title”);
$Program_Text=mysql_result($result,$i,”Program_Text”);
$Iceland_Title=mysql_result($result,$i,”Iceland_Title”);
$Iceland_Text=mysql_result($result,$i,”Iceland_Text”);
$Images_Title=mysql_result($result,$i,”Images_Title”);
$Images=mysql_result($result,$i,”Images”);
?>
<form action=”update.php”>
<input type=”hidden” name=”UD_ID” value=”<?php echo ($ID) ?>” />
<input name=”Nav_Bar” type=”text” value=”<?php echo htmlentities($Nav_Bar) ?>” />
<input name=”Next_Meeting” type=”text” value=”<?php echo htmlentities($Next_Meeting) ?>” />
<input name=”Next_Meeting_Text” type=”text” value=”<?php echo htmlentities($Next_Meeting_Text) ?>” />
<input name=”Program_Title” type=”text” value=”<?php echo htmlentities($Program_Title) ?>” />
<input name=”Program_Text” type=”text” value=”<?php echo htmlentities($Program_Text) ?>” />
<input name=”Iceland_Title” type=”text” value=”<?php echo htmlentities($Iceland_Title) ?>” />
<input name=”Iceland_Text” type=”text” value=”<?php echo htmlentities($Iceland_Text) ?>” />
<input name=”Images_Title” type=”text” value=”<?php echo htmlentities($Images_Title) ?>” />
<input name=”Images” type=”text” value=”<?php echo htmlentities($Images) ?>” />
<input type=”Submit” value=”update”>
</form>
<?
++$i;
}
?>
[/code]

update.php

[code=php]
<?php

$hostname=”localhost”;
$username=”comp”;
$password=”hiy”;
$database=”n”;

// Connect to the database
mysql_CONNECT($hostname, $username, $password) OR die(mysql_error());
@mysql_SELECT_DB(“$database”) OR die(mysql_error());

// Ask the database for the information from the links table
$query=”UPDATE Front_Page SET

Nav_Bar = `$Nav_Bar`,
Next_Meeting = `$Next_Meeting`,
Next_Meeting_Text = `$Next_Meeting_Text`,
Program_Title = `$Program_Title`,
Program_Text = `$Progam_Text`,
Iceland_Title = `$Iceland_Title`,
Iceland_Text = `$Iceland_Text`,
Images_Title = `$Images_Title`,
Images = `$Images`;
WHERE
ID=’ID'”;

@mysql_select_db($database) or die(mysql_error());

mysql_query($query) or die(mysql_error());
echo “Record updated”;
mysql_close();
?>

[/code]

[/code]

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMar 01.2006 — [code=php]$query="UPDATE Frotn_Page SET [/code]

Isn't there a typo on this line? Frotn? Front?
Copy linkTweet thisAlerts:
@scottyrobauthorMar 01.2006 — Changed, Problem still occurs
Copy linkTweet thisAlerts:
@ProWebMar 01.2006 — make sure the value of '$ud_id' actually matches something in the database.

Also most sql syntax errors are much easier to debug if you print the query to the screen prior to execution.
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMar 01.2006 — place the fieldnames in backticks, not the variables, instead, place the variables in single quotes
Copy linkTweet thisAlerts:
@kattenMar 01.2006 — where you see this
[code=php]
mysql_query($query);
[/code]

change to
[code=php]
mysql_query($query) or die(mysql_error());
[/code]


Could be somthing wrong with your table
Copy linkTweet thisAlerts:
@scottyrobauthorMar 01.2006 — The error i get now is

You have an error in your SQL syntax near '; WHERE ID=''' at line 10

(The code above in update.php has been changed to show any suggestions you have made, and that i have edited it in the original file...)
Copy linkTweet thisAlerts:
@kattenMar 01.2006 — WHERE

ID='ID' <- id has got no value that is why
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMar 01.2006 — You're missing a $-sign for the ID variable, aren't you?
Copy linkTweet thisAlerts:
@ProWebMar 02.2006 — As I said Above ? check ID has a value!
×

Success!

Help @scottyrob spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...