Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

error in script need help (again but different script)

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
bartonjo2
Asked:
bartonjo2
  • 3
  • 2
1 Solution
 
beauty_foolCommented:
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
 
beauty_foolCommented:
sorry, not 'required' but 'nrequired', just before the 'WHERE'
0
 
bartonjo2Author Commented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bartonjo2Author Commented:
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
 
beauty_foolCommented:
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
 
AmeristCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now