Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,193,944 members, 7,952,814 topics. Date: Thursday, 19 September 2024 at 03:43 AM

Mysql Dynamic Update - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Mysql Dynamic Update (520 Views)

I Can Build And Manage Your Static/cms (dynamic) And E-commerce Websites / Register For The Building Dynamic Web Applications Part 1 - Free Online Training / The Difference Between Dynamic Ip And Static Ip (2) (3) (4)

(1) (Reply) (Go Down)

Mysql Dynamic Update by ivcraig(m): 1:26am On Nov 21, 2015
I have a challenge with updating records in my mysql database. It only updates when I put in the row id manually but when I put the dynamic variable ($newid=&_get[`id:]) it doesn't work. Somehow the variable becomes undeclared at (if(isset($_get[`submit`] )) { //update code}.
Gurus, help me out. Thanks.
Re: Mysql Dynamic Update by Adesege(m): 7:25am On Nov 21, 2015
Hello,

Can you post the code here so I can have a look at it??

Also, is the id an index?

It may also be a typo on your part. Pasting the code here will lead me to the right direction.

Best regards,
Adesege
Re: Mysql Dynamic Update by ivcraig(m): 9:14am On Nov 21, 2015
chars($_SERVER["PHP_SELF"]);?>">
<?php
$ID= $_GET['id'];
$query = "SELECT * FROM music WHERE musicID = $ID";
$result= mysqli_query($connection, $query);
$row = mysqli_fetch_array($result);
$artID = $row['IDartiste'];
$query2 = mysqli_query($connection,"SELECT music.*, artiste.* FROM music INNER JOIN artiste ON music.IDartiste=artiste.artisteID WHERE artiste.artisteID = $artID"wink;
$row2 = mysqli_fetch_array($query2);
?>
<!-- Artiste name field--> <div class="form-group">
<label for="topic" style="color: #55AAFF">Artiste name:</label>
<input type="text" class="form-control" name="artisteName" value="<?php echo $row2['artisteName'];?>" required autofocus>

<label for="sel1" style="color: #55AAFF">Artiste's continent:</label>
<select class="form-control" id="sel1" name="continent">
<option><?php echo $row2['continent'];?></option>
<option>African</option>
<option>English</option>
<option>European</option>
<option>Asian</option>
</select>
<label for="topic" style="color: #55AAFF">Artiste nationality:</label>
<input type="text" class="form-control" name="nationality" value="<?php echo $row2['nationality'];?>" required autofocus>
</div>

<!-- Article topic field--> <div class="form-group">
<label for="topic" style="color: #55AAFF">Music title:</label>
<input type="text" class="form-control" name="title" value="<?php echo $row['musicTitle'];?>" autofocus>
</div>

<!--Article textarea--> <div class="form-group">
<label for="body" style="color: #55AAFF">Content (text):</label>
<textarea name="article" class="form-control"><?php echo $row['musicArticle'];?>
</textarea>
</div>

<!-- Upload image start--> <div class="col-ms-6 col-xs-12" >
<div class="panel panel-default">
<div class="panel-heading" style="color: #55AAFF">Upload Image</div>
<div class="panel-body">
<iframe src="fileupload.php" width="100%" style="border:none"></iframe>
</div>
</div>
</div>
<!--Image link field--> <div class="form-group">
<label for="image_link" style="color: #55AAFF">Input image link: </label>
<input type="text" name="image" value="<?php echo $row2['artistePhoto'];?>" class="form-control"/>
</div>

<!-- Upload music start--> <div class="col-ms-6 col-xs-12" >
<div class="panel panel-default">
<div class="panel-heading" style="color: #55AAFF">Upload Music</div>
<div class="panel-body">
<iframe src="music_file_upload.php" width="100%" style="border:none"></iframe>
</div>
</div>
</div>

<!--Music link field--> <div class="form-group">
<label for="music_link" style="color: #55AAFF">Input music link: </label>
<input type="text" name="file" class="form-control" value="<?php echo $row['musicFile'];?>"/>
</div>
<center>....<button type="submit" class="btn btn-default" id="btnsubmit" name="btnsubmit" style="color: #55AAFF">Update</button>....</center>


<br />
</form>
</div>

<?php
if(isset($_GET['btnsubmit']
date_default_timezone_set('Africa/Lagos');

$setdate= date('Y-m-d-h-m-s');

$date= strftime($setdate);

$time= strftime('%X');

$artiste = $_GET["artisteName"];

$title = $_GET["title"];

$article = $_GET["article"];

$artisteImage = $_GET["image"];

$musicFile = $_GET["file"];

$artisteContinent = $_GET['continent'];

$nationality = $_GET["nationality"];

$sql_artiste = "UPDATE kingdomjoy.artiste SET artisteName = '$artiste', nationality = '$nationality' , continent = '$artisteContinent' WHERE artiste.artisteID='$artID'";
$artisteupdate = $connection->query($sql_artiste);
if ($artisteupdate === TRUE) {
echo"<script>swal('Success! artiste library updated')</script>";
} else {
echo "Error: " . die(mysqli_error($connection));
}
$sql_music = "UPDATE music SET musicTitle = '$title', musicFile = '$musicFile', musicPhoto = '$artisteImage', musicArticle = '$article', entryDate = '$date' WHERE musicID = $ID";
$musicupdate = $connection->query($sql_music);
if ($musicupdate === TRUE) {
echo"<script>swal('Success! music library updated')</script>";
} else {
echo "Error: " . die(mysqli_error($connection));
}
}
?>
</div>
Re: Mysql Dynamic Update by Adesege(m): 10:22am On Nov 21, 2015
You've pasted more than one query that requires id but I will assume it's the first query.

Since you are using a get variable, does your address have a query string??

Something like www.domain.com/page.php?id=20

Regards
Re: Mysql Dynamic Update by ivcraig(m): 11:41am On Nov 21, 2015
I've updated the script. Yes to your question, I have a query string in my address. The first MySQL query is matching a Where clause with '$artID' and the second is matching the variable '$ID'
Re: Mysql Dynamic Update by ivcraig(m): 6:43pm On Nov 23, 2015
Problem solved. I had to restart my local server where my app was running. I also had to use prepared statement.

(1) (Reply)

Urgent!!! Only For People Residing In Ilorin / Can Someone Please Review This Site / Learn Software Programming Today And Become Highly Sought After

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 23
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.