HTML help

TahoE

Forum Fiend
Hey everyone,

I am designing a little website for a company and I am running into a single issue that I cannot resolve myself it seems. I keep getting this error:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1"

Every time I try to submit the information I get this error. Here is the coding on the page (I am using Dreamweaver CS5):

<?php
include_once "../auth.php";
include_once "../include/header_up_pic_emp.php";
include_once "../include/menu.php";
include_once "../connect.php";
?>
<h1>Add Staff Member</h1>
<div id="content">
<img src="images/spacer.gif" height="32" width="1" style="float: left"/>

<div class="version">General Information</div>

<div id="status_emp"></div>
<div id="car_details">
<form name="form1" method="get" action="javascript:add_employee()">
<table border="0" cellpadding="0" cellspacing="0" class="list" style="padding:20px 0px;">
<tr>
<td width="10"></td>
<td height="30"><label for="name">Name</label></td>
<td><input type="text" name="name" id="name" size="55" value="" /></td>
</tr>
<tr>
<td width="10"></td>
<td height="30"><label for="title">Title</label></td>
<td><input type="text" name="title" id="title" size="55" value="" /></td>
</tr>
<tr>
<td width="10"></td>
<td height="30"><label for="description">Description</label></td>
<td><textarea name="description" cols="100" rows="6" id="description"></textarea> </td>
</tr>
<tr>
<td width="10"></td>
<td height="30"></td>
<td></td>
</tr>
<tr>
<td width="10"></td>
<td height="30"><label for="description">Upload Photos</label></td>
<td><input id="uploadify" name="uploadify" type="file" />
<div id="status"></div> </td>
</tr>
<tr>
<td colspan="3">
<input type="hidden" id="time" name="time" value="<?=$time?>">
<input name="Submit" type="submit" id="Submit" style="color:#ffffff;background:#545354;padding:4px 10px;border:0px;font-size:11pt;font-family:Arial;font-weight:bold;margin-left:196px;margin-top:55px" value="Submit" />
</td>
</tr>
</table>
</form>
</div>




Thanks for all your help guys!

P.S. I will be posting pics of my new computer system soon (THANKS AGAIN PHOBUS FOR THE HELP WITH THAT)
 

spidEY

Poster Extraordinaire
It seems that you have a syntax error in your MySQL query, this is not a HTML problem, can you post your PHP code?
 
Last edited:

Passerby

Poster Extraordinaire
ya nothing in there can really help that is just all basic formating information for tables with a few php includes. could you post the content of the php includes.
 

TahoE

Forum Fiend
Ok, sorry been busy at work. Here are the php includes:

Auth.php


<?php
session_cache_expire(50000);
session_start();
if ((isset($_SESSION["user"]))&&($_SESSION['user']=="admin"))
{ }
else
{
header("Location: /ad/index.php?err=1");
}
?>
 

TahoE

Forum Fiend
Header_up_pic_emp.php



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>ADMIN PANEL</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<link rel="stylesheet" type="text/css" href="/ad/files/main.css" />
<link rel="stylesheet" type="text/css" href="/ad/files/menu.css" />
<link rel="stylesheet" type="text/css" href="/ad/files/mozilla.css" />
<!-- Mozilla specific features enabled -->
<script type="text/javascript" src="/ad/files/ie5.js"></script>
<script type="text/javascript" src="/ad/files/XulMenu.js"></script>
<script type="text/javascript" src="/ad/files/browser.js"></script>
<script type="text/javascript" src="/ad/files/tooltip.js"></script>
<script type="text/javascript" src="/ad/files/pop-list.js"></script>
<script type="text/javascript" src="../example/scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../example/scripts/swfobject.js"></script>
<script type="text/javascript" src="../example/scripts/jquery.uploadify.v2.1.0.min.js"></script>
<script type="text/javascript" src="../employees/load_content.js"></script>
<link href="../example/css/default.css" rel="stylesheet" type="text/css" />
<link href="../example/css/uploadify.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">

$(document).ready(function() {
$("#uploadify").uploadify({
'uploader' : '../example/scripts/uploadify.swf',
'script' : '../example/scripts/upload_pic_emp.php',
'cancelImg' : '../example/cancel.png',
'folder' : '/images',
'method' : 'GET',
'auto' : true,
'multi' : true,
'scriptData' : {'time' : <?php $time = time(); echo $time;?>},
onError: function (a, b, c, d) {
if (d.info == 404)
alert('Could not find upload script. Use a path relative to: '+'<?php echo getcwd() ?>');
else
alert('error '+d.type+": "+d.info);
},
onComplete: function(a, b, c, d, e){
document.getElementById('status').innerHTML = 'Upload succesful...';
if (d !== '1')
alert(d);
}
});

});
$('#uploadify').uploadifySettings('buttonText','UPLOAD');
</script>
</head>
<body>
<script type="text/javscript">
/* preload images */
var arrow1 = new Image(4, 7);
arrow1.src = "images/arrow1.gif";
var arrow2 = new Image(4, 7);
arrow2.src = "images/arrow2.gif";
</script>
<div id="page">
 

TahoE

Forum Fiend
Menu.php


<div class="menugradient">

<div id="bar" class="bar">

<div align="center">
<table align="center" cellpadding="5" cellspacing="0" class="XulMenu" id="mainMenu">

<tr>

<td><div align="center"><img src="/ad/images/nubs.gif" alt="" style="margin-top:5px;"/></div></td>

<td>

<div align="center"><a class="button" href="/ad/cars/all_cars.php"><img src="/ad/images/m_dir.gif" border="0" alt="" />INVENTORY</a> </div></td>



<td><div align="center"><img src="/ad/images/nubs.gif" alt="" style="margin-top:5px;"/></div></td>

<td>

<div align="center"><a class="button" href="/ad/cars/add_car.php"><img src="/ad/images/m_dir.gif" border="0" alt="" />ADD CAR</a> </div></td>



<td><div align="center"><img src="/ad/images/nubs.gif" alt="" style="margin-top:5px;"/></div></td>

<td>

<div align="center"><a class="button" href="/ad/cars/add_csv.php"><img src="/ad/images/m_dir.gif" border="0" alt="" />ADD CSV</a> </div></td>


<td><div align="center"><img src="/ad/images/nubs.gif" alt="" style="margin-top:5px;"/></div></td>

<td>

<div align="center"><a class="button" href="/ad/edit-pages/"><img src="/ad/images/m_dir.gif" border="0" alt="" />PAGES</a> </div></td>



<td>

<div align="center"><a class="button"href="javascript:void(0)"><img src="/ad/images/m_conf.gif" border="0" alt="" />System</a> </div> <div class="section">

<div align="center"><a class="item" href="/ad/change-password.php">Change PASSWORD</a> </div>
</div> </td>



<td>

<div align="center"><a class="button"href="/ad/admin.php"><img src="/ad/images/main_button.jpg" border="0" alt="" /><font color="blue">Main</font></a> </div></td>



<td>

<div align="center"><a class="button" href="/ad/logout.php"><img src="/ad/images/m_logout.gif" border="0" alt="" />LOGOUT</a> </div></td>



<td align="right"><div align="center"></div></td>
</tr>
</table>
</div>
</div>

</div>

<div align="center"></div>
<script type="text/javascript">var mainMenu = new XulMenu("mainMenu");mainMenu.arrow1 = "images/arrow1.gif";mainMenu.arrow2 = "images/arrow2.gif";mainMenu.init();</script>
 

TahoE

Forum Fiend
Connect.php


<?php
//session_start();
$db_server_name = "localhost";
$db_username = "heaven5_heavens";
$db_password ="EDITED";
$db_database_name = "heaven5_heavensent";

$conexiune = mysql_connect($db_server_name, $db_username, $db_password) or die(mysql_error());

mysql_select_db($db_database_name, $conexiune) or die ("Nu pot conecta la baza de date");

?>
 
Last edited by a moderator:

TahoE

Forum Fiend
Load_content.js (I have much more script, but this is all that relates to the situation at hand I think)

var bustcachevar=1; //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects="";
var rootdomain="http://"+window.location.hostname;
var bustcacheparameter="";

function ajaxpage(url, containerid){
//

var page_request = false;
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest();
else
if (window.ActiveXObject){ // if IE
try {

page_request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
else
return false;
page_request.onreadystatechange=function(){
loadpage(page_request, containerid);
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
page_request.open('GET', url+bustcacheparameter, true);
page_request.send(null);
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
document.getElementById(containerid).innerHTML=page_request.responseText;

}
}

function loadobjs(){
if (!document.getElementById)
return;
for (i=0; i<arguments.length; i++){
var file=arguments;
var fileref="";
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref);
loadedobjects+=file+" "; //Remember this object as being already added to page
}
}
}

function add_employee()
{
var poststr = "time=" + encodeURI(document.getElementById("time").value) +"&name=" + encodeURI(document.getElementById("name").value) + "&title=" + encodeURIComponent(document.getElementById("title").value) + "&description=" + encodeURIComponent(document.getElementById("description").value) + "&Submit=" + encodeURI(document.getElementById("Submit").value);
//alert(poststr);
ajaxpage("/ad/employees/edit_employee.php?"+poststr, "status_emp");
}
 

TahoE

Forum Fiend
edit_employee.php


<?php
include("../../connect.php");
$q = "";
foreach ($_GET as $key=>$value)
{
if($key == 'id')
continue;
if($key == 'Submit' && $value == 'Submit')
break;
else
$q.= $key."='".mysql_real_escape_string(urlencode($value))."', ";
}
$q = rtrim($q, ", ");
//echo "update employees set ".$q." where id=".$_GET['id'];
mysql_query("update employees set ".$q." where id=".$_GET['id']) or die(mysql_error());

if(mysql_affected_rows() > 0)
{
echo "employee updated";
}
else echo "Update Failed !";
?>



Thanks again guys for all your help with this
 

spidEY

Poster Extraordinaire
There you go. :)

<?php
include('../../connect.php');

foreach ($_GET as $key => $value) {
if ($key == 'id') {
continue;
}

elseif ($key == 'Submit') {
break;
}

$data[] = sprintf("'%s' = '%s'", $key, mysql_real_escape_string($value));
}

$join_data = join(',', $data);

$query = sprintf("UPDATE employees SET %s WHERE id = %s", $join_data, $_GET['id']);
mysql_query($query) or die(mysql_error());

if (mysql_affected_rows() > 0) {
echo 'Employee Updated';
} else {
echo 'Update Failed';
}
?>

PHP tags are broken for some reason. :(
 

TahoE

Forum Fiend
hrm... maybe not so smexy after all... edit_employee works... but I still can't add a new one from the add_employee.php page. Still the same SQL syntax error
 

TahoE

Forum Fiend
add_employee.php is the first post I made. Do I need to add something to it? Adjust something? Sorry I am rather new to this and thank God that I have you guys to help me! If this is resolved by Monday I will donate $100.00 to EdgeGamers.... not kidding.


Edit: OR maybe $50.00 to EdgeGamers and $50.00 to whoever finds the solution....
 
Last edited:

spidEY

Poster Extraordinaire
add_employee.php is the first post I made. Do I need to add something to it? Adjust something? Sorry I am rather new to this and thank God that I have you guys to help me! If this is resolved by Monday I will donate $100.00 to EdgeGamers.... not kidding.


Edit: OR maybe $50.00 to EdgeGamers and $50.00 to whoever finds the solution....
Can you please add me on Steam, I see where the problem is, but it would be easier to explain it to you over Steam. ;)
 

spidEY

Poster Extraordinaire
Ok, here is one of many possible solutions to this. The idea here is to have two pages, one for adding employees and other one for updating.

Let's call them:

  • add.php
  • update.php

add.php

Code:
<?php
include_once "../auth.php";
include_once "../include/header_up_pic_emp.php";
include_once "../include/menu.php";
include_once "../connect.php";
?>
<script>
$(document).ready(function() {
    $("form#submit").submit(function() {
 
    var name        	= $('#name').attr('value');
    var title			= $('#title').attr('value');
    var description     = $('#description').attr('value');
	var uploadify 		= $('#uploadify').attr('value');
	var time 			= $('#time').attr('value');
	
	if (name == '' || title == '' || description == '' || uploadify == '')
	{
		$('#error').fadeIn('slow');
		return false;
	}
 
        $.ajax({
            type: "POST",
            url: "form_add.php",
            data: {name: name, title: title, description: description, uploadify: uploadify, time: time},
            success: function() {
			    $('#error').fadeOut('slow');
                $('#sucsses').fadeIn('slow');
            }
        });
    return false;
    });
});
</script>
<h1>Add Staff Member</h1>
<div id="content">
<img src="images/spacer.gif" height="32" width="1" style="float: left"/>

<div class="version">General Information</div>

<div id="status_emp"></div>
<div id="car_details">
<form name="form1" method="post" action="" id="submit">
<table border="0" cellpadding="0" cellspacing="0" class="list" style="padding:20px 0px;">
<tr>
<td width="10"></td>
<td height="30"><label for="name">Name</label></td>
<td><input type="text" name="name" id="name" size="55" value="" /></td>
</tr>
<tr>
<td width="10"></td>
<td height="30"><label for="title">Title</label></td>
<td><input type="text" name="title" id="title" size="55" value="" /></td>
</tr>
<tr>
<td width="10"></td>
<td height="30"><label for="description">Description</label></td>
<td><textarea name="description" cols="100" rows="6" id="description"></textarea> </td>
</tr>
<tr>
<td width="10"></td>
<td height="30"></td>
<td></td>
</tr>
<tr>
<td width="10"></td>
<td height="30"><label for="description">Photos</label></td>
<td><input id="uploadify" name="uploadify" type="file" />
<div id="status"></div> </td>
</tr>
<tr>
<td colspan="3">
<input type="hidden" id="time" name="time" value="<?php echo time(); ?>">
<input name="Submit" type="submit" id="Submit" style="color:#ffffff;background:#545354;padding:4p x 10px;border:0px;font-size:11pt;font-family:Arial;font-weight:bold;margin-left:196px;margin-top:55px" value="Submit" />
<br />
<div id="error" style="display: none;">Make sure you entered all the details correctly</div>
<div id="sucsses" style="display: none;">Employee Added</div>
</td>
</tr>
</table>
</form>
</div>
add.php sends data to form_add.php via AJAX POST request with a little help of jQuery. There is also simple form validation so user doesn't send empty data.

form_add.php


<?php
include('../../connect.php');

foreach ($_POST as $key => $value) {

if ($key == 'Submit') {
break;
}

$data_keys[] = sprintf("%s", $key);
$data_values[] = sprintf("'%s'", mysql_real_escape_string($value));
}

$keys = join(', ', $data_keys);
$values = join(', ', $data_values);

$query = sprintf("INSERT INTO employees (%s) VALUES (%s)", $keys, $values);
mysql_query($query) or die(mysql_error());

if (mysql_affected_rows() > 0) {
echo 'Employee Inserted';
} else {
echo 'Insert Failed';
}
?>


update.php

Code:
<?php
include_once "../auth.php";
include_once "../include/header_up_pic_emp.php";
include_once "../include/menu.php";
include_once "../connect.php";
?>
<script>
$(document).ready(function(){
    $("form#submit").submit(function() {
 
    var name        	= $('#name').attr('value');
    var title			= $('#title').attr('value');
    var description     = $('#description').attr('value');
	var uploadify 		= $('#uploadify').attr('value');
	var id 				= $('#id').attr('value');
	var time 			= $('#time').attr('value');
	
	if (name == '' || title == '' || description == '' || uploadify == '' || id == '')
	{
		$('#error').fadeIn('slow');
		return false;
	}
 
        $.ajax({
            type: "POST",
            url: "form_update.php",
            data: {name: name, title: title, description: description, uploadify: uploadify, id: id, time: time},
            success: function(){
			    $('#error').fadeOut('slow');
                $('#sucsses').fadeIn('slow');
            }
        });
    return false;
    });
});
</script>
<h1>Update Staff Member</h1>
<div id="content">
<img src="images/spacer.gif" height="32" width="1" style="float: left"/>

<div class="version">General Information</div>

<div id="status_emp"></div>
<div id="car_details">
<form name="form1" method="post" action="" id="submit">
<table border="0" cellpadding="0" cellspacing="0" class="list" style="padding:20px 0px;">
<tr>
<td width="10"></td>
<td height="30"><label for="name">ID</label></td>
<td><input type="text" name="id" id="id" size="55" value="" /></td>
</tr>
<tr>
<td width="10"></td>
<td height="30"><label for="name">Name</label></td>
<td><input type="text" name="name" id="name" size="55" value="" /></td>
</tr>
<tr>
<td width="10"></td>
<td height="30"><label for="title">Title</label></td>
<td><input type="text" name="title" id="title" size="55" value="" /></td>
</tr>
<tr>
<td width="10"></td>
<td height="30"><label for="description">Description</label></td>
<td><textarea name="description" cols="100" rows="6" id="description"></textarea> </td>
</tr>
<tr>
<td width="10"></td>
<td height="30"></td>
<td></td>
</tr>
<tr>
<td width="10"></td>
<td height="30"><label for="description">Photos</label></td>
<td><input id="uploadify" name="uploadify" type="file" />
<div id="status"></div> </td>
</tr>
<tr>
<td colspan="3">
<input type="hidden" id="time" name="time" value="<?php echo time(); ?>">
<input name="Submit" type="submit" id="Submit" style="color:#ffffff;background:#545354;padding:4p x 10px;border:0px;font-size:11pt;font-family:Arial;font-weight:bold;margin-left:196px;margin-top:55px" value="Submit" />
<br />
<div id="error" style="display: none;">Make sure you entered all the details correctly</div>
<div id="sucsses" style="display: none;">Employee Updated</div>
</td>
</tr>
</table>
</form>
</div>
form_update.php


<?php
include('../../connect.php');

foreach ($_POST as $key => $value) {
if ($key == 'id') {
$id = $value;
continue;
}

if ($key == 'Submit') {
break;
}

$data[] = sprintf("%s = '%s'", $key, mysql_real_escape_string($value));
}

$join_data = join(', ', $data);

$query = sprintf("UPDATE employees SET %s WHERE id = %s", $join_data, $id);
mysql_query($query) or die(mysql_error());

if (mysql_affected_rows() > 0) {
echo 'Employee Updated';
} else {
echo 'Update Failed';
}
?>


I tested this on my end and it works fine. Find me on Steam so I can help you set this up. :)
 
Top