Jump to content

Change Data in MySQL


Smee

Recommended Posts

Hi,

 

Was wondering how i would go about changing the answer of lets say an attending column in a database.

 

Basically i want to use yes/no radio buttons in a form to allow users to say if they will attend. If they click yes then 'yes' will be stored in attending column, where as if they click no .. 'no' will be stored in attending column.

 

Hope this makes sense :P

 

Thanks for any help

Link to comment
https://forums.phpfreaks.com/topic/200417-change-data-in-mysql/
Share on other sites

Thanks for your relpy,

 

I have tried implementing something along those lines but to no avail!

 

I am getting the error:

 

an error occured in the script '/home/footba33/public_html/attending.php' on 47:

Undefined variable: result

 

Lince 47 code is:

 

   if (mysql_num_rows($result) == 0) {
      $query = "UPDATE users attending VALUES '$at'";
      $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error:" .mysql_error());
  } else {

 

The rest of the script is below and thanks for any help!

 

<?php 

// Tell php we're using sessions.

// This script allows us to search our database

require_once ('./includes/config.inc.php');

$page_title = 'Search';

include_once ('./includes/header.html');

?>

<div id="search">

<h1> Attending Next Match </h1>

<form action="attending.php" method="post" />
            
            <p class="attending"><label> Attending Yes/No: </label>
<input type="text" name="attending" maxlength="3" value="<?php if (isset($_POST['attending'])) echo $_POST['attending']; ?>" />

	  <p class="submit">
<input type="submit" name="submit" value="Register" />
            
  </form>

</div>

<div id="searchconfirmation">

<?php

if (isset($_POST['submit'])) {

require_once ('../mysql_connect.php');

$error = false;
if (preg_match ('/^[[:alpha:]\.\'\-]{2,30}$/i', stripslashes(trim($_POST['attending'])))) {
   $at = mysql_real_escape_string($_POST['attending']);
}else {
   $error = true;
   echo '<center><p><font color ="red"> Please enter Yes or No!</font></p></center>';
}

   if (mysql_num_rows($result) == 0) {
      $query = "UPDATE users attending VALUES '$at'";
      $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error:" .mysql_error());
  } else {
   
      if (mysql_affected_rows() == 1) {
      
         echo '<center><p>Your Status has been set!</p></center>';

      }else { 
   echo '<center><p><font color="red"> Please try again.</font></p></center>';
}
      
mysql_close();

}

}

?>

</div>

<?php

// Footer
include ('./includes/footer.html');

?>

That was not what I posted. 

  $query = "UPDATE users attending VALUES '$at'";

 

What you want is something like:

 

  $query = "UPDATE users SET attending = '$at' WHERE id=$id";

 

But I see you have no userid in your form, so I don't know how to help you.  What I can say, however, is that "UPDATE users attending VALUES '$at'"; will fail.

 

http://dev.mysql.com/doc/refman/5.0/en/update.html

 

please review.

 

 

 

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.