Jump to content

Recommended Posts

here is the code:

<?php

include('/Library/WebServer/Documents/scripts/db-connnect.php');

$username = $_POST['name'];
$userfacility = $_POST['facility'];
$userposition = $_POST['position'];
$useremail = $_POST['email'];
$usercontact = $_POST['contact'];
$userpass = $_POST['pass1'];
$id = $_POST['userid'];

$query = "UPDATE `addison`.`users` SET `user_name` = '$username',`user_facility` = '$userfacility',`user_position` = '$userposition',`user_email` = '$useremail',`user_contact` = '$usercontact',`user_pass` = '$userpass',`update_date` = NOW( ) WHERE `users`.`user_id` ='$id' LIMIT 1 ;";

mysql_select_db('addison');

$check = mysql_query("SELECT user_name FROM users WHERE user_name = '$username'") or die ("query 1: " . mysql_error());
$mysql_num = mysql_num_rows($check);

if ($mysql_num != 1)
{
echo "<br /><br /><br /><h2><center>I can't add <b>".$username."</b> because this person is already a user.</h2></center>\n";
echo '<br /><h4><center>Please use the <a href="http://mysite.com/index.php?page=update-a-user">User Update Form</a> or simply <a href="' . $_SERVER['HTTP_REFERER'] . '">Retry</a> it.</h4></center>';
}
else
{ 
mysql_query( $query);
echo "<br><br><center><h2>The user <b>".$username."</b> was added succesfully!</h2></center>\n";
echo '<br /><center><h4><a href="' . $_SERVER['HTTP_REFERER'] . '">Go Back</a></center></h4>';
}

mysql_close($mysql_link);

?>

 

I even used phpMyAdmin to generate the query this time. It doesn't error but it doesn't update anything. If i change this to an insert. . .it will work . . ???? What am I doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/62493-update-just-not-working/
Share on other sites

are you creating accounts?  this looks like an account creation page since you are querying the user table to check to see if the username already exists.  if this is an account creation page, then you need to use INSERT instead of UPDATE.  there has to be a record that already exists to update it.

 

 

EDIT:

 

plus you need to add the code thorpe suggested.

mysql_query( $query) or die(mysql_error());

 

Now do you get an error?

 

nope. no error. also, this is a user creation thing . .well its an edit page. I have the information thrown into a form. this is the page that sends to the script:

<?php

include('/Library/WebServer/Documents/scripts/db-connnect.php');

mysql_select_db("addison") or die(mysql_error());

$id = $_GET['id'];
$query = mysql_query("SELECT * FROM users WHERE user_id='$id'");
$values = mysql_fetch_array($query);

echo "<table style=\"width: 800px; height: 98px; text-align: left; margin-left: auto; margin-right: auto;\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">";
echo "<tr><td>";
echo "<fieldset><legend>Edit ".$values['user_name']."</legend>";
echo "<form name=\"userinfo\" enctype=\"multipart/form-data\" action=\"/scripts/update-a-user.php\" method=\"POST\">";
echo "<br>  ";
echo "<input name=\"name\" value=\"".$values['user_name']."\">  Full Name<br>";
echo "<br>  ";
echo "<select selected=\"".$values['user_facility']."\" name=\"facility\">";
echo "<option>Chesapeake</option>";
echo "<option>Fort Worth</option>";
echo "<option>Ontario</option>";
echo "<option>Providence</option>";
echo "</select>  Composing Facility<br>";
echo "<br>  ";
echo "<select selected=\"".$values['user_position']."\" name=\"position\">";
echo "<option>Book Builder</option>";
echo "<option>Ad Builder</option>";
echo "<option>Proofer</option>";
echo "<option>Trafficker</option>";
echo "<option>Typesetter</option>";
echo "<option>Shift Manager</option>";
echo "<option>Customer Serivce</option>";
echo "<option>Office Manager</option>";
echo "<option>Composing Manager</option>";
echo "</select>  Position<br>";
echo "<br>  ";
echo "<input name=\"email\" value=\"".$values['user_email']."\">  Email Address<br>";
echo "<br>  ";
echo "<input name=\"contact\" value=\"".$values['user_contact']."\">  Contact Number<br>";
echo "<br>  ";
echo "<input name=\"pass1\" value=\"".$values['user_password']."\">  Password<br>";
echo "<br>  ";
echo "<input name=\"userid\" disabled value=\"".$id."\">  Addison ID Number<br>";
echo "<br> ";
echo "<input value=\"Add\" type=\"submit\">  <input value=\"Clear Form\" type=\"reset\"><br><br>";
echo "</fieldset><br><br>";
echo "</form>";
echo "</td></tr>";
echo "</table>";

mysql_close($mysql_link);

?>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.