timecut Posted March 9, 2007 Share Posted March 9, 2007 hi guys, need bit of help with my script if u can. i've a db "album" with a field 'band' and more fields for details bout every single album of this band. in my index page i have a form that show all the bands in my db and, between brackets, how many album each. the user can select the band clicking the name in the form and i linked it to a band.php page where i receive the name of the band select with the method post. it's workinf if the band has a name with no blank spaces (ex. ministry) but not if the name is composed (ex.nine inch nails). well, i echoed the var that i post and it came out just 'nine' (for the previous example). anyone has got any idea of what's goin' on? i'm not so good in php so maybe is a basic error!!! thanx a lot ??? Link to comment https://forums.phpfreaks.com/topic/41963-form-with-post-and-blank-spaces/ Share on other sites More sharing options...
redarrow Posted March 9, 2007 Share Posted March 9, 2007 when the band enter there name you need to use the command trim on the varable so that there no spaces to search the database correctly ok. Link to comment https://forums.phpfreaks.com/topic/41963-form-with-post-and-blank-spaces/#findComment-203456 Share on other sites More sharing options...
timecut Posted March 9, 2007 Author Share Posted March 9, 2007 yeah, know what u mean but i'd like to keep the form showing the correct name of the band. if i trim the name before storing it into the db, then the form is gonna show it all together (ex.nineinchnails). thanx anyway for ur kindness. do u know any other way? Link to comment https://forums.phpfreaks.com/topic/41963-form-with-post-and-blank-spaces/#findComment-203459 Share on other sites More sharing options...
redarrow Posted March 9, 2007 Share Posted March 9, 2007 Use the id in the drop down box then call the band names via there id in the search. Link to comment https://forums.phpfreaks.com/topic/41963-form-with-post-and-blank-spaces/#findComment-203475 Share on other sites More sharing options...
Glyde Posted March 9, 2007 Share Posted March 9, 2007 As suggested, you can use the ID. Also, ensure that in your HTML, there are double quotes around the value attribute. So, instead of this: value=Nine Inch Nails It should be this: value="Nine Inch Nails" Link to comment https://forums.phpfreaks.com/topic/41963-form-with-post-and-blank-spaces/#findComment-203486 Share on other sites More sharing options...
timecut Posted March 9, 2007 Author Share Posted March 9, 2007 thanx a lot guys but the id is more related to the albums. the band name is a field that is repeated in the database: i can have 2 albums by "nine inch nails" so i can't collect the just of the band. to make it more clear i'll show you my database structure: `id_p` int(11) default NULL auto_increment, `band` varchar(100) default NULL, `title` varchar(100) default NULL, `cover_image` varchar(100) default NULL, `short_description` varchar(255) default NULL, `complete_description` longtext, PRIMARY KEY (`id_p`) hope it can be more clear if u'r still up to give me an help. bout the double quotes, i use this code in my index page to recall the name band (and the script item just shw how many albums...between brackets): <form method=post action=band.php><select name=band style="font-size: 9 px; font-family: arial; background-color:B8AF9E" size="1"> <option selected>Select a band</option> <?php include("config.php"); mysql_connect($host,$user,$password)or die("can't conect"); mysql_select_db("$xxxx")or die("can't connect to the db"); $dati=mysql_query("select distinct band from album"); $numofrows=mysql_num_rows($dati); while($array=mysql_fetch_array($dati)){ echo"<option value=$array[band]>$array[band]"; $a=$array[band]; item($a);echo"</option>"; } ?> </select><input type=submit value=go style="font-size: 9 px; font-family: arial; font-weight: bold"> </form> Link to comment https://forums.phpfreaks.com/topic/41963-form-with-post-and-blank-spaces/#findComment-203489 Share on other sites More sharing options...
redarrow Posted March 9, 2007 Share Posted March 9, 2007 dont no if this would work but the idear is to get the id from the select statement then search the database for that band from the like statement. <?php $db=mysql_connect("localhost","username","password"); mysql_select_db("database_name",$db); $query1="select id,bands from music where ".$_GET['id']." LIKE "%bands%" "; $result1=mysql_query($query1) or die(mysql_error()); while($c=mysql_fetch_assoc($result1){ echo" ".$c['band_name']." <br> ".$c['music_playing']." <br>"; } echo"<form method='POST' action''>"; echo"<select name='bands'>"; $query2="select id,bands from music"; $result2=mysql_query($query2); while($x=mysql_fetch_assoc($result2)){ echo"<option value='".$x['id']."'>".$x['bands'],"</option>"; } echo"<br>"; echo"<input type='submit' name='submit' value='Get The Band'>"; echo"</select>"; echo"</form>>"; ?> Link to comment https://forums.phpfreaks.com/topic/41963-form-with-post-and-blank-spaces/#findComment-203491 Share on other sites More sharing options...
timecut Posted March 9, 2007 Author Share Posted March 9, 2007 i see what u mean... it's probably the best method to do that. if i understood properly i should create a simple table where i've all the bands with an id. on my album database i can recall the band's id instead of the real name and print it on the screen with blank spaces cuz i query on the id instead of the name. is it what ur code suggest, isn'it? Link to comment https://forums.phpfreaks.com/topic/41963-form-with-post-and-blank-spaces/#findComment-203494 Share on other sites More sharing options...
redarrow Posted March 9, 2007 Share Posted March 9, 2007 yes but dont no if it works a guess but you got the idear ok Link to comment https://forums.phpfreaks.com/topic/41963-form-with-post-and-blank-spaces/#findComment-203495 Share on other sites More sharing options...
timecut Posted March 9, 2007 Author Share Posted March 9, 2007 many thanx... i guess i understand why super guru. simple solution in front of my eyes and i was looking for compicated functions.... Link to comment https://forums.phpfreaks.com/topic/41963-form-with-post-and-blank-spaces/#findComment-203496 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.