Current location: Hot Scripts Forums » Programming Languages » PHP » I need help with my first php script


I need help with my first php script

Reply
  #1 (permalink)  
Old 08-01-03, 01:24 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
I need help with my first php script

ok .. I just wrote my first ever php script .. but it's showing a parser error in the IF statment ..

Parse error: parse error, unexpected T_IF in
c:\program files\apache group\apache\htdocs\scripts\addition.php on line 31


and here is my php code :
PHP Code:

<?php

/*first get all feilds values in here ..*/
    
$title=$HTTP_POST_VARS['title'];
    
$bookid=$HTTP_POST_VARS['bookID'];
    
$authf=$HTTP_POST_VARS['authf'];
    
$authl=$HTTP_POST_VARS['authl'];
    
$price=$HTTP_POST_VARS['price'];

/*now we Clean in the entries from spaces , to make
 sure the DB don't get screwed up ..*/
    
$title=trim($title);
    
$bookid=trim($bookid);
    
$authf=trim($authf);
    
$authl=trim($authl);
    
$price=trim($price);

/*another cleaning process ,, but this time to make sure 
no special chars would hurt the DB */
    
$title=addslashes($title);
    
$bookid=addslashes($bookid);
    
$authf=addslashes($authf);
    
$authl=addslashes($authl);
    
$price=addslashes($price);

/*now we should specify the MySQL connection info ..*/
    
$db_name="bookdb";
    
$server="localhost";
    
$db_user="saleh";
    
$db_pass="hidden"

/*check if user completed the form or not ..*/
if (!isset($title) || !isset($bookid) || !isset($authf) || !isset($authl) || !isset($price))
                           {
echo 
"Sorry but you did not complete all fields .. please go back and fill ALL fields";
                        }
/*now we will try to connect to MySQL database .*/
                            
else
        {  
            echo 
"now we are trying to connect to MySQL ..";
        }
    
mysql_connect($server $db_user $db_pass)
    or die(
"Could not connect: " mysql_error());
    print (
"Connected successfully");

    
mysql_db_select($db_name);
    
mysql_query("INSERT INTO books (title, bookID, authF, authL, price)
    VALUES (
$title$bookid$authf$authl$price)");

        
$result=mysql_query("SELECT * FROM books"$db);
        
$record_total=mysql_num_rows($result);
        echo 
"Total of books Record in the database is :" .$record_total .;
?>
the varibles values should be passed via form submittion .. the form is plain HTML ....
you know I love php but after this thing I started to hate it
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]

Last edited by NeverMind; 08-01-03 at 01:31 PM.
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 08-01-03, 01:54 PM
Godsmack Godsmack is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
You forgot the semicolon on the line above the IF statement.

PHP Code:

$db_pass="hidden" 


Randy

Last edited by Godsmack; 08-01-03 at 01:57 PM.
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 08-01-03, 02:05 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
ok this is done ..
also mysql_select_db(); is done .. now it's showing this :

now we are trying to connect to MySQL ..Connected successfully
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in c:\program files\apache group\apache\htdocs\scripts\addition1.php on line 46

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\scripts\addition1.php on line 47
Total of books Record in the database is :
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 08-01-03, 02:26 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
ok ... this is done ..
thanks the legend [Unknown] (he is a friend of mine poped up in MSN messanger after I posted this topic)
just for the record here are the problems in my code :
PHP Code:

$db_pass="hidden" 

should have a semicolon
PHP Code:

mysql_query("INSERT INTO books (title, bookID, authF, authL, price)   VALUES ($title$bookid$authf$authl$price)"); 

varibles should be in quote ' '
PHP Code:

$result=mysql_query("SELECT * FROM books"$db); 

I put an undefined varible ($db) which isn't needed anyway ...
(I don't know how I did this stupid mistake :-[)
PHP Code:

echo "Total of books Record in the database is :" .$record_total .; 

the . (dot) before ; is wrong ..

that's all .. now it's working perfectly ..
thanks again for [Unknown]
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 08-01-03, 02:27 PM
Godsmack Godsmack is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
change line 46 to:
PHP Code:

mysql_select_db($db_name); 

instead of mysql_db_select

Randy
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
PHP script HELP Jerome PHP 7 12-22-09 07:44 AM
error when creating database tables with php script spiroth10 PHP 4 01-06-04 04:59 PM
PHP theme selection script TMD PHP 2 09-22-03 04:43 AM
PHP script required Mickey Job Offers & Assistance 8 09-07-03 04:00 PM
30% off Hosting - Free PHP Script Autoinstaller cyberwisdom General Advertisements 0 07-06-03 02:47 PM


All times are GMT -5. The time now is 07:13 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.