Josh Barton
asked on
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);
?>
<?php
$db = mysql_connect("localhost",
mysql_select_db("scouts", $db);
mysql_query("UPDATE data set name='$name', rank='$rank', position='$position', required='$required', nrequired='$nrequired', WHERE id='$id'", $db);
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry, not 'required' but 'nrequired', just before the 'WHERE'
ASKER
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);
?>
<?php
$db = mysql_connect("localhost",
mysql_select_db("scouts",$
mysql_query("DELETE from $table WHERE id=$id", $db);
?>
<?php
$db = mysql_connect("localhost",
mysql_select_db("scouts",$
mysql_query("INSERT INTO $table SET name='$iname', rank='$irank', position='$iposition, required='$irequired'", $db);
?>
other script
<?php
$db = mysql_connect("localhost",
mysql_select_db("scouts",$
mysql_query("DELETE from $table WHERE id=$id", $db);
?>
ASKER
plese tell me the errors for the insert one and then the delete, i will add 10 points because you guys are doing this
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
>>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
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.
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.