Web Hosting Talk







View Full Version : Bare with me I am learning php :)


obviousl
11-04-2004, 07:11 PM
Hey all,

I have made my first php posting to mysql script, but alas it's not working. Was wondering if you can pick out the problem:

this is my action.php :

<?php
// Connecting, selecting database
$link = mysql_connect('localhost', 'username', 'password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('database') or die('Could not select database');
$tablename = table;

// Performing SQL posting
$result =mysql_query("INSERT INTO $tablename(
'gender','name','age','height','hair','eyes','from','city','suburb',
'type','sign','f.movie','f.music','f.food',
'message','seek','password','email') VALUES ('".$_POST["gender"]."',
'".$_POST["name"]."','".$_POST["age"]."',
'".$_POST["height"]."','".$_POST["hair"]."','".$_POST["eyes"]."',
'".$_POST["from"]."','".$_POST["city"]."','".$_POST["suburb"]."',
'".$_POST["type"]."','".$_POST["sign"]."',
'".$_POST["f.movie"]."','".$_POST["f.music"]."','".$_POST["f.food"]."',
'".$_POST["message"]."','".$_POST["seek"]."','".$_POST["password"]."',
'".$_POST["email"]."')");

// Closing SQL link
mysql_close($link);
echo 'Posted successfully';
?>


Any idea why this doesn't post any information to my database?

Cheers,

Chris

xgoth3
11-04-2004, 07:48 PM
Well i see a parse error here:

$tablename = table;

Change it to:

$tablename = 'table';

add quotes.

obviousl
11-04-2004, 08:09 PM
Coolio cheers for that.
Will go try it out.

Chris

azizny
11-04-2004, 09:00 PM
Originally posted by xgoth3
Well i see a parse error here:



Change it to:

$tablename = 'table';

add quotes.

Thats not the error, it should work fine without the quote.

What is the error that it gives you,

try turning error_reporting to all

Peace,

orbitz
11-04-2004, 09:29 PM
$link = mysql_connect('localhost', 'username', 'password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('database') or die('Could not select database');

just make sure those line are correct....
did you have username, password, and database correct?

obviousl
11-04-2004, 10:43 PM
Ok trying something a bit more basic this time to just test things out:

test.php

<form action="testaction.php" method="POST">
Nickname: <input type="text" name="nickname"><br>
<INPUT type="submit">
</FORM>


testaction.php

<?php
// Connecting, selecting database
$link = mysql_connect('localhost', 'username', 'password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('testdb') or die('Could not select database');
$tablename = 'test';

// Performing SQL posting
$result =mysql_query("INSERT INTO $tablename(
'nickname') VALUES ('".$_POST["nickname"]."')");

// Closing SQL link
mysql_close($link);
echo 'Posted successfully';
?>


But alas it still won't post anything to the sql table.
Now after posting the data from test.php to testaction.php i receive both "posted successfully" echos.

So I am kind of stuck again :(
No Errors are reported :(

I have PHPBB running on the same server, so it's not a problem with the server / mysql.

Cheers for your input :)

Chris

tiamak
11-04-2004, 11:00 PM
$result = mysql_query("INSERT INTO $tablename (`nickname`) VALUES ('".$_POST["nickname"]."')") or die ('query error: '. mysql_error());



??????? :)
like for me field names should be in `` not in ' ' :)



(something out of topic below)

slackware+postfix here :D:D:D hehe nice to meet slack+qmail in the world dominated by redhats :D

obviousl
11-04-2004, 11:24 PM
Taimak,

Thanks heaps for your help ! All working now !!
See us slackware buddies look out for each other ;)

Chris

tiamak
11-04-2004, 11:28 PM
hehe no problem :)