PDA

View Full Version : Sql/php database problem by newbie


Jennifer
08-18-2002, 08:44 PM
I have a form which has the following action code:

<form action="insert.php" method="post">

wherein "insert.php" states:

<?php

@mysql_connect("localhost","boundby_jennifer","********");
@mysql_select_db("boundby_memrevs") or die( "Unable to select database");


$query INSERT INTO MemberReviews VALUES (",'$Memb_name','$BookName' , '$Author','$Grade','$Review')";
mysql_query($query);

mysql_close();

?>

The purpose of the form is to allow members to input their own book reviews. Have the date inputted into the Mysql database that i have created and then output the information onto a sortable database.

So far, the form looks good, but when the 'submit' button is pushed, it goes to the input.php page. I get a "page cannot be found" error.

When I go to look at the database there is no data.

The second problem that i have is creating the code to publish the 5 field data. So far, I have:

<?
$username="*******";
$password="*********";
$database="boundby_memrevs";

@mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * FROM MemberReviews";
SELECT * FROM MemberReviews ORDER BY Author ASC
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Member Reviews</center></b><br><br>";

$i=0;
while ($i < $num) {

$Memb_Name=mysql_result($result,$i,"memb_name");
$Book=mysql_result($result,$i,"book");


I am probably totally screwed up and would appreciate all the advice given or a place where someone who is not very php literate could go and read up. Thanks in advance

Jennifer

Regor
08-20-2002, 09:25 PM
Jennifer,

I found the post below from "David", and the tutorial he refers to is very handy. It walks you through the whole procedure, to include code. You may notice something you missed, or . . . .

(beggining of David's quote) "There is a tutorial on my site:
http://www.freewebmasterhelp.com/tutorials/phpmysql/
which will take you through the creation of a contact management system, which allows contacts to be added and displays the result in a table. Its actually quite close to what you are wanting to do, and I expect that after reading through the tutorial you would be able to do what you are looking for quite easily.

Hope that helps.

__________________
Free Webmaster Help - Everything a webmaster needs - for free
Free-Webhosting.info - Free web hosts reviewed and rated
Script Avenue - Visitor-rated scripts directory
Gowansnet - Web professionals' portal" (end of David's quote)

Good luck Regor


"

adamfitch
09-02-2002, 01:57 PM
Jennifer, IRC is a great place to talk 1:1 with other PHP coders, I'd say at least 95% of them use MySQL as well. I am regular in #php on DALnet, EFnet is another great server.

in your insert.php:
$result = mysql_query("INSERT INTO sometable (column1, column2, column3) VALUES ('$var1', '$var2', '$var3') or exit("could not insert into the database");


on your second script:
$query = "SELECT * FROM MemberReviews ORDER BY Author ASC";
$result=mysql_query($query) or exit("Error - $query");
$num=mysql_num_rows($result);

if ($num) {
echo "There are $num entries <BR>";
while ($a = mysql_fetch_array($result)) {
echo $a['column1'] ." - ". $a['column2'] ."<BR>";
}
}


this is a bit general but hopefully it will help you. You were setting up your $query improperly in both scripts, and in the 2nd script the function is mysql_num_rows
-Adam