PDA

View Full Version : SQL Syntax (Errors Using MySQL 5.0 Language PHP)


pipwax1390564
10-17-2009, 01:30 PM
The Sql fail to submit. This is what I get when I test the page "SELECT * FROM employeelookup 0" I made this change to the code so that I can see the information
===========modified code===========
$query_Members = sprintf("SELECT * FROM employeelookup %s", GetSQLValueString($WhereParam_Members, "int"));
echo $query_Members;
exit;
$Members = mysql_query($query_Members, $Recipes) or die(mysql_error());
$row_Members = mysql_fetch_assoc($Members);
$totalRows_Members = mysql_num_rows($Members);
?>
=============end modified code==============

======================entire code=================
<?php require_once('../../Connections/Recipes.php'); ?>
<?php
mysql_select_db($database_Recipes, $Recipes);
$query_EmployeeLookup = "INSERT INTO employeelookup SELECT employees_1.EmployeeID, jobs.JobID, jobs.JobTitle, employees_1.EmployeeFirst, employees_1.EmployeeLast, departments.DepartmentName, CONCAT(employees.EmployeeFirst,' ',employees.EmployeeLast) AS ManagerName, employees_1.EmployeeEmail, employees_1.EmployeePhone, employees_1.EmployeeMobil, employees_1.EmployeeCube FROM employees, employees employees_1, jobs, jobs jobs_1, departments WHERE ((((jobs.JobTypeID = jobs_1.JobID) AND (jobs.JobDepartment = departments.DepartmentID)) AND (employees.EmployeeJob = jobs_1.JobID)) AND (employees_1.EmployeeJob = jobs.JobID))";
mysql_query($query_EmployeeLookup,$Recipes);
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$WhereParam_Members = 'Where MemberID <> 0';
if (isset($WhereParam)) {
$WhereParam_Members = $WhereParam;
}
mysql_select_db($database_Recipes, $Recipes);
$query_Members = sprintf("SELECT * FROM employeelookup %s", GetSQLValueString($WhereParam_Members, "int"));
echo $query_Members;
exit;
$Members = mysql_query($query_Members, $Recipes) or die(mysql_error());
$row_Members = mysql_fetch_assoc($Members);
$totalRows_Members = mysql_num_rows($Members);
?><?php
$query_EmployeeLookup = "DELETE FROM employeelookup";
mysql_query($query_EmployeeLookup,$Recipes);
?>
======================end====================
Any help would be greatly helpful

Jason Byrnes
10-19-2009, 09:43 AM
Why are you putting the where clause into a parameter for the members recordset?

The way I see it, the where clause will not change, right? parameters are used for variable data. data that may change.

why not just hard code the where clause with the select statement:

SELECT * FROM employeelookup Where MemberID <> 0

pipwax1390564
10-19-2009, 11:37 AM
To the best of my knowledge i was following the instructions from the book. (Web application recipes) I just added the members table because I wanted to use thr module for a members system to a web community. However, when I think about it I only had to change the html lables?

Jason Byrnes
10-19-2009, 01:11 PM
The problem is the way the members recordset is created.


Do not use a parameter, just add the where clause directly in the SQL:
SELECT * FROM employeelookup Where MemberID <> 0

pipwax1390564
10-19-2009, 02:54 PM
I am still learning this stuff, I am not sure where I would need to alter the code. Could you help me out? I am using Dreamweaver. My best guess is to double click the recordset and remove the Param and enter the Sql statement you gave me.

Jason Byrnes
10-19-2009, 03:21 PM
that is correct.

Double click the recordset, remove the parameter and add the where clause directly to the SQL statement.

pipwax1390564
10-19-2009, 06:10 PM
Made Great progress these are the errors I am getting Now:

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/content/p/i/p/pipwax2/html/test/member_results.php on line 3

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/p/i/p/pipwax2/html/test/member_results.php on line 5

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/p/i/p/pipwax2/html/test/member_results.php on line 44


Here is Line 3:mysql_select_db($database_Recipes, $Recipes);
Here is Line 5:mysql_query($query_EmployeeLookup,$Recipes);
Here is Line 44:mysql_query($query_EmployeeLookup,$Recipes);

My best guess is that $query_EmployeeLookup should be $query_employeeLookup because the table in mysql is emlpoyeelookup but that did not work.

pipwax1390564
10-19-2009, 06:13 PM
My database connection is newsfeed

could this be my problem?
Line 3:mysql_select_db($database_Recipes, $Recipes);
the database name is DavidPippen

Jason Byrnes
10-20-2009, 09:49 AM
Did you edit the "Connections/Recipes.php" file by hand?


On the database tab, double click the recipes connection and click the test button. Does the connection test correctly?


Please send a copy of the Connections/Recipes.php file.

pipwax1390564
10-20-2009, 10:00 AM
I will when I get home

pipwax1390564
10-20-2009, 02:56 PM
Here is the Connection php file. When I test the data connection It comes up no data.
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_newsfeed = "h50mysql61.secureserver.net";
$database_newsfeed = "DavidPippen";
$username_newsfeed = "DavidPippen";
$password_newsfeed = "justin1P";
$newsfeed = mysql_pconnect($hostname_newsfeed, $username_newsfeed, $password_newsfeed) or trigger_error(mysql_error(),E_USER_ERROR);
?>

This is the url on the testing server: http://www.sk8photos.com/test/member_results.php

Jason Byrnes
10-20-2009, 03:15 PM
What is the name of this connection file?


The code you posted earlier was looking for a connection file named Recipes.php


looking at the code, the name of this connection file would be newsfeed.php


make sure that the page is using the recipes.php connection file.


If you wish to use a different connections file, you must go into each recordset or server behavior that uses the connection file and set it to use the new one.

pipwax1390564
10-20-2009, 04:37 PM
Thanks a million! I made the changes to the database connection to this:mysql_select_db($database_newsfeed, $newsfeed); that took care of it I think. Only showing one record.

pipwax1390564
10-20-2009, 04:59 PM
Where would I start to troubleshoot the reason why only one record is showing?

pipwax1390564
10-20-2009, 05:03 PM
Sorry I figured it Out, Silly me!