Reply
Form not working for some reason...
Old 08-06-2009, 11:31 AM Form not working for some reason...
Super Talker

Posts: 109
Name: Not Telling
Trades: 0
This form is not working.

When I click Save it shows this error.
Quote:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'add SET (`id`, `code`) VALUES (NULL, 'sdfsd')' at line 1
This is the code.
PHP Code:
<form method="post">
<?php
// if
if(isset($_POST['preview'])) {
// show code as html
echo $_POST['code']."<br />";
// show save and edit buttons
echo "<input type='submit' name='save' id='submit' value='Save' /><input type='submit' name='edit' id='submit' value='Edit code' />";
}
else { 
// if not preview then show form
?>
    <label>Enter Add Code:</label>
    <textarea name="code" style="width: 200px; height: 100px;"><?php
                                                                
// if edit then show code in textarea
                                                                
if(isset($_POST['edit'])) {
                                                                    echo 
$_POST['preview']; 
                                                                } 
// if not edit
                                                                
?></textarea>
    <input type="submit" name="submit" id="submit" value="Save" />
    <input type="submit" name="preview" id="submit" value="Preview" />
</form>
<?php
// check if submited code
if(isset($_POST['submit'])) {

/* connect to the database */
// conect to the server
$connect mysql_connect("localhost","db_username","db_password");
    
// if connected to the server continue
    
if($connect == TRUE) {
        
// Select the database and check if connected
        
if(mysql_select_db("db_name") != TRUE) {
            
// if not connected display error
            
exit("<span style='color: red'>Can't connect to the MySQL database. Please contact the webmaster.</body></html>");
        
// end if can not connect to database
        
}
    
// if not connected to the server then contiunue
    
} else{
        
// display error if not connected to the server
        
exit("<span style='color: red'>Can't connect to the MySQL server. Please contact the webmaster.</body></html>");
    
// end if not connected to the server
    
}

// insert add into database
$sql mysql_query("UPDATE add SET (`id`, `code`) VALUES (NULL, '".$_POST['code']."')") or die (mysql_error());

if(
$sql TRUE) {
// echo complete msg or divert
echo "the code has been updated";
// divert back to this page
header('location: forms.php');
// end complete
// end submit
// end if not preview.
?>
---

More about the form:

Basicly what I need, is a Ad Managment script.

Some things In it:

A form, basicly a textarea where I can insert the code and click update.

When I click Update, on the index it will show the Banner/Advert I have placed.

Like It would connect to a database or something.

Thats all I need, no counters, nothing special, a form thats it.

The first person being able to help me out.

----
  • I would create a page in the admin section that displays the current ad with a form below.
  • The form would be a big text area that updates the database, the value of the form would come from the database displaying the html code in the text area.
  • Once the form is edited and submitted the page would reload displaying the new ad.
  • Each ad would require its own page, re-using the original code.
  • Maybe create a preview button to make sure you entered the correct code before you update the database.
I will be able to do something in return, if that means, give you FREE hosting with any features you want or designing you a logo.
sith717 is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 08-10-2009, 02:39 AM Re: Form not working for some reason...
nayes84's Avatar
Super Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 139
Name: John
Location: Tokyo
Trades: 0
the mysql query is not correct
PHP Code:
// insert add into database
$sql mysql_query("UPDATE add SET (`id`, `code`) VALUES (NULL, '".$_POST['code']."')") or die (mysql_error()); 
should be corrected to
PHP Code:
// insert add into database
$sql mysql_query("INSERT INTO `add` (`id`,`code`) VALUES (NULL,'".$_POST['code']."')") or die (mysql_error()); 
not sure if there is no more errors. so anyway just fix this and see if it works
__________________
Upload Your Photos For Free | Submit Website To ePhoto Bay
ASP VS JSP
| Free Online Galleries
If I'm("Helpful") Then Add_Talkupation("nayes84") End If

Last edited by nayes84; 08-10-2009 at 02:41 AM..
nayes84 is offline
Reply With Quote
View Public Profile Visit nayes84's homepage!
 
Reply     « Reply to Form not working for some reason...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.10947 seconds with 13 queries