INSERT wil niet werken (Opgelost)
kiwi - 12/06/2010 12:35 (laatste wijziging 12/06/2010 12:40)
Nieuw lid
Beste Sitemasters leden
ik ben hier een scriptje aan het maken dat je muziek met info e.d. kunt toevoegen, maar op 1 of andere raare manier wil dit maar niet werken
de scriptjes:
form:
<?php
if (isset($_POST['submit'])){
if ($_POST['submit'] == 'Add song'){
if (!empty($_POST['title'])){
$title = $_POST['title'];
$title = stripslashes($title);
$title = strip_tags($title);
$title = htmlspecialchars ($title);
if (!empty($_POST['artist'])){
$artist = $_POST['artist'];
$artist = stripslashes($artist);
$artist = strip_tags($artist);
$artist = htmlspecialchars ($artist);
if (!empty($_POST['album'])){
$album = $_POST['album'];
$album = stripslashes($album);
$album = strip_tags($album);
$album = htmlspecialchars ($album);
} else {
$album = 'not assigned';
}
if (!empty($_POST['genre'])){
$genre = $_POST['genre'];
$genre = stripslashes($genre);
$genre = strip_tags($genre);
$genre = htmlspecialchars ($genre);
} else {
$genre = 'not assigned';
}
if (!empty($_POST['youtube'])){
$youtube = $_POST['youtube'];
$youtube = stripslashes($youtube);
$youtube = strip_tags($youtube);
$youtube = htmlspecialchars ($youtube);
} else {
$youtube = 'not assigned';
}
$user = $_SESSION['username'];
if (check_admin($user)){
$admin = 1;
}
echo 'Song added';
$comment = 'not assigned';
$add_by = $user;
add_song($title, $artist, $album, $youtube,$comment,$genre,$add_by,$admin);
} else {
$do = 0;
echo 'Fill in the artist!';
}
} else {
$do = 0;
echo 'fill in a title!';
}
}
} else {
if (login_check()){
echo "
<form action='?site=addsong' method='post'>
<table border='0' cellspacing='4' cellpadding='0'>
<tr>
<td >Title*:</td>
<td><input type='text' name='title' maxlength='50'/></td>
</tr>
<tr>
<td>Artist*:</td>
<td><input type='text' name='artist' maxlength='50'/></td>
</tr>
<tr>
<td>Album:</td>
<td><input type='text' name='album' maxlength='50'/></td>
</tr>
<tr>
<td>Genre:</td>
<td><input type='text' name='genre' maxlength='20'/></td>
</tr>
<tr>
<td>Full youtube link:</td>
<td><input type='text' name='youtube' maxlength='20'/></td>
</tr>
<tr>
<td><input type='submit' name='submit' value='Add song'/></td>
</tr>
</table>
</from>";
} else {
echo 'Your need to be logged in.';
}
}
?>
<?php
if ( isset ( $_POST [ 'submit' ] ) ) { if ( $_POST [ 'submit' ] == 'Add song' ) {
if ( ! empty ( $_POST [ 'title' ] ) ) { $title = $_POST [ 'title' ] ;
if ( ! empty ( $_POST [ 'artist' ] ) ) { $artist = $_POST [ 'artist' ] ;
if ( ! empty ( $_POST [ 'album' ] ) ) { $album = $_POST [ 'album' ] ;
} else {
$album = 'not assigned' ;
}
if ( ! empty ( $_POST [ 'genre' ] ) ) { $genre = $_POST [ 'genre' ] ;
} else {
$genre = 'not assigned' ;
}
if ( ! empty ( $_POST [ 'youtube' ] ) ) { $youtube = $_POST [ 'youtube' ] ;
} else {
$youtube = 'not assigned' ;
}
$user = $_SESSION [ 'username' ] ;
if ( check_admin( $user ) ) {
$admin = 1 ;
}
$comment = 'not assigned' ;
$add_by = $user ;
add_song( $title , $artist , $album , $youtube , $comment , $genre , $add_by , $admin ) ;
} else {
$do = 0 ;
echo 'Fill in the artist!' ; }
} else {
$do = 0 ;
}
}
} else {
if ( login_check( ) ) {
<form action='?site=addsong' method='post'>
<table border='0' cellspacing='4' cellpadding='0'>
<tr>
<td >Title*:</td>
<td><input type='text' name='title' maxlength='50'/></td>
</tr>
<tr>
<td>Artist*:</td>
<td><input type='text' name='artist' maxlength='50'/></td>
</tr>
<tr>
<td>Album:</td>
<td><input type='text' name='album' maxlength='50'/></td>
</tr>
<tr>
<td>Genre:</td>
<td><input type='text' name='genre' maxlength='20'/></td>
</tr>
<tr>
<td>Full youtube link:</td>
<td><input type='text' name='youtube' maxlength='20'/></td>
</tr>
<tr>
<td><input type='submit' name='submit' value='Add song'/></td>
</tr>
</table>
</from>" ;
} else {
echo 'Your need to be logged in.' ; }
}
?>
functie:
function add_song($title, $artist, $album, $youtube,$comment,$genre,$add_by, $admin){
$add_on = date("Y-m-d");
if ($admin == 1){
$confirmed_by = $add_by;
$confirmed_on = $add_on;
$confirmed = '1';
} else {
$confirmed_by = '';
$confirmed_on = '';
$confirmed = '0';
}
echo "<br /><strong>title:</strong>$title <br /><strong>artist:</strong>$artist <br /><strong>Album:</strong>$album <br /><strong>Youtube:</strong>$youtube <br />
<strong>Comment:</strong>$comment <br /><strong>Genre:</strong>$genre <br /><strong>Added on:</strong>$add_on <br /><strong>Added by:</strong>$add_by <br />
<strong>Confirmed by:</strong>$confirmed_by <br /><strong>Confirmed on:</strong>$confirmed_on <br /><strong>Confirmed:</strong>$confirmed";
mysql_query ("INSERT INTO music (id, Title, Artist, Album, youtube, comment, genre, add_by, add_on, confirmd_by, confirmd_on, confirmed)
VALUES ('', $title, $artist, $album, $youtube, $comment, $genre, $add_by, $add_on, '$confirmed_by', '$confirmed_on', $confirmed)");
// @header ("refresh: 1; ?site=home");
}
function add_song( $title , $artist , $album , $youtube , $comment , $genre , $add_by , $admin ) {
if ( $admin == 1 ) {
$confirmed_by = $add_by ;
$confirmed_on = $add_on ;
$confirmed = '1' ;
} else {
$confirmed_by = '' ;
$confirmed_on = '' ;
$confirmed = '0' ;
}
echo "<br /><strong>title:</strong>$title <br /><strong>artist:</strong>$artist <br /><strong>Album:</strong>$album <br /><strong>Youtube:</strong>$youtube <br /> <strong>Comment:</strong>$comment <br /><strong>Genre:</strong>$genre <br /><strong>Added on:</strong>$add_on <br /><strong>Added by:</strong>$add_by <br />
<strong>Confirmed by:</strong>$confirmed_by <br /><strong>Confirmed on:</strong>$confirmed_on <br /><strong>Confirmed:</strong>$confirmed " ;
mysql_query ( "INSERT INTO music (id, Title, Artist, Album, youtube, comment, genre, add_by, add_on, confirmd_by, confirmd_on, confirmed) VALUES ('', $title , $artist , $album , $youtube , $comment , $genre , $add_by , $add_on , '$confirmed_by ', '$confirmed_on ', $confirmed )" ) ;
// @header ("refresh: 1; ?site=home");
}
dit was de output van die echo dat er staat:
title:Meet me halfway
artist:Black eyed peas
Album:meet me halfway
Youtube:not assigned
Comment:not assigned
Genre:not assigned
Added by:kiwi
Added on:2010-06-12
Confirmed by:kiwi
Confirmed on:2010-06-12
Confirmed:1
title: Meet me halfway
artist: Black eyed peas
Album: meet me halfway
Youtube: not assigned
Comment: not assigned
Genre: not assigned
Added by: kiwi
Added on: 2010 - 06 - 12
Confirmed by: kiwi
Confirmed on: 2010 - 06 - 12
Confirmed: 1
Databank:
CREATE TABLE IF NOT EXISTS `music` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`Title` varchar(50) NOT NULL,
`Artist` varchar(50) NOT NULL,
`Album` varchar(50) NOT NULL,
`youtube` varchar(500) NOT NULL,
`comment` text NOT NULL,
`genre` varchar(100) NOT NULL,
`add_by` varchar(50) NOT NULL,
`add_on` date NOT NULL,
`confirmd_by` varchar(50) NOT NULL,
`confirmd_on` date NOT NULL,
`confirmed` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
CREATE TABLE IF NOT EXISTS `music` (
`id` int( 11 ) NOT NULL AUTO_INCREMENT ,
`Title` varchar( 50 ) NOT NULL ,
`Artist` varchar( 50 ) NOT NULL ,
`Album` varchar( 50 ) NOT NULL ,
`youtube` varchar( 500 ) NOT NULL ,
`comment` text NOT NULL ,
`genre` varchar( 100 ) NOT NULL ,
`add_by` varchar( 50 ) NOT NULL ,
`add_on` date NOT NULL ,
`confirmd_by` varchar( 50 ) NOT NULL ,
`confirmd_on` date NOT NULL ,
`confirmed` int( 11 ) NOT NULL DEFAULT '0' ,
PRIMARY KEY ( `id` )
) ENGINE= MyISAM DEFAULT CHARSET= latin1 AUTO_INCREMENT = 4 ;
Ziet er iemand wat ik over het hoofd zie? alvast bedankt
8 antwoorden
Gesponsorde links
dieterke - 12/06/2010 12:39
Nieuw lid
er staat NSERT maar het moet INSERT zijn op r15 van u functie
kiwi - 12/06/2010 12:40
Nieuw lid
Aangepast en nog steeds geen resultaat
dieterke - 12/06/2010 12:44 (laatste wijziging 12/06/2010 12:45)
Nieuw lid
doe dan is even mysql_query("...") or die(mysql_error())
dan kan je zien of er iets fout gaat tijdens het uitvoeren van de query
kiwi - 12/06/2010 12:51
Nieuw lid
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 'me halfway, Black eyed peas, meet me halfway, not assigned, not assigned, not as' at line 2
Dus, het zijn de spaties. hoe los je dit op?
dieterke - 12/06/2010 12:56
Nieuw lid
je moet qoutes er rond zetten, dus:
"INSERT INTO music (id, Title, Artist, Album, youtube, comment, genre, add_by, add_on, confirmd_by, confirmd_on, confirmed)
VALUES ('', '$title', '$artist', '$album', '$youtube', '$comment', '$genre', '$add_by', '$add_on', '$confirmed_by', '$confirmed_on', '$confirmed')");
Bedankt door: kiwi
kiwi - 12/06/2010 13:02
Nieuw lid
Thx,
blijkbaar had ik die perongelijk weg gedaan, bedankt!
Jelmerholland - 12/06/2010 13:27
PHP beginner
En dan is het nog beter als je ze ook escaped:
VALUES('','" . $title . "', '" . $artist . "', etc)
Gesponsorde links
Dit onderwerp is gesloten .