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
https://forums.phpfreaks.com/topic/230433-error-message/
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
https://forums.phpfreaks.com/topic/230433-error-message/#findComment-1186671
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
https://forums.phpfreaks.com/topic/230433-error-message/#findComment-1186677
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
https://forums.phpfreaks.com/topic/230433-error-message/#findComment-1186746
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
https://forums.phpfreaks.com/topic/230433-error-message/#findComment-1186824
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
https://forums.phpfreaks.com/topic/230433-error-message/#findComment-1186875
Share on other sites

Are those values what you'd expect them to be?

 

Is there a record in the table with id = 7 ?

 

Does a record already exist with all of those same values? If it does, mysql_affected_rows() will show 0 in that case.

Link to comment
https://forums.phpfreaks.com/topic/230433-error-message/#findComment-1186878
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
https://forums.phpfreaks.com/topic/230433-error-message/#findComment-1186985
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.