Current location: Hot Scripts Forums » Programming Languages » PHP » Why won't select list item insert into database?


Why won't select list item insert into database?

Reply
  #1 (permalink)  
Old 04-12-04, 01:01 PM
gavacho gavacho is offline
New Member
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Why won't select list item insert into database?

Yes, I am a newbie. Could some kind person please take a look at the following code and let me know why the "Select" list item chosen does not insert into the database? All of the other form fields including "firstname", "lastname", etc. insert ok. It is only the selection from the "categories" list that does not insert. Why??

Here is the form (the processing script and script used to create the table are below):


<form action="orderconfirm.php" method="post">
<input type="hidden" name="username" value="<? print $_POST['username']?>">
<input type="hidden" name="password" value="<?print $_POST['password']?>">
<p align="left" class="latext">First Name:
<input name="firstname" type="text" id="firstname">
<br><br>
Last Name:
<input name="lastname" type="text" id="lastname">
<br><br>
E Mail Address:
<input name="email" type="text" id="email" size="55">
<br><br>
Website URL:&nbsp;&nbsp;&nbsp;
<input name="url" type="text" id="url" size="55">
<br><br>Number of links desired: <input name="linknum" type="int" id="linknum" size="2"></p>
<p align="left" class="latext">Select the category<br>
for your link(s)</p>
<p align="left" class="latext">


<select name="category" id="category">
<option value="Advertising & Marketing">Advertising & Marketing</option>
<option value="Agriculture & Forestry">Agriculture & Forestry</option>
<option value="Arts & Artists">Arts & Artists</option>
<option value="Automotive">Automotive</option>
<option value="Business and Financial Services">Business and Financial Services</option>
<option value="Business Opportunities">Business Opportunities</option>
<option value="Business to Business">Business to Business</option>
<option value="Computers & Internet">Computers & Internet</option>
<option value="Consumer Products and Services">Consumer Products and Services</option>
<option value="Education">Education</option>
<option value="Energy & Environment">Energy & Environment</option>
<option value="Food & Drink">Food & Drink</option>
<option value="Gaming">Gaming</option>
<option value="Health, Nutrition and Beauty">Health, Nutrition and Beauty</option>
<option value="Hobbies, Crafts, and Games">Hobbies, Crafts, and Games</option>
<option value="Home & Garden">Home & Garden</option>
<option value="Law">Law</option>
<option value="Managing & Consulting">Managing & Consulting</option>
<option value="Media & Entertainment">Media & Entertainment</option>
<option value="People">People</option>
<option value="Real Estate & Construction">Real Estate & Construction</option>
<option value="Security">Security</option>
<option value="Sports">Sports</option>
<option value="Talon">Talon</option>
<option value="Telecommunications">Telecommunications</option>
<option value="Transportation & Logistics">Transportation & Logistics</option>
<option value="Travel & Tourism">Travel & Tourism</option>
</select>


</p>
<div align="left" class="latext">Enter your link and descriptive text (2 short sentences max) here:<br>
<textarea name="link" cols="80" rows="5" id="describe"></textarea>
<br>
<input type="submit" name="Submit" value="Submit">
&nbsp;You will be taken to the Order Confirmation page. </div>
</form>



Here is the processing script:

<html><head><title>Linkdata Insert Record</title></head>
<body>
<?
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$url=$_POST['url'];
$linknum=$_POST['linknum'];
$category=$_POST['category'];
$link=$_POST['link'];
$linkedto=$_POST['linkedto'];
$linkedfrom=$_POST['linkedfrom'];
$linkedtoconf=$_POST['linkedtoconf'];
$linkedfromconf=$_POST['linkedfromconf'];
$maindate=$_POST['mainDate'];
$db="linkar";
$conn = mysql_connect("localhost","root","triadpass");
//$link = mysql_connect("localhost",$_POST['username'],$_POST['password']);
if (! $conn)Couldn't connect to MySQL");
mysql_select_db($db , $conn) or die("Select Error: ".mysql_error());
$result=mysql_query("INSERT INTO linkar (firstname, lastname, email, url, linknum, category, link) VALUES ('$firstname','$lastname','$email','$url','$linknu m','$category','$link')")or die("Insert Error: ".mysql_error());
mysql_close($conn);

?>
<form method="POST" action="linkorder.php">
<input type="submit" value="Insert Another Record">
</form>
</body>
</html>

Here is the script used to create the table "linkdata":


<html><head><title> Create Link Data Table</title></head>
<body>
<?
$db="linkar";
$conn = mysql_connect("localhost","root","triadpass");
if (! $conn)
die("Couldn't connect to MySQL");
mysql_select_db($db , $conn)
or die("Select DB Error: ".mysql_error());
//create table
mysql_query("CREATE TABLE linkdata( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), firstname VARCHAR(55), lastname VARCHAR(55), email VARCHAR(55), url VARCHAR(55), linknum INT(5), category VARCHAR(55), link VARCHAR(255), linkedto VARCHAR(255), linkedfrom VARCHAR(255), linkedtoconf TINYINT(1), linkedfromconf TINYINT(1), mainDate VARCHAR(255))")or die("Create table Error: ".mysql_error());
mysql_close($conn);

?>
</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-05-08, 07:36 PM
markei markei is offline
New Member
 
Join Date: Dec 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
A place to start:
it appears there are several errors in your code, I would correct these first, such as:
Quote:
Originally Posted by gavacho View Post
if (! $conn)Couldn't connect to MySQL");
There's a bunch missing here: a way to output the message, a beginning double quote and there's a single right parens that would cause it to fail.
Quote:
Originally Posted by gavacho View Post
('$firstname','$lastname','$email','$url','$linknu m','$category','$link')")or
There's a space in $linknum that shouldn't be there.
Check your code thoroughly for these type of errors, then repost if it still doesn't work.
Hope it helps!
markei
---------------------
no sig yet
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-05-08, 07:38 PM
markei markei is offline
New Member
 
Join Date: Dec 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
I just realized this thread is 4 years old, not from yesterday...lol
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with retaining select list values sky4est PHP 1 03-25-04 06:00 PM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 07:02 AM
MySQL table problem perleo PHP 9 12-16-03 02:16 PM
PHP Can't select database EST PHP 4 08-19-03 11:14 AM
dropdown list from database and with images redspider ASP 4 07-30-03 07:13 AM


All times are GMT -5. The time now is 01:30 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.