Jump to content

error message


searls03

Recommended Posts

why am I getting 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 '7'' at line 1:

<?php
session_start(); // Must start session first thing
/* 
Created By Adam Khoury @ www.flashbuilding.com 
-----------------------June 20, 2008----------------------- 
*/
// Here we run a login check
if (!isset($_SESSION['id'])) { 
   echo 'Please <a href="login.php">log in</a> to access your account';
   exit(); 
}
//Connect to the database through our include 
include_once "connect_to_mysql.php";
// Place Session variable 'id' into local variable
$id=$_SESSION['id'];
// Process the form if it is submitted
if ($_POST['startdate']) {
    $event = $_POST['event'];
    $startdate = $_POST['startdate'];
    $enddate = $_POST['enddate'];
    $description = $_POST['description'];
   $subevent1 = $row['subevent1'];
$subevent2 = $row['subevent2'];
$subevent3 = $row['subevent3'];
$subevent4 = $row['subevent4'];
$subevent5 = $row['subevent5'];
$subevent6 = $row['subevent6'];
$subevent7 = $row['subevent7'];
$subevent8 = $row['subevent8'];
$title1 = $row['title1'];
$title2 = $row['title2'];
$title3 = $row['title3'];
$title4 = $row['title4'];
$title5 = $row['title5'];
$title6 = $row['title6'];
$title7 = $row['title7'];
$title8 = $row['title8'];
$price1 = $row['price1'];
$price2 = $row['price2'];
$price3 = $row['price3'];
$price4 = $row['price4'];
$price5 = $row['price5'];
$price6 = $row['price6'];
$price7 = $row['price7'];
$price8 = $row['price8'];
    $sql = mysql_query("UPDATE Registration SET event='$event', startdate='$startdate', enddate='$enddate', description='$description', subevent1='$subevent1', subevent2='$subevent2', subevent3='$subevent3', subevent4=$subevent4', subevent5='$subevent5', subevent6='$subevent6', subevent7='$subevent7', subevent8='$subevent8', title1='$title1', title2='$title2', title3='$title3', title4='$title4', title5='$title5', title6='$title6', title7='$title7', title8='$title8', price1='$price1', price2='$price2', price3='$price3', price4='$price4', price5='$price5', price6='$price6', price7='$price7', price8='$price8', id='$id'") or die (mysql_error());

printf("Records updated: %d\n", mysql_affected_rows());

exit();
} // close if post
?>

Link to comment
Share on other sites

Change

<?php
$sql = mysql_query("UPDATE Registration SET event='$event', startdate='$startdate', enddate='$enddate', description='$description', subevent1='$subevent1', subevent2='$subevent2', subevent3='$subevent3', subevent4=$subevent4', subevent5='$subevent5', subevent6='$subevent6', subevent7='$subevent7', subevent8='$subevent8', title1='$title1', title2='$title2', title3='$title3', title4='$title4', title5='$title5', title6='$title6', title7='$title7', title8='$title8', price1='$price1', price2='$price2', price3='$price3', price4='$price4', price5='$price5', price6='$price6', price7='$price7', price8='$price8', id='$id'") or die (mysql_error());
?>

to

<?php
$q =  "UPDATE Registration SET event='$event', startdate='$startdate', enddate='$enddate', description='$description', subevent1='$subevent1', subevent2='$subevent2', subevent3='$subevent3', subevent4=$subevent4', subevent5='$subevent5', subevent6='$subevent6', subevent7='$subevent7', subevent8='$subevent8', title1='$title1', title2='$title2', title3='$title3', title4='$title4', title5='$title5', title6='$title6', title7='$title7', title8='$title8', price1='$price1', price2='$price2', price3='$price3', price4='$price4', price5='$price5', price6='$price6', price7='$price7', price8='$price8', id='$id'";
$sql = mysql_query($q) or die("Problem with the query: $q<br>" . myslq_error());
?>

and post what is displayed.

 

BTW, this query as it stands will update ALL the events in your DB with theses values, since you don't have a "where" clause to tell mysql which record to update.

 

Ken

 

Link to comment
Share on other sites

now this is what i got:

Problem with the query: UPDATE Registration SET event='akajl', startdate='jlkjkl', enddate='jkljakljlk', description='', subevent1='', subevent2='', subevent3='', subevent4=', subevent5='', subevent6='', subevent7='', subevent8='', title1='', title2='', title3='', title4='', title5='', title6='', title7='', title8='', price1='', price2='', price3='', price4='', price5='', price6='', price7='', price8='', id='7'

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 '7'' at line 1

Link to comment
Share on other sites

Notice how none of your variables have values? Where are they supposed to come from? You need to investigate that. Also, is `id` the table's primary key index, and did you leave out a WHERE in the query string? As it stands at the moment, if that query actually runs, it will update every record in the table with empty strings in those fields.

Link to comment
Share on other sites

alright now I got the error to go away by taking away some things, but now it says 0 records updated.  help me:

<?php
session_start(); // Must start session first thing
/* 
Created By Adam Khoury @ www.flashbuilding.com 
-----------------------June 20, 2008----------------------- 
*/
// Here we run a login check
if (!isset($_SESSION['id'])) { 
   echo 'Please <a href="login.php">log in</a> to access your account';
   exit(); 
}
//Connect to the database through our include 
include_once "connect_to_mysql.php";
// Place Session variable 'id' into local variable
$id=$_SESSION['id'];
// Process the form if it is submitted
if ($_POST['event']) {
    $event = $_POST['event'];
    $startdate = $_POST['startdate'];
    $enddate = $_POST['enddate'];
    $description = $_POST['description'];
   $subevent1 = $_POST['subevent1'];
   $location = $_POST['location'];
   $q =  "UPDATE Registration SET event='$event', startdate='$startdate', enddate='$enddate', description='$description', location=
   '$location' where id='$id'";
$sql = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());

printf("Records updated: %d\n", mysql_affected_rows());

echo mysql_error();
exit();
} // close if post
?>

Link to comment
Share on other sites

like this?

  $q =  "UPDATE Registration SET event='$event', startdate='$startdate', enddate='$enddate', description='$description', location=
   '$location' where id='$id'";
$sql = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
echo $q;
printf("Records updated: %d\n", mysql_affected_rows());

 

if that is it, this is what I get:

UPDATE Registration SET event='hjjg', startdate='fdgfd', enddate='dfgdfg', description='type in content herefgdfgd', location= 'fdgfdgfh' where id='7'Records updated: 0

Link to comment
Share on other sites

You need to pass the pk index of the record to the UPDATE query from the form that is used to edit the record, either through a hidden form field or a $_SESSION var. You should use  $_SESSION['id'] to verify that the user editing the record owns it, or is authorized to edit it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.