attaboy Posted March 22, 2013 Share Posted March 22, 2013 I have this mysql table called playlist(see attachment) I have a php file called playlist_form.php which i use to generate a form with the contents of the playlist database it looks like this: <?php $con = new mysqli("localhost", "root", "root", "dpsite"); $sql = "SELECT * FROM playlist"; $res = mysqli_query($con,$sql); if($res != FALSE) { $toWrite = ""; while($row = mysqli_fetch_assoc($res)){ $toWrite .= "<form action='process_playlist.php' method='post'>\n"; $toWrite .= "<table>\n"; foreach($row as $key => $value){ $value = "\"".$value."\""; if ($key == "song_title") $toWrite .= "<tr><td>Song Title: </td><td><input type='text' maxlength='30' name=".$key." value=".$value." /></td></tr><br>\n"; if ($key == "artist_name") $toWrite .= "<tr><td>Artist Name: </td><td><input type='text' maxlength='30' name=".$key." value=".$value." /></td></tr><br>\n"; if ($key == "image_path") $toWrite .= "<tr><td>Image: </td><td><input type='text' maxlength='30' name=".$key." value=".$value." /></td></tr><br>\n"; if ($key == "mp3_path") $toWrite .= "<tr><td>mp3: </td><td><input type='text' maxlength='30' name=".$key." value=".$value." /></td></tr><br>\n"; } $toWrite .= "</table>"; } $toWrite .="<p><input type='submit' name='submit' value='Submit' /></p>"; $toWrite .= "</form>"; echo $toWrite; }else{ echo "form was not written!"; } mysqli_close($con); exit; ?> The attachment generated_form shows you the output playlist_form.php generates. To this point everything seems to work well. I can enter new values into any of the songs I want. When I submit this form I want truncate the table then enter the new data but I'm having trouble wrapping my head around this problem. This is what I've done so far: <?php $con = new mysqli("localhost", "root", "root", "dpsite"); if (isset($_POST["song_title"])) $title = $_POST["song_title"]; if (isset($_POST["artist_name"])) $artist = $_POST["artist_name"]; if (isset($_POST["image_path"])) $img = $_POST["image_path"]; if (isset($_POST["mp3_path"])) $mp3 = $_POST["mp3_path"]; //$url = $_POST["url_target"]; $sql = "INSERT INTO playlist(`song_title`,`artist_name`,`image_path`,`mp3_path`) VALUES('$title','$artist','$img','$mp3')"; $res = mysqli_query($con,$sql); while($row = mysqli_fetch_assoc($res)){ foreach($row as $key => $value){ if($title != "") { if($res === TRUE) { echo "data inserted"; }else{ echo "data was not inserted"; } } } } mysqli_close($con); exit; ?> It's very incomplete but If someone can provide a simple example of how to update a table this way I'd be very grateful. thanks Quote Link to comment https://forums.phpfreaks.com/topic/276002-i-need-to-make-multiple-updates-to-a-table-at-once/ Share on other sites More sharing options...
Solution attaboy Posted March 23, 2013 Author Solution Share Posted March 23, 2013 I found it works just fine submitting one at a time. Quote Link to comment https://forums.phpfreaks.com/topic/276002-i-need-to-make-multiple-updates-to-a-table-at-once/#findComment-1420441 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.