Jump to content

Php Form, Update Database


beennn

Recommended Posts

why don't you show us your code so we can verify it's accuracy? and have you echo'd the output of mysql_affected_rows?

Link to comment
Share on other sites

iv tried:

UPDATE groups WHERE group_name='$group_name' SET number_of_members = number_of_members + 1

and get this error, is there a way to get the '\\\' out of it? error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE group_name='PFU\\\'s' SET number_of_members = number_of_members + 1' at line 1 EDIT:

why don't you show us your code so we can verify it's accuracy? and have you echo'd the output of mysql_affected_rows?
i did on page 1:
<?$con = mysql_connect("localhost","username","password");if(!$con) {  echo mysql_error();}mysql_select_db("db_name", $con);$group_name = mysql_real_escape_string($_GET['group_name']);$result = mysql_query("SELECT * FROM groups WHERE group_name='$group_name'");if(!$result) {  echo mysql_error();}while($row = mysql_fetch_array($result))  {  mysql_query("UPDATE groups SET number_of_members = number_of_members + 1");  }?>

Link to comment
Share on other sites

the code request was in reference to the latest changes. not what you started with, because we know that didn't work. What's helpful is seeing what you are currently trying to do as you make the changes to it.

Link to comment
Share on other sites

oooh, ok, heres what im trying now:

<?$con = mysql_connect("localhost","username","password");if(!$con) {  echo mysql_error();}mysql_select_db("db_name", $con);$group_name = mysql_real_escape_string($_GET['group']);$result = mysql_query("SELECT * FROM groups WHERE group_name='$group_name'");if(!$result) {  echo mysql_error();}  $check = mysql_query("UPDATE groups SET number_of_members = number_of_members + 1 WHERE group_name='$group_name'");if(!$check){  echo mysql_error();}?>

i moved the WHERE to the end which got rid of the error thanks but still doesnt update the db

Link to comment
Share on other sites

just out of curiosity, what's the purpose of the SELECT query? it might be easier to just get the number_of_members from the SELECT result, and then add +1 to it, then just use that value in the UPDATE, rather than trying to do all the math in the query.

Link to comment
Share on other sites

still trying to get to grips with php >.< only done a few things with it in the past and so i try to modify preveious scripts made, i assumed it needed that as i was checking each row. so like this?

<?$con = mysql_connect("localhost","username","password");if(!$con) {  echo mysql_error();}mysql_select_db("db_name", $con);$group_name = mysql_real_escape_string($_GET['group']);$result = mysql_query("UPDATE groups SET number_of_members = number_of_members + 1 WHERE group_name='$group_name'");if(!$result) {  echo mysql_error();}?>

Link to comment
Share on other sites

i um, really confused, appeared to work perfectly in phpMyAdmin, then checked the database and nothing had changed AAAH! ok, its the ' in PFU's that was causing the problem, i tried on a plain text and worked perfectly, is there a way around this?

Link to comment
Share on other sites

You need to figure out why it doesn't match the database. It might be a different character. If it was the same character as what was stored in the database then it would match. Look at the record in the database versus the where clause in your query. Incidentally, this is one of the reasons why people typically use numeric IDs.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...