Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Mon Feb 09, 2004 9:04 am
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?
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Feb 09, 2004 9:27 am
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
Last edited by
JayBird on Mon Feb 09, 2004 10:21 am, edited 2 times in total.
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Mon Feb 09, 2004 9:36 am
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);
?>
?>
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Feb 09, 2004 10:01 am
i have edited the code in my previous post, saw some more errors that you made
Mark
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Mon Feb 09, 2004 10:08 am
cheers mark...still struggling with it, but I think you've been kind enough already.
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Feb 09, 2004 10:16 am
please tell.....
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Mon Feb 09, 2004 10:18 am
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
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Feb 09, 2004 10:23 am
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
Last edited by
JayBird on Mon Feb 09, 2004 10:24 am, edited 1 time in total.
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Mon Feb 09, 2004 10:24 am
cheers...like I said my first run I have written myself. I'll get on with that tommorrow.