spiceydog Posted June 26, 2008 Share Posted June 26, 2008 So I have a php script that tells MySQL to post 30 lines but sometimes I don't want it to post all 30 lines and to stop at say the 15th line depending on something. Here is what it looks like (Yes it's messy but it's what I need): { $query = "INSERT INTO albuminfo(track, details, dl, user, trackn, genre, theyear, art, artist, albumname) VALUES ('$track_1', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_2', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_3', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_4', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_5', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_6', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_7', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_8', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_9', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_10', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_11', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_12', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_13', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_14', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_15', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_16', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_17', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_18', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_19', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_20', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_21', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_22', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_23', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_24', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_25', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_26', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_27', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_28', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_29', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname'), ('$track_30', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname')"; } { mysql_query($query) or die('YOUR FIELD WAS TO LONG!'); exit; } } So what I want to happen is for if track_24 is empty then to stop there and not post anymore lines. Seems simple enough but I just can't figure it out! Please help! Thanks, Spiceydog Quote Link to comment Share on other sites More sharing options...
fenway Posted June 26, 2008 Share Posted June 26, 2008 You have to check in advance. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 <?php $query = "INSERT INTO albuminfo(track,details,dl,user,trackn,genre,theyear,art,artist,albumname) VALUES "; $inserts = array(); for($n=1;$n <= 30;$n++){ $track = ${'track_'.$n}; if(empty($track)) break; $insert[] = "('$track', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname')"; } if(count($inserts)){ $query .= implode(',',$inserts); mysql_query($query) or die('YOUR FIELD WAS TO LONG!'); } ?> Quote Link to comment Share on other sites More sharing options...
spiceydog Posted June 26, 2008 Author Share Posted June 26, 2008 Awesome thanks! ohhh but, I am now getting this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/muzicwar/public_html/postmuzic.php on line 57 and line 57 is: $query = "INSERT INTO albuminfo(track,details,dl,user,trackn,genre,theyear,art,artist,albumname) VALUES "; Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 there is nothing wrong with that line...check the lines before it Quote Link to comment Share on other sites More sharing options...
spiceydog Posted June 26, 2008 Author Share Posted June 26, 2008 Well I looked up and I didn't see anything... Here's the entire script though, maybe you'll see something: <?php if(isset($_POST['btnSubmit'])) { include 'login.php'; $track_1 = trim($_POST['track_1']); $track_2 = trim($_POST['track_2']); $track_3 = trim($_POST['track_3']); $track_4 = trim($_POST['track_4']); $track_5 = trim($_POST['track_5']); $track_6 = trim($_POST['track_6']); $track_7 = trim($_POST['track_7']); $track_8 = trim($_POST['track_8']); $track_9 = trim($_POST['track_9']); $track_10 = trim($_POST['track_10']); $track_11 = trim($_POST['track_11']); $track_12 = trim($_POST['track_12']); $track_13 = trim($_POST['track_13']); $track_14 = trim($_POST['track_14']); $track_15 = trim($_POST['track_15']); $track_16 = trim($_POST['track_16']); $track_17 = trim($_POST['track_17']); $track_18 = trim($_POST['track_18']); $track_19 = trim($_POST['track_19']); $track_20 = trim($_POST['track_20']); $track_21 = trim($_POST['track_21']); $track_22 = trim($_POST['track_22']); $track_23 = trim($_POST['track_23']); $track_24 = trim($_POST['track_24']); $track_25 = trim($_POST['track_25']); $track_26 = trim($_POST['track_26']); $track_27 = trim($_POST['track_27']); $track_28 = trim($_POST['track_28']); $track_29 = trim($_POST['track_29']); $track_30 = trim($_POST['track_30']); $details = trim($_POST['details']); $dl = trim($_POST['dl']); $user = trim($_POST['user']); $trackn = trim($_POST['trackn']); $genre = trim($_POST['genre']); $year = trim($_POST['year']); $art = trim($_POST['art']); $artist = trim($_POST['artist']); $albumname = trim($_POST['albumname']); if ($albumname == '') { exit; } if ($dl == '') { exit; } if ($artist == '') { exit; } $query = "INSERT INTO albuminfo(track,details,dl,user,trackn,genre,theyear,art,artist,albumname) VALUES "; $inserts = array(); for($n=1;$n <= 30;$n++){ $track = ${'track_'.$n}; if(empty($track)) break; $insert[] = "('$track', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname')"; } if(count($inserts)){ $query .= implode(',',$inserts); mysql_query($query) or die('YOUR FIELD WAS TO LONG!'); } ?> <html> <script language="Javascript" type="text/javascript"> <!-- function addField(area,field,limit) { if(!document.getElementById) return; var field_area = document.getElementById(area); var all_inputs = field_area.getElementsByTagName("input"); var last_item = all_inputs.length - 1; var last = all_inputs[last_item].id; var count = Number(last.split("_")[1]) + 1; if(count > limit && limit > 30) return; if(document.createElement) { var li = document.createElement("li"); var input = document.createElement("input"); input.id = field+count; input.name = field+count; input.type = "text"; li.appendChild(input); field_area.appendChild(li); } else { field_area.innerHTML += "<li><input name='"+(field+count)+"' id='"+(field+count)+"' type='text' /></li>"; } } //--> </script> <body> <form name="albuminfo" method="POST"> Track: <ol id="tracks_area"> <li><input type="text" name="track_1" id="track_1" /></li> <li><input type="text" name="track_2" id="track_2" /></li> <li><input type="text" name="track_3" id="track_3" /></li> <li><input type="text" name="track_4" id="track_4" /></li> <li><input type="text" name="track_5" id="track_5" /></li> </ol> <input type="button" value="Add track Field" onclick="addField('tracks_area','track_',10);" /> Artist Name: <input name="artist" type="text" size="20" maxlength="50"> Album Name: <input name="albumname" type="text" size="20" maxlength="50"> Length: <input name="length" type="text" size="6" maxlength="6"> Details: <input name="details" type="text" size="20" maxlength="200"> Download Links: <input name="dl" type="text" size="20" maxlength="75"> Your Username: <input name="user" type="text" size="20" maxlength="50"> Genre: <select name="genre"> <option value="" selected>--Select Your Genre--</option> <option value="metal">Metal</option> <option value="rock">Rock</option> <option value="raphop">Rap/Hip-Hop</option> <option value="country">Country</option> <option value="folk">Folk</option> <option value="classical">Classical</option> <option value="techtrance">Techno/Trance</option> </select> Year: <input name="theyear" type="text" size="4" maxlength="4"> Artwork: <input name="art" type="text" size="20" maxlength="50"> <input name="btnSubmit" type="submit" value="Post Muzic"> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 you were missing a close brace at the end...but your code can be WAY shorter with this: <?php if(isset($_POST['btnSubmit'])){ include 'login.php'; $details = mysql_real_escape_string(trim($_POST['details'])); $dl = mysql_real_escape_string(trim($_POST['dl'])); $user = mysql_real_escape_string(trim($_POST['user'])); $trackn = mysql_real_escape_string(trim($_POST['trackn'])); $genre = mysql_real_escape_string(trim($_POST['genre'])); $year = mysql_real_escape_string(trim($_POST['year'])); $art = mysql_real_escape_string(trim($_POST['art'])); $artist = mysql_real_escape_string(trim($_POST['artist'])); $albumname = mysql_real_escape_string(trim($_POST['albumname'])); if ($albumname == '') die("Albumn is empty"); if ($dl == '') die("DL is empty"); if ($artist == '') die("Artist is empty"); $query = "INSERT INTO albuminfo(track,details,dl,user,trackn,genre,theyear,art,artist,albumname) VALUES "; $inserts = array(); for($n=1;$n <= 30;$n++){ $track = mysql_real_escape_string($_POST['track_'.$n]); if(empty($track)) break; $insert[] = "('$track', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname')"; } if(count($inserts)){ $query .= implode(',',$inserts); mysql_query($query) or die('YOUR FIELD WAS TO LONG!'); } } ?> Quote Link to comment Share on other sites More sharing options...
spiceydog Posted June 26, 2008 Author Share Posted June 26, 2008 ahh man i feel like i'm getting really close to fixing it! but now I am getting the error: Parse error: syntax error, unexpected T_VARIABLE in /home/muzicwar/public_html/postmuzic.php on line 4 Line 4 is: $details = mysql_real_escape_string(trim($_POST['details'])); And I copied and pasted what you gave me exactly rhodesa Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 if you comment out the include before it, does the error go away? if so, what is the code for login.php? Quote Link to comment Share on other sites More sharing options...
spiceydog Posted June 26, 2008 Author Share Posted June 26, 2008 If I comment out login.php then nothing will work because all that is is the script that logs me into my database. here it is <?php $dbhost = 'localhost'; $dbuser = 'muzicwar_user; $dbpass = '123456'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('LOGIN ERROR!!!!!!'); $dbname = 'muzicwar_muzic'; mysql_select_db($dbname) or die ('DATABASE SELECTION ERROR!!!!!!!!'); ?> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 you are missing a single quote after the username Quote Link to comment Share on other sites More sharing options...
spiceydog Posted June 26, 2008 Author Share Posted June 26, 2008 eh I copied it wrong. and I commented it out and i got the same error. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 well...i don't get any errors :/ Quote Link to comment Share on other sites More sharing options...
spiceydog Posted June 26, 2008 Author Share Posted June 26, 2008 oh man I'm so confused now.... I was looking at other scripts of mine and I decided to switch the "include" line with the "if (isset(" button and now it's saying: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/muzicwar/public_html/postmuzic.php on line 2 Line 2 is: include 'input.php'; Here is my entire script again... this is so weird: <?php include 'inputt.php'; if(isset($_POST['btnSubmit'])) { $details = mysql_real_escape_string(trim($_POST['details'])); $dl = mysql_real_escape_string(trim($_POST['dl'])); $user = mysql_real_escape_string(trim($_POST['user'])); $trackn = mysql_real_escape_string(trim($_POST['trackn'])); $genre = mysql_real_escape_string(trim($_POST['genre'])); $year = mysql_real_escape_string(trim($_POST['year'])); $art = mysql_real_escape_string(trim($_POST['art'])); $artist = mysql_real_escape_string(trim($_POST['artist'])); $albumname = mysql_real_escape_string(trim($_POST['albumname'])); if ($albumname == '') die("Albumn is empty"); if ($dl == '') die("DL is empty"); if ($artist == '') die("Artist is empty"); $query = "INSERT INTO albuminfo(track,details,dl,user,trackn,genre,theyear,art,artist,albumname) VALUES "; $inserts = array(); for($n=1;$n <= 30;$n++){ $track = mysql_real_escape_string($_POST['track_'.$n]); if(empty($track)) break; $insert[] = "('$track', '$details', '$dl', '$user', '$trackn', '$genre', '$theyear', '$art', '$artist', '$albumname')"; } if(count($inserts)){ $query .= implode(',',$inserts); mysql_query($query) or die('YOUR FIELD WAS TO LONG!'); } } ?> <html> <script language="Javascript" type="text/javascript"> <!-- function addField(area,field,limit) { if(!document.getElementById) return; var field_area = document.getElementById(area); var all_inputs = field_area.getElementsByTagName("input"); var last_item = all_inputs.length - 1; var last = all_inputs[last_item].id; var count = Number(last.split("_")) + 1; if(count > limit && limit > 30) return; if(document.createElement) { var li = document.createElement("li"); var input = document.createElement("input"); input.id = field+count; input.name = field+count; input.type = "text"; li.appendChild(input); field_area.appendChild(li); } else { field_area.innerHTML += "<li><input name='"+(field+count)+"' id='"+(field+count)+"' type='text' /></li>"; } } //--> </script> <body> <form name="albuminfo" method="POST"> Track: <ol id="tracks_area"> <li><input type="text" name="track_1" id="track_1" /></li> <li><input type="text" name="track_2" id="track_2" /></li> <li><input type="text" name="track_3" id="track_3" /></li> <li><input type="text" name="track_4" id="track_4" /></li> <li><input type="text" name="track_5" id="track_5" /></li> </ol> <input type="button" value="Add track Field" onclick="addField('tracks_area','track_',10);" /> Artist Name: <input name="artist" type="text" size="20" maxlength="50"> Album Name: <input name="albumname" type="text" size="20" maxlength="50"> Length: <input name="length" type="text" size="6" maxlength="6"> Details: <input name="details" type="text" size="20" maxlength="200"> Download Links: <input name="dl" type="text" size="20" maxlength="75"> Your Username: <input name="user" type="text" size="20" maxlength="50"> Genre: <select name="genre"> <option value="" selected>--Select Your Genre--</option> <option value="metal">Metal</option> <option value="rock">Rock</option> <option value="raphop">Rap/Hip-Hop</option> <option value="country">Country</option> <option value="folk">Folk</option> <option value="classical">Classical</option> <option value="techtrance">Techno/Trance</option> </select> Year: <input name="theyear" type="text" size="4" maxlength="4"> Artwork: <input name="art" type="text" size="20" maxlength="50"> <input name="btnSubmit" type="submit" value="Post Muzic"> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 try using this instead: require('inputt.php'); Quote Link to comment Share on other sites More sharing options...
spiceydog Posted June 26, 2008 Author Share Posted June 26, 2008 sadly... still no... Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/muzicwar/public_html/postmuzic.php on line 2 Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 that makes no sense...and the code we've been working on is that file: /home/muzicwar/public_html/postmuzic.php ??? commend out that line and see if the error changes (i know the script won't work, but just try to see what the error changes to) Quote Link to comment Share on other sites More sharing options...
spiceydog Posted June 26, 2008 Author Share Posted June 26, 2008 alright commented that out and i get Parse error: syntax error, unexpected T_VARIABLE in /home/muzicwar/public_html/postmuzic.php on line 6 Line 6 is: $details = mysql_real_escape_string(trim($_POST['details'])); Quote Link to comment Share on other sites More sharing options...
fenway Posted June 26, 2008 Share Posted June 26, 2008 This is a PHP issue.... don't double-post. Quote Link to comment Share on other sites More sharing options...
spiceydog Posted June 26, 2008 Author Share Posted June 26, 2008 fenway what in the world are you talking about? this entire WEBSITE is for php (phpfreaks.com) $details = mysql_real_escape_string(trim($_POST['details'])) ^ that was in my last post... it says "mysql" and therefore I assume that it would go in the mysql section of this php devoted website. Also you mentioned double posting? I simply created a new topic because as you can see, this one has completely diverged off of the original topic which regarded something about a "MySQL End Tag" Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 fenway is right...this should be in PHP can you email me the actual postmuzic.php file? there is something weird in it... Quote Link to comment Share on other sites More sharing options...
spiceydog Posted June 26, 2008 Author Share Posted June 26, 2008 ok I emailed u the 2 files! did u get them? ps. thanks for all the help! Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 the file had weird characters in it where the spaces should have been...file sent back ..input.php was fine.. Quote Link to comment Share on other sites More sharing options...
fenway Posted June 26, 2008 Share Posted June 26, 2008 Also you mentioned double posting? I simply created a new topic because as you can see, this one has completely diverged off of the original topic which regarded something about a "MySQL End Tag" Yes, but it makes no sense without reference to this thread.... Quote Link to comment 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.