?
Solved

error in script need help (again but different script)

Posted on 2003-03-06
6
Medium Priority
?
268 Views
Last Modified: 2009-12-16
I am trying to update a database but it wont update but it all looks in order, the variables come from a separate form

<?php
$db = mysql_connect("localhost","root");
mysql_select_db("scouts", $db);

mysql_query("UPDATE data set name='$name', rank='$rank', position='$position', required='$required', nrequired='$nrequired', WHERE id='$id'", $db);

?>
0
Comment
Question by:bartonjo2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 

Accepted Solution

by:
beauty_fool earned 160 total points
ID: 8086819
you have an extra comma after the required field

>> nrequired='$nrequired', WHERE id='$id'", $db);

remove that.

If this is not the problem, then what error exactly are u getting?
0
 

Expert Comment

by:beauty_fool
ID: 8086826
sorry, not 'required' but 'nrequired', just before the 'WHERE'
0
 
LVL 3

Author Comment

by:bartonjo2
ID: 8087354
great! it worked but i have two others scripts with problems can you guys look at these

<?php
$db = mysql_connect("localhost","root");
mysql_select_db("scouts",$db);

mysql_query("DELETE from $table WHERE id=$id", $db);

?>
<?php
$db = mysql_connect("localhost","root");
mysql_select_db("scouts",$db);

mysql_query("INSERT INTO $table SET name='$iname', rank='$irank', position='$iposition, required='$irequired'", $db);

?>

other script

<?php
$db = mysql_connect("localhost","root");
mysql_select_db("scouts",$db);

mysql_query("DELETE from $table WHERE id=$id", $db);

?>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Author Comment

by:bartonjo2
ID: 8087359
plese tell me the errors for the insert one and then the delete, i will add 10 points because you guys are doing this
0
 

Expert Comment

by:beauty_fool
ID: 8087440
About the DELETEs : from the first question it seems that the id field is a string. If this is also the case with the tables you're trying to delete from then you should put the $id variable in single quotes:

>>DELETE from $table WHERE id='$id'

The INSERT statement siyntax is as follows:
>>INSERT INTO $table (field_name) VALUES ('$value')

In your case it would be

>>INSERT INTO $table (name, rank, position, required) VALUES ('$iname', '$irank', '$iposition, '$irequired')

regards
0
 
LVL 1

Expert Comment

by:Amerist
ID: 8093559
Easy.

Replace:

mysql_query("UPDATE data set name='$name', rank='$rank', position='$position', required='$required', nrequired='$nrequired', WHERE id='$id'", $db);

With:

mysql_query("UPDATE data set name='$name', rank='$rank', position='$position', required='$required', nrequired='$nrequired', WHERE id='$id'");

In other words, get rid of the ", $db" at the end.   It's not necessary.  You have already selected your database in the previous line.
0

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question