searls03 Posted March 12, 2011 Share Posted March 12, 2011 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 ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 12, 2011 Share Posted March 12, 2011 Echo your query string. It's nearly impossible to tell what's wrong otherwise. Quote Link to comment Share on other sites More sharing options...
teng84 Posted March 12, 2011 Share Posted March 12, 2011 echo your query Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 12, 2011 Author Share Posted March 12, 2011 sorry, how do I echo the query, I am a bit new to this stuff. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 12, 2011 Share Posted March 12, 2011 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 Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 12, 2011 Author Share Posted March 12, 2011 here error: Fatal error: Call to undefined function myslq_error() in /home/a6254834/public_html/eventup.php on line 40 Quote Link to comment Share on other sites More sharing options...
mattal999 Posted March 12, 2011 Share Posted March 12, 2011 You have misspelt mysql_error(). Fix it, and post the error. Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 12, 2011 Author Share Posted March 12, 2011 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 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 12, 2011 Share Posted March 12, 2011 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. Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 12, 2011 Author Share Posted March 12, 2011 What do you mean they have no value? If you mean where values come from, there is a form on another page that (should) populates the values Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 12, 2011 Share Posted March 12, 2011 Look at the query string that was echoed. Maybe it's intentional, but most of the variables hold no value, apparently. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 12, 2011 Share Posted March 12, 2011 If you look at the code just above the query, the variables are set from the array $row. Where is that array populated? I don't see that in the code you posted. Ken Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 13, 2011 Author Share Posted March 13, 2011 I don't know why I didn't see that.... I should have noticed that. Thanks!!!!!!!!!!!! Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 13, 2011 Author Share Posted March 13, 2011 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 ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 13, 2011 Share Posted March 13, 2011 OK, once again echo the query string and let's see what it looks like. Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 13, 2011 Author Share Posted March 13, 2011 I never took it it out................Correct? the onlythings I took out were some fields..... Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 13, 2011 Share Posted March 13, 2011 Now it only echos if the query fails, which doesn't seem to be happening any longer, so you'll need to temporarily put an echo $q; in there right after the query is executed. Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 13, 2011 Author Share Posted March 13, 2011 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 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 13, 2011 Share Posted March 13, 2011 Do you have a record in your database with the an id of 7? Ken Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 13, 2011 Share Posted March 13, 2011 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. Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 13, 2011 Author Share Posted March 13, 2011 Oh...ok, i see what is happening, it is taking the session id, which is the user id.....this is my userid. how can I fix this? Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 13, 2011 Author Share Posted March 13, 2011 I can't seem to get it to post to the right id....................do I need to change session variable? since that is what it is pulling? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 13, 2011 Share Posted March 13, 2011 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. Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 13, 2011 Author Share Posted March 13, 2011 so make a hidden field called id in the form? Or should I rename it like eventid? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 13, 2011 Share Posted March 13, 2011 Give it a name that's identifiable, and doesn't conflict with any of the other field names. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.