473,287 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

PHP MySQL query not displaying data

Hello!

I am having some problems with a database query that I am trying to do.
I am trying to develop a way to search a database for an entry and
then edit the existing values. Upon submit, the new values are updated
in all corresponding tables (the function of the pages in question).
However, on the page that does the DB update, I also want to do some
checks on the data before performing the update.

Now, the problem that I am running into is that when I don't update the
primary key field (keyid) the page is running into the section where it
displays a message that the keyid already exists. This only happens
when the keyid on the previous page is not changed.

Upon troubleshooting the problem I found that the very first SELECT
statement does not seem to be returning any rows despite the fact that
the statement, when run on the SQL server, returns exactly one row. If
any could provide some assistance with this matter, I would be most
appreciative.

Regards;

Jayson Schultz

Code:
<?php
session_start();
header("Cache-control: private"); //IE 6 Fix

//continue if authenticated
if ($_SESSION['auth'] == 1)
{

//get variables from post
$keyid = $_POST['keyid'];
$username = $_POST['username'];
$corpid = $_POST['corpid'];
$usergroupname = $_POST['usergroupname'];
$oldkeyid = $_POST['oldkeyid'];
$oldcorpid = $_POST['oldcorpid'];
echo("Keyid: $keyid");

// Connect to MySQL
mysql_connect ("address.com", "user", "pass")
or die ('I cannot connect to the database because: ' .
mysql_error());
//select database on server
mysql_select_db ("seniorproject");

//SQL Statement
$sql = "SELECT keyid, corpid FROM users
WHERE keyid='".$keyid"'";

// Execute the query and put results in $result

$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );
echo mysql_result($result,0);

// Count number of matches and print to screen
$numrows = mysql_numrows( $result );
if ($numrows == 1)
{ echo(" SQL Query: $sql");
$result_ar = mysql_fetch_row($result);
$result_ar = mysql_fetch_row($result);
$dbkeyid = $result_ar['keyid'];
$dbcorpid = $result_ar['corpid'];
echo("<br> CorpID: $corpid <br>");
echo(" DBCorpid: $dbcorpid <br>");
echo(" DBKeyID: $dbkeyid <br>");
if($dbcorpid == $oldcorpid)
{
//If this condition is true, then KEYID has not changed. Execute
code

// Formulate the query

$sql = "UPDATE users
SET corpid = '".$corpid."', username = '".$username."',
usergroup = '".$usergroupname."', keyid = '".$keyid."'
WHERE keyid = '".$oldkeyid."'";

// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error." );
// Formulate the query
$sql = "UPDATE accesslog
SET keyid = '".$keyid."'
WHERE keyid = '".$oldkeyid."'";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error." );

// Formulate the query
$sql = "UPDATE aclusersdoors
SET user = '".$keyid."'
WHERE user = '".$oldkeyid."'";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error." );

// Formulate the query
$sql = "UPDATE aclusersdoorgroups
SET user = '".$keyid."'
WHERE user = '".$oldkeyid."'";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error." );
//DB Modifcaiton Succeeded
echo("DB Modification Succeeded");
} //Terminates if from line 40

else{
$error = "New KeyID Already Exists";

die;

}//Terminates Else

}//Termiantes If
else{

//No Duplicate DoorID Exists... Can Proceed

//Check for valid door group
$sql = "SELECT * FROM usergroups
WHERE usergroup ='$usergroupname'";

// Execute the query and put results in $result

$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );

// Count number of matches and print to screen
$numrows = mysql_numrows( $result );

if ($numrows == 1)
{
//DoorGroup is valid. Can Proceed.
// Formulate the query
echo("KeyID: $keyid");
$sql = "UPDATE users
SET corpid = '".$corpid."', username = '".$username."',
usergroup = '".$usergroupname."', keyid = '".$keyid."'
WHERE keyid = '".$oldkeyid."'";
echo("Users: $sql");

// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error." );
// Formulate the query
$sql = "UPDATE accesslog
SET keyid = '".$keyid."'
WHERE keyid = '".$oldkeyid."'";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error.");

// Formulate the query
$sql = "UPDATE aclusersdoors
SET user = '".$keyid."'
WHERE user = '".$oldkeyid."'";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error." );

// Formulate the query
$sql = "UPDATE aclusersdoorgroups
SET user = '".$keyid."'
WHERE user = '".$oldkeyid."'";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error." );

echo("DB Modification Succeeded");

");
}
else{
$error = "Invalid Door Group";

die;
}
}
}
else{
echo("
//Display Restricted Area HTML Page
");
}

?>

Jul 17 '05 #1
2 3395
On 2005-03-25, jaysonsch <ja****@jaysonschultz.com> wrote:
Hello!

I am having some problems with a database query that I am trying to do.
I am trying to develop a way to search a database for an entry and
then edit the existing values. Upon submit, the new values are updated
in all corresponding tables (the function of the pages in question).
However, on the page that does the DB update, I also want to do some
checks on the data before performing the update.

[snip code]

Start scripts with:
ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);

Append mysql_error() to your message in the die() function call.

Use mysql_real_escape_string before inputting it blindly in a query.
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #2


jaysonsch wrote:
Hello!

<snip>

Well, right off hand...

$sql = "SELECT keyid, corpid FROM users WHERE keyid='".$keyid . "'";
missing^
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Philip Stoev | last post by:
Hi all, Please tell me if any of this makes sense. Any pointers to relevant projects/articles will be much appreciated. Philip Stoev http://www.stoev.org/pivot/manifest.htm ...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
6
by: jfizer | last post by:
I'm trying to print out a table of mySQL data as XML. However, the performance I'm getting is REALY bad. Adding the header("Content-Type: $mime;charset=$charset"); statement triples the load time...
10
by: Lloyd Harold | last post by:
I'm very new to PHP and attempting to put together a simple script for retrieving MySQL data of personal records. The MySQL table I'm using consists of: 0: id 1: name 2: location (an integer...
3
by: printline | last post by:
Hello All I need a little help with a phph script to display some specific data from a mysql table. I have a mysql table with 4 columns and 10 rows. I want to display fx. data from row 4, 6, 8...
4
by: foss | last post by:
HI all, I am able to upload the image as blob to mysql. but while displaying the image i cant display it properly . The code used for uploading image to mysql inserts data into mysql table.The...
3
by: thesmithman | last post by:
Well, actually, I'm sure it's my code... I have a basic nested query: $query="INSERT INTO items (blah, blah, blah) VALUES ('$blah', '$blahblah', NULL)"; $result=mysql_query($query) or...
4
by: bodhiSoma | last post by:
I've got this weird problem. I'm connecting to MySQL via PHP, querying a particular table, closing the connection then parsing and displaying the results. I then modify the table but when I...
9
by: PI | last post by:
Hi Guys, I need some assistance with the following scenario please. I know this might be more of a MySQL post than a PHP one, but it is likely some developer has been here before and would be...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.