Page 1 of 2
can some1 check wots wrong with this script?
Posted: Sun May 05, 2002 1:56 am
by Biglines
Code: Select all
<?
if ( $title == "" )
{
$dbconn = mysql_connect("localhost", "*****", "*****");
$result = mysql_select_db("ringtones", $dbconn);
$sql="INSERT INTO ringtones (title, name, email, nokcode, nokcomp, nokkey) VALUES ($title,
$naameee, $email, $nokcode, $nokcomp, $nokkey)";
mysql_query($sql);
?>
Data has been sent
<?
}
else
{
?>
<form method="post" action="db.php">title
<input type="text" name="title">name
<input type="text" name="name">email
<input type="text" name="email">code
<input type="text" name="nokcode">comp
<input type="text" name="nokcomp">key
<input type="text" name="nokkey">
<input type="submit" name="submit">
<?
}
?>
Posted: Sun May 05, 2002 3:50 am
by mikeq
You don't say what error you get, but I'm guessing no records get inserted, correct?
Any fields which are expected to be characters must be enclosed in single quotes '
so if $title, $naameee and $email are expected to be strings then:
$sql="INSERT INTO ringtones (title, name, email, nokcode, nokcomp, nokkey) VALUES ('$title', '$naameee', '$email', $nokcode, $nokcomp, $nokkey)";
Mike
Posted: Sun May 05, 2002 6:15 am
by Biglines
tnx
Posted: Sun May 05, 2002 6:16 am
by Biglines
also needed to change the == into !=, cuz otherwise it always sents empty strings

Posted: Sun May 05, 2002 6:19 am
by Biglines
<span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> still doesnt work
Posted: Sun May 05, 2002 6:29 am
by Biglines
i changed it to this:
Code: Select all
<?
if ( $title != "" )
{
$title = "d";
$naameee = "d";
$email = "d";
$nokcode = "d";
$nokcomp = "d";
$nokkey = "d";
$dbconn = mysql_connect("localhost", "***", "***");
$result = mysql_select_db("ringtones", $dbconn);
$sql="INSERT INTO ringtones (title, name, email, nokcode, nokcomp, nokkey) VALUES ('$title', '$naameee', '$email', '$nokcode', '$nokcomp', '$nokkey')";
mysql_query($sql);
?>
Data has been sent
<?
}
else
{
?>
<form method="post" action="db.php">title
<input type="text" name="title">name
<input type="text" name="name">email
<input type="text" name="email">code
<input type="text" name="nokcode">comp
<input type="text" name="nokcomp">key
<input type="text" name="nokkey">
<input type="submit" name="submit">
<?
}
?>
but nothing is in database
example is:
http://www.biglines.nl/db.php
source is:
http://www.biglines.nl/db.phps
Posted: Sun May 05, 2002 7:43 am
by leenoble_uk
Code: Select all
<?
if ( $title != "" )
{
$dbconn = mysql_connect("localhost", "*****", "*****");
$result = mysql_select_db("ringtones", $dbconn);
$sql="INSERT INTO ringtones (title, name, email, nokcode, nokcomp, nokkey) VALUES ('$title', '$name', '$email', '$nokcode', '$nokcomp', '$nokkey')"; //added quotes around values & $naamee didn't match the field names.
mysql_query($sql, $dbconn); // added $dbconn to mysql_query
?>
Data has been sent
<?
}
else
{
?>
<form method="post" action="db.php">
title<input type="text" name="title">
name<input type="text" name="name">
email<input type="text" name="email">
code<input type="text" name="nokcode">
comp<input type="text" name="nokcomp">
key<input type="text" name="nokkey">
<input type="submit" name="submit">
</form> <!-- added /form tag -->
<?
}
?>
I hope that's all there is.
Posted: Sun May 05, 2002 7:51 am
by jason
Biglines wrote:$sql="INSERT INTO ringtones (title, name, email, nokcode, nokcomp, nokkey) VALUES ('$title', '$naameee', '$email', '$nokcode', '$nokcomp', '$nokkey')";
mysql_query($sql);
?>
Data has been sent
<?
}
else
{
?>
Two things I want you to do. Use $_POST['title'], $_POST['naameee'], and the rest of them, instead of $title, $naameee, etc.
Also, add this line right have you do mysql_query();
Posted: Sun May 05, 2002 10:33 am
by Biglines
now i did this:
Code: Select all
<?
if ( $title != "" )
{
$dbconn = mysql_connect("localhost", "***", "***");
$result = mysql_select_db("ringtones", $dbconn);
$sql="INSERT INTO ringtones (title, name, email, nokcode, nokcomp, nokkey) VALUES ($_POSTї'title'], $_POSTї'name'], $_POSTї'email'], $_POSTї'nokcode'], $_POSTї'nokcomp'], $_POSTї'nokkey'])";
mysql_query($sql);
echo mysql_error();
?>
Data has been sent
<?
}
else
{
?>
<form method="post" action="db.php">title
<input type="text" name="title">name
<input type="text" name="name">email
<input type="text" name="email">code
<input type="text" name="nokcode">comp
<input type="text" name="nokcomp">key
<input type="text" name="nokkey">
<input type="submit" name="submit">
<?
}
?>
and i get this error:
Code: Select all
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /usr/local/psa/home/vhosts/biglines.nl/httpdocs/db.php on line 7
Posted: Sun May 05, 2002 11:05 am
by jason
Biglines: Why not and do some error checking. The error is a very simple error.
Code: Select all
$sql="INSERT INTO ringtones (title, name, email, nokcode, nokcomp, nokkey) VALUES ($_POSTї'title'], $_POSTї'name'], $_POSTї'email'], $_POSTї'nokcode'], $_POSTї'nokcomp'], $_POSTї'nokkey'])";
That is where the error is.
Use this:
Code: Select all
$sql="INSERT INTO ringtones (title, name, email, nokcode, nokcomp, nokkey) VALUES ($_POSTїtitle], $_POSTїname], $_POSTїemail], $_POSTїnokcode], $_POSTїnokcomp], $_POSTїnokkey])";
Posted: Sun May 05, 2002 11:19 am
by sam
Code: Select all
$sql="INSERT INTO ringtones (title, name, email, nokcode, nokcomp, nokkey) VALUES ($_POSTїtitle], $_POSTїname], $_POSTїemail], $_POSTїnokcode], $_POSTїnokcomp], $_POSTїnokkey])";
Should give you warnings "undefined constants will assume subset... blah" so you need to quote those subsets:
Code: Select all
$sql="INSERT INTO ringtones (title, name, email, nokcode, nokcomp, nokkey) VALUES ('".$_POSTї"title"]."','". $_POSTї"name"]."','". $_POSTї"email"]."','". $_POSTї"nokcode"]."','". $_POSTї"nokcomp"]."','". $_POSTї"nokkey"]."')";
Should work now...
Cheers Sam
Jes, prutser... :p
Posted: Sun May 05, 2002 11:42 am
by rowdy
Hey Jes,
Een van de eerste dingen die je moet doen is leren je code goed te structureren. Dan is alles veel makkelijker. maar dat is maar een tip...
Om te beginnen... Een van je grote fouten is:
Code: Select all
$dbconn = mysql_connect("localhost", "*****", "*****");
$result = mysql_select_db("ringtones", $dbconn);
Wat doe je hier? Een databaseconnectie in een variabele proppen. Daarna ga je een database selecteren. Bij het selecteren maak je die databaseverbinding aan, en stop je de selectieprocedure weer in een variabele.
En vervolgens doe je niets meer met die variabele!
Dus alles wat je op databasegebied probeert te doen geeft errors. Hieronder je code die zou moeten werken, maarre, controleer je database zelf even, en controleer hem de volgende dingen:
- De tabelnaam (Hoofdlettergevoelig!!)*
- De tabelvelden zelf (Hoofdlettergevoelig!!)*
- De soorten van de tabelvelden niet dat je een string in een int probeert te stampen; dat lukt nie...
Gebruik bijvoorbeeld om te testen eens gewoon voor alles de soort 'TEXT'.
* Als dit niet helemaal klopt krijg je allemaal hele wazige en onduidelijke fouten die je niet thuis kunt brengen...
Code: Select all
<?
if(!$title){
mysql_connect("localhost", "*****", "*****");
mysql_select_db("ringtones");
$sql = " INSERT INTO ringtones (title, name, email, nokcode, nokcomp, nokkey)";
$sql .= "VALUES ('$title', '$naameee', '$email', '$nokcode', '$nokcomp', '$nokkey')";
result = mysql_query( $sql );
if($result){
echo "Data sent... ";
}
}
else{
?>
<form method="post" action="db.php">title
<input type="text" name="title">name
<input type="text" name="name">email
<input type="text" name="email">code
<input type="text" name="nokcode">comp
<input type="text" name="nokcomp">key
<input type="text" name="nokkey">
<input type="submit" name="submit">
<?
}
?>
Posted: Sun May 05, 2002 12:49 pm
by Biglines
Code:
$sql="INSERT INTO ringtones (title, name, email, nokcode, nokcomp, nokkey) VALUES ($_POST[title], $_POST[name], $_POST[email], $_POST[nokcode], $_POST[nokcomp], $_POST[nokkey])";
Should give you warnings "undefined constants will assume subset... blah" so you need to quote those subsets:
Code:
$sql="INSERT INTO ringtones (title, name, email, nokcode, nokcomp, nokkey) VALUES ('".$_POST["title"]."','". $_POST["name"]."','". $_POST["email"]."','". $_POST["nokcode"]."','". $_POST["nokcomp"]."','". $_POST["nokkey"]."')";
Should work now...
Cheers Sam
i get this error:
Code: Select all
No Database Selected Data has been sent
Posted: Sun May 05, 2002 12:56 pm
by Biglines
new php code, still not working, why????
Code: Select all
<?
if ( $title != "" )
{
$dbconn = mysql_connect("localhost", "****", "****");
$result = mysql_select_db("ringtones", $dbconn);
$sql="INSERT INTO ringtones (title, name, email, nokcode, nokcomp, nokkey) VALUES ('".$_POSTї"title"]."','". $_POSTї"name"]."','". $_POSTї"email"]."','". $_POSTї"nokcode"]."','". $_POSTї"nokcomp"]."','". $_POSTї"nokkey"]."')";
mysql_query($sql);
echo mysql_error();
?>
Data has been sent
<?
}
else
{
?>
<form method="post" action="db.php">title
<input type="text" name="title">name
<input type="text" name="name">email
<input type="text" name="email">code
<input type="text" name="nokcode">comp
<input type="text" name="nokcomp">key
<input type="text" name="nokkey">
<input type="submit" name="submit">
<?
}
?>
Posted: Fri May 10, 2002 12:07 pm
by Biglines
can some1 help me???