Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

PHP, mysql UPDATE will not work


  • Please log in to reply
1 reply to this topic

#1 g2gsr93

g2gsr93

  • Members
  • 21 posts
  • OFFLINE
  •  
  • Local time:01:56 PM

Posted 02 July 2010 - 08:36 AM

Sorry I've been blowing up this forum lately. I have a problem that I have yet to be able to solve looking back on this site or anywhere else around the web.
Here is my code

<?php
session_start();
$connection = mysql_connect("localhost","admin","admin"); //connection variable for later use
if (!$connection)
	{
	die('Could not connect to the database. ' . mysql_error()); //error for no connection
	}
mysql_select_db("supplysource",$connection);//select db
//set edit rep form variables
$repid = $_POST['repID'];
$repnamelast = $_POST['repNameLast'];
$repnamefirst = $_POST['repNameFirst'];
$repphone = $_POST['repPhone'];
$repemail = $_POST['repEmail'];
//create function for editing rep info
function edituser($repnamelast, $repnamefirst, $repphone, $repemail)
	{
	$updaterep = "UPDATE salesrep SET repNameLast='$repnamelast', repNameFirst='$repnamefirst', repPhone='$repphone', repEmail='$repemail' WHERE repID='$repid'";
	mysql_query($updaterep) or die(mysql_error());
	$_SESSION['editrep'] = 3;//change editrep variable to 3 for adminrepsadmin.php proper handling
	}
//check for blank form fields
if(empty($repnamefirst) || empty($repnamelast) || empty($repphone) || empty($repemail))
	{
	$_SESSION['editrep'] = 4;
	header("Location:http:adminrepsadmin.php");
	}
//if all error checking return ture, run edituser funciton and return to adminrepsadmin.php
else
	{
	edituser($repnamelast, $repnamefirst, $repphone, $repemail);
	header("Location:http:adminrepsadmin.php");
	}
?>

My problem is the "UPDATE salesrep..." query. It will not update the database. The code runs and gives me my "Rep changed!" output saying that it has been done, and there are no errors. I've echoed all my variables and they are being set properly. I have even echoed the entire UPDATE query, and pasted it into myphpadmin and it updated the way it was supposed to. So somehow the query isn't being delivered properly. Any ideas?


EDIT: Sorry again, but I figured it out. Its amazing how when you ask for help, set the project down for an hour and come back you figure it out. I wasn't calling the $repid in the function "edituser" when I added it in, works like a charm. Thanks again if you did look at it. =)

Edited by g2gsr93, 02 July 2010 - 09:56 AM.


BC AdBot (Login to Remove)

 


#2 Adam17

Adam17

  • Members
  • 21 posts
  • OFFLINE
  •  
  • Local time:01:56 PM

Posted 06 July 2010 - 04:20 PM

No need to be sorry about asking for help. That is why the forum is here :thumbsup:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users