peter_anderson Posted June 25, 2009 Share Posted June 25, 2009 Hi, Sorry for asking for help again, but sometimes I get a problem which I just can't see why. The below code is NOT performing the query function. Error checking is on, but no errors appear. Here is the process: <?php ini_set('display_errors',1); error_reporting(E_ALL); require_once("aconfig.php"); //get input $event = $_POST['eventname']; $location = $_POST['location']; $date = $_POST['date']; $concess = $_POST['concess']; $adult = $_POST['adult']; $open = $_POST['open']; $id = $_POST['eid']; //start classes $db = new db(); //connect to DB //attempt it $sql = new mysqli(db::$config['host'], db::$config['user'], db::$config['pass'], db::$config['db']); //check for ERR if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } // //perform query $query3 = "UPDATE tickets SET event_name = '$event' SET location = '$location' SET date = '$date' SET adult_price = '$adult' SET concession_price = '$concess' SET open = '$open' WHERE id = $id"; $result = $sql->query($query3); echo '<p>Event updated.</p> <p><a href="index.php">Click here</a> to return to the ACP homepage.</p>'; ?> Here is the form: <h1>MANAGE EVENTS</h1> <p>You can edit an event from below.</p> <p><strong>Select "0" if you want to stop taking orders for tickets, or if the event is over in the "Sell tickets?" field</strong>.</p> <form method="post" action="meprocess.php" name="managevent"> <p>Event Name:<br /> <input type="text" value="'.$row2[event_name].'" name="eventname" /></p> <p>Event Location:<br /> <input type="text" value="'.$row2[location].'" name="location" /></p> <p>Date:<br /> <input type="text" value="'.$row2[date].'" name="date" /><br /> <em>You MUST use the following format, in FULL:<br /> <u>YEAR-MONTH-DAY</u>, Eg: <u>2009-07-15</u></em></p> <p>Adult Price:<br /> <input type="text" value="'.$row2[adult_price].'" name="adult" /></p> <p>Concess Price:<br /> <input type="text" value="'.$row2[concession_price].'" name="concess" /></p> <p>Sell Tickets?<br /> <input type="text" value="'.$row2[open].'" name="open" maxlength="2" /><br /> <input type="hidden" value="'.$eid.'" name="eid" /> <em>Use <strong>1</strong> if you wish to continue selling tickets, or <strong>0</strong> if you do not.</em></p> <p><span style="color: rgb(255, 0, 0);"><strong>WARNING: Submitting will edit this record IMMEDIATELY, and can NOT be undone!</strong></span></p> <p><strong><input type="submit" name="editrecord" value="Edit Event!" /></strong></p> </form> <p> </p> And this is my DB stucture: id event_name location date adult_price concession_price open Why isn't it updating? Link to comment https://forums.phpfreaks.com/topic/163657-solved-update-query-not-performing/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 25, 2009 Share Posted June 25, 2009 The two lines of code that set display_errors/error_reporting only apply to php detected errors (fatal, warnings, notices.) They have nothing to do with SQL errors in a query. Your code has no error checking and error reporting to test if the mysqli_query worked or not and to tell that it did not work when it fails. Any query can fail for several different reasons. Code must at least test the value returned by the query to see if it worked before declaring that it succeeded - if($sql->query($query3)){ // the query worked, output the success message - echo '<p>Event updated.</p> <p><a href="index.php">Click here</a> to return to the ACP homepage.</p>'; } else { // the query failed, for debugging, display the mysqli_error - printf("Errormessage: %s\n", $sql->error); } Finally, your SET syntax is incorrect. Use the SET keyword once, followed by a comma separated list of columns = values, that you want to set. Link to comment https://forums.phpfreaks.com/topic/163657-solved-update-query-not-performing/#findComment-863532 Share on other sites More sharing options...
peter_anderson Posted June 25, 2009 Author Share Posted June 25, 2009 Thanks I had not used the SET query before. Link to comment https://forums.phpfreaks.com/topic/163657-solved-update-query-not-performing/#findComment-863540 Share on other sites More sharing options...
PFMaBiSmAd Posted June 25, 2009 Share Posted June 25, 2009 Actually that is no excuse. The syntax for an UPDATE query is documented in the mysql manual and in countless books, tutorials, and code examples posted all over the Internet. Link to comment https://forums.phpfreaks.com/topic/163657-solved-update-query-not-performing/#findComment-863743 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.