jack12345 Posted July 26, 2006 Share Posted July 26, 2006 I have a small problem in regards to php/mysql. I have a drop down box/list on my form for entering data into a mysql database. [code]<select><?php$options = array('Jack', 'Jane', 'Irene', 'Marry', 'Jody', 'Ana', 'Ivana');foreach ($options as $option) { $isSelected = $option == $name ? ' selected' : ''; print "<option$isSelected>$option</option>\n";}?></select>[/code]Now the problem is that instead of insertin Irene, Jane, Marry... into the database i'd like to insert html code in it. Example <a href="url">Irene</a> and something like that for every name. Now i can't seem to figure out how to use that instead of just the name. Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/ Share on other sites More sharing options...
trq Posted July 26, 2006 Share Posted July 26, 2006 Where is the code that does the actual inserting? Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64368 Share on other sites More sharing options...
jack12345 Posted July 26, 2006 Author Share Posted July 26, 2006 I'm not aure i understand the question exactly. But this drop down box. When i select an option from it and click add to database it get's added so i don't have a problem with it. It is a part of a form which works ok.The problem is that i am not able to replace Irene, Jane, Jack ... which are in the array as they are they are not variables, with html code. So that when i select Jack in the database it get's added <a href="http://www.test.com/jack.html">Jack</a> So how do i replace those simple names in the array with html code. Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64373 Share on other sites More sharing options...
redarrow Posted July 26, 2006 Share Posted July 26, 2006 try this ok save as seen lol.......................edited with database info ok.when a user selects a username the database will get the link with the user name and url.test.php[code]<form action="" method="POST"><select name="name"><?php$array=array('Jack', 'Jane', 'Irene', 'Marry', 'Jody', 'Ana', 'Ivana');for($i=0; $i<count($array); $i++){?><option value=<? echo $array[$i]; ?> ><?echo $array[$i]; ?></option><?}?><input type="submit" name="submit" value="submit"></select><?if($_POST['submit']){$member_name_with_link="<a href='what_ever.com'>$name</a>";$query="INSERT INTO xxxxx ( member_name_with_link)VALUES('$member_name_with_link')";$result=mysql_query($query);}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64400 Share on other sites More sharing options...
trq Posted July 27, 2006 Share Posted July 27, 2006 [quote]Now the problem is that instead of insertin Irene, Jane, Marry... into the database i'd like to insert html code in it.[/quote]Once again. Can we see the code that does the actual database insert? Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64403 Share on other sites More sharing options...
jack12345 Posted July 27, 2006 Author Share Posted July 27, 2006 Ok here is the whole code of the form.[code]<html><body><?php$db = mysql_connect("localhost", "dbuser", "dbpass");mysql_select_db("dbname",$db);if ($submit) { // here if no ID then adding else we're editing if ($id) { $sql = "UPDATE profile SET name='$name',listassignement='$listassignement',listposition='$listposition',rank_image='$rank_image', medal_image='$medal_image', rank='$rank', species='$species', birthplace='$birthplace', current_posting='$current_posting', qualification='$qualification', age='$age', sex='$sex', dob='$dob', appearance='$appearance',history='$history', background='$background', service_record='$service_record', commendations='$commendations', reprimands='$reprimands', med_record='$med_record', interests='$interests', added_notes='$added_notes', picture='$picture' WHERE id=$id"; } else { $sql = "INSERT INTO profile (name,listassignement,listposition,rank_image,medal_image,rank,species,birthplace,current_posting,qualification,age,sex,dob,appearance,history,background,service_record,commendations,reprimands,med_record,interests,added_notes,picture) VALUES ('$name','$listassignement','$listposition','$rank_image','$medal_image','$rank','$species','$birthplace','$current_posting','$qualification','$age','$sex','$dob','$appearance','$history','$background','$service_record','$commendations','$reprimands','$med_record','$interests','$added_notes','$picture')"; } // run SQL against the DB $result = mysql_query($sql) or die(mysql_error()); echo "Record updated/edited!<p>";} elseif ($delete) { // delete a record $sql = "DELETE FROM profile WHERE id=$id"; $result = mysql_query($sql); echo "$sql Record deleted!<p>";} else { // this part happens if we don't press submit if (!$id) { // print the list if there is not editing $result = mysql_query("SELECT * FROM profile",$db); while ($myrow = mysql_fetch_array($result)) { printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["id"], $myrow["name"], $myrow["rank"]); printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]); } } ?> <P> <a href="<?php echo $PHP_SELF?>">ADD A RECORD</a> <P> <form method="post" action="<?php echo $PHP_SELF?>"> <?php if ($id) { // editing so select a record $sql = "SELECT * FROM profile WHERE id=$id"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); $id = $myrow["id"]; $name = $myrow["name"]; $listassignement = $myrow["listassignement"]; $listposition = $myrow["listposition"]; $rank_image = $myrow["rank_image"]; $medal_image = $myrow["medal_image"]; $rank = $myrow["rank"]; $species = $myrow["species"]; $birthplace = $myrow["birthplace"]; $current_posting = $myrow["current_posting"]; $qualification = $myrow["qualification"]; $age = $myrow["age"]; $sex = $myrow["sex"]; $dob = $myrow["dob"]; $appearance = $myrow["appearance"]; $history = $myrow["history"]; $background = $myrow["background"]; $service_record = $myrow["service_record"]; $commendations = $myrow["commendations"]; $reprimands = $myrow["reprimands"]; $med_record = $myrow["med_record"]; $interests = $myrow["interests"]; $added_notes = $myrow["added_notes"]; $picture = $myrow["picture"]; // print the id for editing ?> <input type=hidden name="id" value="<?php echo $id ?>"> <?php } ?> Character Name:<br><br><input type="Text" name="name" value="<?php echo $name ?>"><br><br> Assignement for the positions page(a link to the ship or base on which he is serving): <br><br> <select name="listassignement"><?php$options = array('USS Jackson', 'USS Viking', 'USS Delaware', 'USS Big Foot', 'USS Jody', 'USS Ana', 'USS Ivana');foreach ($options as $option) { $isSelected = $option == $listassignement ? ' selected' : ''; print "<option$isSelected>$option</option>\n";}?></select> <br><br> Position for the positions page, use an abrevation, consult the position page for the abrevations<br><br> <select name="listposition"><?php$options = array('', 'CO', 'FO', 'CTSO', 'SMO', 'CEO', 'COO', 'CNO', 'CScO', 'CMO', 'CNS', 'EXO', 'MLT', 'CTO', 'CSO', 'Tac', 'Sec', 'CIVIL', 'ORE', 'DCS', 'AMB', 'CSbS', 'CSbO', 'ECH', 'LiO', 'CSOO', 'CIO', 'AI', 'Cadet', 'CHO', 'TO', 'SO', 'FW', 'CCO', 'NS', 'CAO');foreach ($options as $option) { $isSelected = $option == $listposition ? ' selected' : ''; print "<option$isSelected>$option</option>\n";}?></select> <br> <br> Rank Image(just enter the name of the rank image file something.jpg):<input type="Text" name="rank_image" value="<?php echo $rank_image ?>"><br> Medal image(enter the html code to display the medal image): <textarea name="medal_image" cols="80" rows="20"><?php echo $medal_image ?></textarea> <br> Rank name:<input type="Text" name="rank" value="<?php echo $rank?>"><br> Species:<input type="Text" name="species" value="<?php echo $species ?>"><br> Birthplace:<br> <textarea name="birthplace" cols="80"><?php echo $birthplace ?></textarea> <br> Current Posting:<input type="Text" name="current_posting" value="<?php echo $current_posting ?>"><br> Qualification:<br> <textarea name="qualification" cols="80" rows="5"><?php echo $qualification ?></textarea> <br> Age:<input type="Text" name="age" value="<?php echo $age ?>"><br> Sex:<input type="Text" name="sex" value="<?php echo $sex ?>"><br> Date of Birth:<input type="Text" name="dob" value="<?php echo $dob ?>"><br> Apperance:<br><textarea name="appearance" cols="60" rows="20" wrap="VIRTUAL" ><?php echo $appearance ?></textarea> <br>History:<br><textarea name="history" cols="80" rows="20" wrap="VIRTUAL" ><?php echo $history ?></textarea> <br> Background:<br><textarea name="background" cols="80" rows="20" wrap="VIRTUAL" ><?php echo $background ?></textarea> <br> Service record, enter a (br at the end of each line):<br><textarea name="service_record" cols="60" rows="20" wrap="VIRTUAL" ><?php echo $service_record ?></textarea> <br> Commendations(same as above):<br><textarea name="commendations" cols="60" rows="20" wrap="VIRTUAL" ><?php echo $commendations ?></textarea> <br> Reprimands:<br><textarea name="reprimands" cols="60" rows="20" wrap="VIRTUAL" ><?php echo $reprimands ?></textarea> <br> Medical Record:<br><textarea name="med_record" cols="60" rows="20" wrap="VIRTUAL" ><?php echo $med_record ?></textarea> <br> Interests:<br><textarea name="interests" cols="60" rows="20" wrap="VIRTUAL" ><?php echo $interests ?></textarea> <br> Additional Notes:<br><textarea name="added_notes" cols="60" rows="20" wrap="VIRTUAL" ><?php echo $added_notes ?></textarea> <br> Picture(just enter the image url):<br> <textarea name="picture" cols="70" rows="2"><?php echo $picture ?></textarea> <br> <input type="Submit" name="submit" value="Enter information"> </form><?php}?></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64407 Share on other sites More sharing options...
trq Posted July 27, 2006 Share Posted July 27, 2006 Is it the $listposition variable your talking about? I dont see your original code anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64410 Share on other sites More sharing options...
jack12345 Posted July 27, 2006 Author Share Posted July 27, 2006 No, it is $listassignement. Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64412 Share on other sites More sharing options...
redarrow Posted July 27, 2006 Share Posted July 27, 2006 you need to stripslashes and also you need to sort out the php_selfthat all i can help with good luck. Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64413 Share on other sites More sharing options...
redarrow Posted July 27, 2006 Share Posted July 27, 2006 your using the varable $options a lot Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64414 Share on other sites More sharing options...
trq Posted July 27, 2006 Share Posted July 27, 2006 [quote]No, it is $listassignement.[/quote][code=php:0]if ($id) { $sql = "UPDATE profile SET name='$name',listassignement='<a href=\"url\">$listassignement</a>',listposition='$listposition',rank_image='$rank_image', medal_image='$medal_image', rank='$rank', species='$species', birthplace='$birthplace', current_posting='$current_posting', qualification='$qualification', age='$age', sex='$sex', dob='$dob', appearance='$appearance',history='$history', background='$background', service_record='$service_record', commendations='$commendations', reprimands='$reprimands', med_record='$med_record', interests='$interests', added_notes='$added_notes', picture='$picture' WHERE id=$id"; } else { $sql = "INSERT INTO profile (name,listassignement,listposition,rank_image,medal_image,rank,species,birthplace,current_posting,qualification,age,sex,dob,appearance,history,background,service_record,commendations,reprimands,med_record,interests,added_notes,picture) VALUES ('$name','<a href=\"url\">$listassignement</a>','$listposition','$rank_image','$medal_image','$rank','$species','$birthplace','$current_posting','$qualification','$age','$sex','$dob','$appearance','$history','$background','$service_record','$commendations','$reprimands','$med_record','$interests','$added_notes','$picture')"; }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64415 Share on other sites More sharing options...
trq Posted July 27, 2006 Share Posted July 27, 2006 Redarrow... do you even read the questions? Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64417 Share on other sites More sharing options...
jack12345 Posted July 27, 2006 Author Share Posted July 27, 2006 Ok i've tried that and now i get always the same url no matter what option i select from the drop down box and i need the url to be different for each option. And thnx for taking your time to help me out. Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64418 Share on other sites More sharing options...
trq Posted July 27, 2006 Share Posted July 27, 2006 Hoiw do you want the url to be different? Where is this different data comming from? Give me an example url. Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64421 Share on other sites More sharing options...
jack12345 Posted July 27, 2006 Author Share Posted July 27, 2006 Ok. I'll explain. I have a drop down box the one where i chose listassignement. There i have several ships listed. Say USS Jackson USS Viking USS Delawareso when i select in the list let's say USS Viking in the database it gets's added <a href="http://felixsavali.awardspace.com/table.php">USS Viking</a> or if i select USS Jackson it gets added <a href="http://test.freserver.org/Jackson.php">USS Jackson</a> Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64422 Share on other sites More sharing options...
trq Posted July 27, 2006 Share Posted July 27, 2006 Give me an example url. Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64440 Share on other sites More sharing options...
jack12345 Posted July 27, 2006 Author Share Posted July 27, 2006 Ups... i gave it but i forgot to put it in code so the post read it like a hyperlink. Here it is:[code]<a href="http://felixsavali.awardspace.com/table.php">USS Viking</a>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15746-phpmysql-problem/#findComment-64579 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.