logo-dw

Go Back   Dreamweaver Club Forums > Dreamweaver forums > Video Tutorials
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 02-21-2009, 08:26 PM   #1
shazzi2k
 
Join Date: Feb 2009
Posts: 9
Default SQL syntax error

Hi again :S

I am on the tutorial part10 Deleting data. I got to the part where i am testing. I come to hitting the delete button to remove a record and i get this message.

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

Line 1 just has <?php
shazzi2k is offline   Reply With Quote
Old 02-22-2009, 01:44 AM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

there is an error in your SQL mate

you have to read the error messages as they give a good clue

post the SQL
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 02-22-2009, 12:43 PM   #3
shazzi2k
 
Join Date: Feb 2009
Posts: 9
Default

In the SQL database or the script? Sorry only started this the other day by watching your tutorials

<?php

require_once("../Connections/connection.php"); //database connection script



////////////////////////
$data2 = $_POST[ 'data2' ] ;
$data3 = $_POST[ 'data3' ] ;
$data4 = $_POST[ 'data4' ] ;
$Submit = $_POST[ 'Submit'] ;
$del = $_GET [ 'del' ] ;
////////////////////////

if ($del) {
////////////////////////
$query = sprintf ("DELETE FROM table1 where field1_id='del')");
mysql_query ($query) or die (mysql_error () );
////////////////////////
}

///////////////////////

if ($Submit && $data2 && $data3 && $data4) {

////////////////////////

$query = sprintf ("INSERT into table1 (field2, field3, field4) values ('$data2', '$data3', '$data4') ");
mysql_query ($query) or die (mysql_error () );

}elseif ($Submit) {
echo "A required field is empty!" ;

}

////////////////////////
$query = sprintf (" select * FROM table1");
$result = mysql_query ($query);
$row = mysql_fetch_array ($result);
////////////////////////

/*do {
echo $row ['field3']. "<br>";

} while ($row = mysql_fetch_array($result) )
*/
?>


<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ShazCorp Insert data</title>
</head>

<body>
<p>&nbsp;</p>
<form id="form1" name="form1" method="post" action="<?php $_SERVER [ 'PHP_SELF'] ; ?>">
<table width="437" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="146" height="28"><div align="center">data2</div></td>
<td width="145"><div align="center">data3</div></td>
<td width="146"><div align="center">data4</div></td>
</tr>
<tr>
<td height="36"><label>
<input name="data2" type="text" id="data2" />
</label></td>
<td><input name="data3" type="text" id="data3" /></td>
<td><input name="data4" type="text" id="data4" /></td>
</tr>
<tr>
<td height="47" colspan="3"><label>
<div align="center">
<input type="submit" name="Submit" value="Submit" />
<input name="Submit" type="hidden" id="Submit" value="1" />
</div>
</label></td>
</tr>
</table>
<p>&nbsp;</p>
</form>
<p>&nbsp;</p>
<table width="603" border="1" cellspacing="1" cellpadding="1">
<tr>
<td width="99" height="27">ID1</td>
<td width="135">data2</td>
<td width="135">data3</td>
<td width="135">data4</td>
<td width="71">&nbsp;</td>
</tr>
<?php do { ?>
<tr>
<td height="30"><?php echo $row ['field1_id']; ?></td>
<td><?php echo $row ['field2']; ?></td>
<td><?php echo $row ['field3']; ?></td>
<td><?php echo $row ['field4']; ?></td>
<td><input type="button" name="Submit2" value="Delete" onclick="document.location.href='shazcorp.php?del= <?php echo $row ['field1_id']; ?> '" /></td>
</tr>
<?php }while ($row = mysql_fetch_array($result)); ?>
</table>
<label></label>
</body>
</html>
shazzi2k is offline   Reply With Quote
Old 02-22-2009, 01:00 PM   #4
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

you have a rogue ) here

PHP Code:
$query sprintf ("DELETE FROM table1 where field1_id='del')"); 
after 'del'
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:44 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com