Jump to content

Trying to get dropdown to insert link in mysql


mc

Recommended Posts

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:
[code]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;
}
[/code]

And this is in the form:
[code]
<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>
[/code]

Any help is greatly appreciated!
Link to comment
Share on other sites

don't get angry if you're already doing this...
But from your post you need the following code below your case statement.
[code]
$con= mysql_connect($host,$login,$pass);
mysql_select_db($dbname,$con);
mysql_query($insertDb,$con);
[/code]
Link to comment
Share on other sites

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?
[code]
mysql_error()
[/code]
Link to comment
Share on other sites

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:
[code]
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...

[/code]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.