Page 1 of 1

My first hand written mySQL /PHP code

Posted: Mon Feb 09, 2004 9:04 am
by mesz
I have been building this alll day and I am bewildered

Code: Select all

<?php
<?
if($submit)
{
	mysql_connect("host","-","-");
	mysql_select_db("dbname");
	$result=MYSQL_QUERY("INSERT INTO tablename (yrname,email,phone,address,thetitle,description,qty,price)".
	"VALUES ('$yrname', '$email', '$phone', '$address', '$thetitle', '$description', '$qty','$price')");
	print "This file has the Database"; 
}
else
{
<form method="post" action="submit.php">
name:
<br>
<INPUT TYPE='TEXT' NAME='yrname' VALUE='your name' size=60>
<br>
e-mail:
<br>
<INPUT TYPE='TEXT' NAME='email' VALUE='your e-mail' size=60>
<br>
phone no:
<br>
<INPUT TYPE='TEXT' NAME='email' VALUE='your phone no.' size=60>
<br>
address:
<br>
<INPUT TYPE='TEXTAREA' VALUE='address' VALUE='your address' rows=10 columns="60"></textarea>
<br><br>
<b>title of item:</b>
<INPUT TYPE='TEXT' NAME='title' VALUE='title' size=60>
<br>
description:<INPUT TYPE='TEXTAREA' VALUE='description' VALUE='description' rows=15 columns="70"></textarea>
<br>
quantity:
<INPUT TYPE='TEXT' NAME='qty' VALUE='1' size=60>
<br>
price:
<br>
<INPUT TYPE='TEXT' NAME='price' VALUE='00.00' size=60>
<br>
<br>
<INPUT TYPE="submit" name="submit" value="submit">
</form>
}
mysql_close ();
?>
?>
I get this error:

Code: Select all

Parse error: parse error in /home/virtual/site28/fst/var/www/html/cpCommerce/submit.php on line 15
Does anybody know why and how I fix it?

Posted: Mon Feb 09, 2004 9:27 am
by JayBird
this should work, you'll see what i have done

Code: Select all

<? 
if($submit) 
{ 
   $link = mysql_connect("host","-","-"); 
   mysql_select_db("dbname"); 
   $result=mysql_query("INSERT INTO tablename (yrname,email,phone,address,thetitle,description,qty,price)". 
   "VALUES ('$yrname', '$email', '$phone', '$address', '$thetitle', '$description', '$qty','$price')"); 
   print "This file has the Database"; 
   mysql_close ($link); 
} 
else 
{ 
?>
<form method="post" action="submit.php"> 
name: 
<br> 
<INPUT TYPE='TEXT' NAME='yrname' VALUE='your name' size=60> 
<br> 
e-mail: 
<br> 
<INPUT TYPE='TEXT' NAME='email' VALUE='your e-mail' size=60> 
<br> 
phone no: 
<br> 
<INPUT TYPE='TEXT' NAME='email' VALUE='your phone no.' size=60> 
<br> 
address: 
<br> 
<INPUT TYPE='TEXTAREA' VALUE='address' VALUE='your address' rows=10 columns="60"></textarea> 
<br><br> 
<b>title of item:</b> 
<INPUT TYPE='TEXT' NAME='title' VALUE='title' size=60> 
<br> 
description:<INPUT TYPE='TEXTAREA' VALUE='description' VALUE='description' rows=15 columns="70"></textarea> 
<br> 
quantity: 
<INPUT TYPE='TEXT' NAME='qty' VALUE='1' size=60> 
<br> 
price: 
<br> 
<INPUT TYPE='TEXT' NAME='price' VALUE='00.00' size=60> 
<br> 
<br> 
<INPUT TYPE="submit" name="submit" value="submit"> 
</form> 
<?
} 
?>
Mark

Posted: Mon Feb 09, 2004 9:36 am
by mesz
Cheers Bud!

Form comes up bit with this error:

Code: Select all

Warning: mysql_close(): no MySQL-Link resource supplied in /home/virtual/site28/fst/var/www/html/cpCommerce/submit.php on line 47
and then using my testreview.php page I can't see any of the data, so either it hasn't been written to file or my script to see it is sh*ite as well.

Code: Select all

<?php
<?php
    /* Connecting, selecting database */
    $link = mysql_connect("", "", "")
        or die("Could not connect");
    print "Connected successfully";
    mysql_select_db("") or die("Could not select database");

    /* Performing SQL query */
    $query = "SELECT * FROM ";
    $result = mysql_query($query) or die("Query failed");

    /* Printing results in HTML */
    print "\n";
    while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
        print "\t\n";
        foreach ($line as $col_value) {
            print "\t\t$col_value\n";
        }
        print "\t\n";
    }
    print "\n";

    /* Free resultset */
    mysql_free_result($result);

    /* Closing connection */
    mysql_close($link);
?>
?>

Posted: Mon Feb 09, 2004 10:01 am
by JayBird
i have edited the code in my previous post, saw some more errors that you made

Mark

Posted: Mon Feb 09, 2004 10:08 am
by mesz
cheers mark...still struggling with it, but I think you've been kind enough already.

Posted: Mon Feb 09, 2004 10:16 am
by JayBird
please tell.....

Posted: Mon Feb 09, 2004 10:18 am
by mesz
I used your edited comments but still get

Code: Select all

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/virtual/site28/fst/var/www/html/cpCommerce/submit.php on line 47

Posted: Mon Feb 09, 2004 10:23 am
by JayBird
sorry, i was being thick, the mysql_close was in completely the wrong place. To be honest, you don't really have to use it at all.

Also, your code isn't going to work at all if you have got register_globals OFF in your PHP.ini. You will need to reference varaibles like this $_POST['variable_name'];

Mark

Posted: Mon Feb 09, 2004 10:24 am
by mesz
cheers...like I said my first run I have written myself. I'll get on with that tommorrow.