Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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

Posts: 115
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
 
 
Register now for full access!
Old 08-06-2009, 10:24 AM Re: Form not working for some reason...
Super Talker

Posts: 115
Name: Not Telling
Trades: 0
Bump. I still need help.
sith717 is offline
Reply With Quote
View Public Profile
 
Old 08-06-2009, 10:49 AM Re: Form not working for some reason...
Extreme Talker

Posts: 177
Trades: 0
can you show us your create table statement for the table?

I dont think id can't be null...unless it's not primary key

Last edited by kbfirebreather; 08-06-2009 at 11:04 AM.. Reason: changed "can" to "can't", which is waht I originally meant
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 08-06-2009, 10:53 AM Re: Form not working for some reason...
Super Talker

Posts: 115
Name: Not Telling
Trades: 0
Here
PHP Code:
<?php
/* connect to the database */
// conect to the server
$connect mysql_connect("localhost","username","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
    
}
?>

<form method="post">
<?php
// if preview
if(isset($_POST['preview'])) {
// show code as html
$code stripslashes($_POST['code']);
echo 
$code."<br />";
echo 
"<input type='hidden' name='code' value='".$code."' / >";
// show save and edit buttons
echo "<input type='submit' name='submit' 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 
stripslashes($_POST['code']); 
                                                                } 
// 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'])) {

// check the database
$sql mysql_query("SELECT * FROM `addvert`") or die (mysql_error());
// count results returned
$count mysql_num_rows($sql);
// check wether to update or insert.
$code mysql_real_escape_string($_POST['code']);
if(
$count == 0) {
$add mysql_query("INSERT INTO `addvert` (`id`, `code`) VALUES (NULL, '$code')") or die (mysql_error());
} else {
$add mysql_query("UPDATE `addvert` SET code='$code' WHERE id='1'") or die (mysql_error());
// ends update or insert

if($add == TRUE) {
// echo complete msg or divert
echo "the code has been updated";
/* 
############### You can echo the code above OR refresh the page ###############
divert back to this page

header('location: thispage.php');
*/
} else { // echo error
echo "there was an error with the querys";
// end complete
// end submit
// end if not preview.
?>
To create the databse use:
PHP Code:
CREATE TABLE IF NOT EXISTS `addvert` (
  `
idint(255NOT NULL auto_increment,
  `
codelongtext NOT NULL,
  
PRIMARY KEY  (`id`)
ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=
and to display the code around the website use:
PHP Code:
<?php
/* Make sure that it has the conection scrip above this code on all pages :) */
$sql mysql_query("SELECT * FROM addvert") or die (mysql_error());
$rows mysql_fetch_array($sql);
echo 
stripslashes($rows['code']);
?>
I just need help with:
HOW TO SHOW MULTIPLE ADVERTS IN DIFFERENT PLACES, AND SHOW THE CURRENT DATABASE TEXT IN THE TEXTBOX VALUE.
sith717 is offline
Reply With Quote
View Public Profile
 
Old 08-06-2009, 11:06 AM Re: Form not working for some reason...
Extreme Talker

Posts: 177
Trades: 0
so you're not getting the error msg like your first post?

PHP Code:
You have an error in your SQL syntaxcheck 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 
to solve this...change your insert statement to be...

PHP Code:
$add mysql_query("INSERT INTO `addvert` (`code`) VALUES ('$code')") or die (mysql_error()); 

you dont need to define the 'id' column, as it is auto increment, and will take care of itself

and I'm a little confused on exactly what your asking...about adverts in different places.

do you want like an admin page that displays current adverts in the database that shows each specific adverts information?
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 08-06-2009, 12:13 PM Re: Form not working for some reason...
Super Talker

Posts: 115
Name: Not Telling
Trades: 0
I have fix it. Thank You anyways.
sith717 is offline
Reply With Quote
View Public Profile
 
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.24280 seconds with 12 queries