Forum Moderators: coopster

Message Too Old, No Replies

Insert Problem

Yes I have looked through the post

         

Light_Gear

2:26 pm on Feb 23, 2006 (gmt 0)

10+ Year Member



Yes I have looked through the post. I have tried everything I can think of.
Anyways here it is. and yes I will probible go jump off cliff when I figure out what went wrong :-)
Now the database is called elisha and the table I want things to insert to is maintext.

Form Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Home Pages Text</title>
<style>
#form1 { background:#CCCCCC;
font-family:Georgia, "Times New Roman", Times, serif;
padding-left:10px;

}
</style>
</head>

<body>
<form action="testcommit.php"method="post">
<fieldset><legend>Website Text</legend>
<p>Website -
<select name="websites" id="websites" value="websites">
<option>Please Select One</option>
<option value="TMI">Teen Missions</option>
<option value="aosc">AIDS Orphans</option>
</select>
</p>
<p>Page -
<select name="page" value="page">
<option>Please Select One</option>
<option value="tmihome">TMI Home Page</option>
<option value="aoschome">AOSC Home Page</option>
<option value="ftm">FTM Page</option>
<option value="bmw">BMW Page</option>
</select>
</p>
<p>
<label>
<input name="Publishing" type="radio" value="Draft" checked="checked" />
Draft</label>
<label>
<input type="radio" name="Publishing" value="Publish" />
Publish</label>
<label>
<input type="radio" name="Publishing" value="Unpublish" />
Unpublish</label>

</p>

<p>
<label>Text Title :</label>
<input name="title" type="text" id="title" value="" size="30" maxlength="100" />
(*Note Text Title will Not Be shown on website)</p>
<p>
<textarea name="webtext" cols="50" rows="10"></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit" /> <input type="Reset" name="Reset" value="Reset" />
</p>
</fieldset>

</form>
</body>
</html>

PHP connecting to database to insert:

<?php
$link=mysql_connect("***","***","***")
or die ("Could not Connect Mayday:".mysql_error());
mysql_select_db('elisha', $link)
or die ("wheres elisha:".mysql_error());

// add the new information into the database

mysql_query ("INSERT INTO maintext (website, page, publishing, title, webtext)
VALUES ('$_POST[website]', '$_POST[page]', '$_POST[publishing]', '$_POST[title]', '$_POST[webtext]') ");

echo "<br />";
echo "<a href=\"form_page.php\">Click here to return to the form page.</a>";
?><pre>DEBUG:
<?php
print_r($_POST);
?></pre>
<p align="center" style="color:#0000FF"> Done. <a href="Textadd.php">Return to ADD </a>
</p>
</body>
</html>

omoutop

3:01 pm on Feb 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



how about inserting websites instead of website?

:)

coopster

5:49 pm on Feb 23, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Good catch, omoutop.

Welcome to WebmasterWorld, Light_Gear.

One way to catch these errors right off during development is to turn on error_reporting [php.net]. This and more good tips on Troubleshooting [webmasterworld.com] can be found in our PHP Forum Library [webmasterworld.com].

phparion

6:04 pm on Feb 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



One small tip that I can give you to track such error is to print the Query before executing it and check whether you are getting all the values properly or not, like in your case due to wrong variable name for WEBSITES, if you would have print this query, you would have seen the BLANK instead of its value and it would have been easy for you to track and understand the error.

Light_Gear

3:41 am on Feb 26, 2006 (gmt 0)

10+ Year Member



Hmm Well that might be the newest error. I know I have copied and pasted every name two or three from my database... Crap I hope that was just it. I will repost if that did it.

Thanks
everyone