0

I checked source code ten times but can't find anymistake,for some reason i remember it was working now it doesn't work,i didn't change anything elsewhere to blame everything wors except update,when iclick Edit button it gives error,meaning that there was something wrong with query.

<?php 
$editId = $_GET['id'];
$event = mysqli_query($con, "SELECT * FROM events WHERE id = '$editId'")->fetch_assoc();
if(isset($_POST['submit'])){
$name = $_POST['name'];
$description = $_POST['description'];
$date = $_POST['date'];
$artists = $_POST['artists'];
$tickets = $_POST['tickets'];
$updateQuery = mysqli_query($con, "UPDATE events SET name='$name',description='$description',date='$date', artists='$artists', ticket='$tickets' WHERE id = '$editId'");
}
?>
<?php if(isset($updateQuery) && $updateQuery): ?>
<div class="alert alert-success">
<strong>Successfully Edited</strong>
</div>
<?php endif; ?>
<?php if(isset($updateQuery) && !$updateQuery): ?>
<div class="alert alert-danger">
<strong>Error</strong>
</div>
<?php endif; ?>
<form action="<?php echo $app_host; ?>/admin/?page=editevent&id=<?php echo $editId; ?>" method="post">
<div class="form-group">
<label for="name">Name</label>
<input value="<?php echo $event['name']; ?>" required="true" type="text" class="form-control" id="name" name="name">
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea class="form-control" id="description" name="description"><?php echo $event['description'];; ?></textarea>
</div>
<div class="form-group">
<label for="date">Date</label>
<input value="<?php echo $event['date']; ?>" required="true" type="text" class="form-control" id="date" name="date">
</div>
<div class="form-group">
<label for="artists">Artists</label>
<input value="<?php echo $event['artists']; ?>" required="true" type="text" class="form-control" id="artists" name="artists" data-role="tagsinput">
</div>
<div class="form-group">
<label for="tickets">Ticket Link</label>
<input value="<?php echo $event['tickets']; ?>" required="true" type="text" class="form-control" id="tickets" name="tickets" data-role="tagsinput">
</div>
<input name="submit" type="submit" class="btn btn-default" value="Edit Event" />
</form>
  • which error gives you ? – Phoenix404 Feb 03 '17 at 21:09
  • 2
    What error does it get? Use `die (mysqli_error($con));` to see the SQL error message. – Barmar Feb 03 '17 at 21:09
  • Since you've switched to mysqli, you should also fix your code to use prepared statements instead of variable substitution. That might solve the problem if the values contain quotes. – Barmar Feb 03 '17 at 21:10
  • Have you defined con variable for the mysql connection ? – Ankit Jain Feb 03 '17 at 21:10
  • Can you access your database from a control panel such as phpMyAdmin? If so, try echoing your query to the page and then pasting it into the control panel. Does it give errors there? – tjfo Feb 03 '17 at 21:28
  • Yes guys i did everything you said,but it's done with routes okay i will check mysqli_erorr –  Feb 03 '17 at 21:51
  • Unknown Column 'ticket' in field list –  Feb 03 '17 at 21:54
  • Thank You bro Write Your answer as offical answer and i Will Up you,Barmar, erorr was in 'ticket' i missed 's' damn what a silly mistake –  Feb 03 '17 at 21:55

1 Answers1

0

Okay,so you declare a variable ,

$tickets = $_POST['tickets'];

and than you say

$updateQuery = mysqli_query($con, "UPDATE events SET name='$name',description='$description',date='$date', artists='$artists', ticket='$tickets' WHERE id = '$editId'");
}

and solution is simple:

$updateQuery = mysqli_query($con, "UPDATE events SET name='$name',description='$description',date='$date', artists='$artists', tickets='$tickets' WHERE id = '$editId'");
}

simply changed 'ticket' in query to 'tickets'.

DummyTarget
  • 112
  • 1
  • 2
  • 10