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
Old 06-04-2005, 07:56 AM Script problem
Junior Talker

Posts: 1
Trades: 0
Ok, it's time for the n00b question:

I wrote this script which is supposed to create a table named by the user. This however gives some nasty errors and if the $_POST['addressbook'] is replaced with a non-variable (like just addressbook) it just loads the page again when the form is submitted.
PHP Code:
 <?
 
if (!$submit)
 {
 
?>
 <table cellspacing='5' cellpadding='5'>
 <form action='<? echo $PHP_SELF?>' method='POST'>
 <tr>
     <td valign='top'><b><font size="-1">Name of the Addressbook:</font></b></td>
     <td><input size="50" maxlength='250' type='text' name='addressbook'></td>
 </tr>
 <tr>
     <td colspan=2><input type='Submit' name='submit' value='Add'></td>
 </tr>
 </form>
 </table>
 <?
 
}
 else
 {
 
     include(
"conf.php");
         
     
$errorList = array();
     
$count 0;
 
 
     if (
sizeof($errorList) == 0)
     {
         
$connection mysql_connect($host$user$pass) or die ("Unable to connect!");
         
         
mysql_select_db($db) or die ("Unable to select database!");
 
         
$query "CREATE TABLE $_POST['addressbook'] (first_name VARCHAR(25), last_name VARCHAR(25), phone_number VARCHAR(15))";
         
$result mysql_query($query) or die ("Error in query: $query. " mysql_error());
 
         echo 
"<font size=-1>Update was successful. <a href=index.php>Return back to the menu.</a>.</font>";
 
         
mysql_close($connection);
     }
     else
     {
         echo 
"<font size=-1>Following errors were noticed: <br>";
         echo 
"<ul>";
         for (
$x=0$x<sizeof($errorList); $x++)
         {
             echo 
"<li>$errorList[$x]";
         }
         echo 
"</ul></font>";
     }
 }
 
?>
As usual, the answer is propably an easy one, but just something I don't seem to notice...

Last edited by 0beron; 06-04-2005 at 08:24 AM.. Reason: Use [php ] tags for php code :)
Kanjiro is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-04-2005, 08:26 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Either drop the single quotes around addressbook (It's within another string so is handled differently), or use a temp variable:

PHP Code:
$temp $_POST['addressbook'];
$query "CREATE TABLE $temp etc...."
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Reply     « Reply to Script problem
 

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.17516 seconds with 12 queries