Jump to content


Photo

Trying to get dropdown to insert link in mysql


  • Please log in to reply
7 replies to this topic

#1 mc

mc
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 13 July 2006 - 06:31 PM

Hi all,

I'm having trouble trying to get a page where the user can select an option from a dropdown, then when submitted it sends an html link to the database.

This is the code I was trying to make work, with no success:
switch ($_POST['venue'])
{
	case "chicago":
	$insertDb = "INSERT INTO events (venue) VALUES ("<a href='chicago.html'>Chicago, IL</a>")}
	break; 
	case "newyork":
	$insertDb = "INSERT INTO events (venue) VALUE ("<a href='newyork.html'>New York, NY</a>")
	break; 
	case "sanjose":
	$insertDb = "INSERT INTO events (venue) VALUE ("<a href='sanjose.html'>San Jose, CA</a>")
	break; 
	default:
	$insertDb = "INSERT INTO events (venue) VALUE ("<a href='default.html'>Default</a>")
	break; 
}

And this is in the form:
<select name="venue" id="venue">
<option value="chicago">Chicago, IL</option>
<option value="newyork">New York, NY</option>
<option value="sanjose">San Jose, CA</option>
</select>

Any help is greatly appreciated!

#2 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 13 July 2006 - 06:43 PM

don't get angry if you're already doing this...
But from your post you need the following code below your case statement.
$con= mysql_connect($host,$login,$pass);
mysql_select_db($dbname,$con);
mysql_query($insertDb,$con);


#3 mc

mc
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 13 July 2006 - 06:46 PM

Thanks for the quick reply!

I have the connection happening at the very end, are you saying I should have that after each case?

#4 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 13 July 2006 - 06:49 PM

no no! :)
Your doing it right.
I didn't see your insert code, so i just assumed what you posted was what was going on.

what is the sql error that gets reported to you after you execute:
mysql_query($insertDb,$con);

can you add this after your query call and tell us the error you receive?
mysql_error()


#5 mc

mc
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 13 July 2006 - 06:56 PM

I get this error:
Parse error: parse error, unexpected T_STRING in /home/www/anihhh/admin.php on line 87

Here are the lines added:
84: switch ($_POST['venue'])
85: {
86:     case "chicago":
87:     $insertDb = "INSERT INTO events (venue) VALUES ("<a href='www.chicago.com'>Chicago, IL</a>")
88:     break; 
89:     case "newyork":

etc...



#6 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 13 July 2006 - 07:00 PM

Change line 87 to this:
$insertDb = "INSERT INTO events (venue) VALUES (\"<a href='www.chicago.com'>Chicago, IL</a>\")";

You needed to escape your double quotes, add a semi-colon on the end of the line and end the first string.



Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#7 mc

mc
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 13 July 2006 - 07:08 PM

Woohoo! :D

Thanks a million dptr1988, that did it.

Also thanks to lead2gold for taking your time.

#8 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 13 July 2006 - 10:18 PM

I would not suggest that you store raw HTML code in your DB -- you should have two columns, one for the HREF target (i.e. the URL), and another for the plaintext, and put them together as HTML in your PHP code.  You'll thank me later when you want to change all of your links.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users