PDA

Click to See Complete Forum and Search --> : Insert into Mysql Table


scoutt
Jul 15th, 2002, 02:15 PM
do waht you have but just make things to a varialbe. if you are getting those from a form then it would look like this. I wouldn't put the image in the DB as that will make it big fast, jut put the path in it or the name

<?php

$connection = mysql_connect ("localhost","stickman373","******");
mysql_select_db("stickman373_uk_db");
$result = mysql_query("INSERT INTO dvd (Title,Review,Image,Other) VALUES ('".$_REQUEST['Title']."','".$_REQUEST['Review']."','".$_REQUEST['image_name']."','"$_REQUEST['other']."' )
");

if(!result)
{
echo "INSERT unsuccessful: ", mysql_error();
exit;
}

else
{
print ("Thanks for submitting details.");
}

?>

stickman373
Jul 15th, 2002, 02:30 PM
how do I assign things to those variables? When i make a form to i set the submit button to the script?

scoutt
Jul 15th, 2002, 03:26 PM
easy, that is regular html. either you have it on the same page or on a different page it is all the same.

<form action="yourpage.php" method="post">
<input type=text name=Title>
<textarea name=Review rows="6" cols="30"></textarea>
<input type=text name=image>
<input type=text name=Other>
<input type=submit name=send value="Send Review">
</form>

the only problem is that if you want to upload an image you will have to add things to the form tag so you can. then you have to hve an upload script in your regular script.

see the name of each input? that is th evariable name you use on the $_REQUEST[] variable. make since?

stickman373
Jul 15th, 2002, 03:28 PM
thanks, that's what i needed, i'm just storing the URL for the images so it should be fine

stickman373
Jul 16th, 2002, 09:03 AM
i'm getting an error with the script

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in insert.php on line 6


<?php

$connection = mysql_connect ("localhost","stickman373","******");
mysql_select_db("stickman373_uk_db");

mysql_query("INSERT INTO dvd (Title,Review,Image,Other) VALUES ('.$_REQUEST['Title'].','.$_REQUEST['Review'].','.$_REQUEST['image'].','$_REQUEST['other'].' );

echo mysql_error();

?>


calling it with this html on a different page

<form action="insert.php" method="post">
<input type=text name=Title>
<textarea name=Review rows="6" cols="30"></textarea>
<input type=text name=image>
<input type=text name=Other>
<input type=submit name=send value="Send Review">
</form>

cpradio
Jul 16th, 2002, 09:14 AM
you forgot the double quotes in this statement:
mysql_query("INSERT INTO dvd (Title,Review,Image,Other) VALUES ('".$_REQUEST['Title']."',
'".$_REQUEST['Review']."','".$_REQUEST['image']."','".$_REQUEST['other']."')");

stickman373
Jul 16th, 2002, 09:23 AM
now i get this:

Parse error: parse error in insert.php on line 6

cpradio
Jul 16th, 2002, 09:24 AM
I missed the quote at the very end right after the last .

stickman373
Jul 16th, 2002, 09:33 AM
you edited the code in you post above right? i tried it again and i still get Parse error: parse error in insert.php on line 6 what am i doing wrong :(

stickman373
Jul 16th, 2002, 09:33 AM
sorry double post read above ;)

cpradio
Jul 16th, 2002, 09:38 AM
Try it again, a . (period) was missing.

stickman373
Jul 16th, 2002, 09:50 AM
almost there, what is wrong on line 1 ;)

You have an error in your SQL syntax near '' at line 1 :(

cpradio
Jul 16th, 2002, 10:01 AM
put a parenthesis after the last '

stickman373
Jul 16th, 2002, 10:13 AM
thanks it works