...

View Full Version : Data not going into database



2y2d
08-09-2007, 11:46 PM
once the user enters data and clicks submit the data doesnt go onto the database i dont know whats wrong. Heres my code


1 <?php
2 ob_start();
3 $host="localhost"; // Host name
4 $username="****"; // Mysql username
5 $password="*****"; // Mysql password
6 $db_name="*****"; // Database name
7 $tbl_name="MainT"; // Table name
8
9 // Connect to server and select databse.
10 mysql_connect("$host", "$username", "$password")or die("cannot connect");
11 mysql_select_db("$db_name")or die("cannot select DB");
12
13 $myusername1 = $_POST['myusername1'];
14 $mypassword1 = $_POST['mypassword1'];
15 $mymail = $_POST['mymail'];
16 $D1 = $_POST['D1'];
17
18 //insert the values
19 $mysql_query = "INSERT INTO `MainT` VALUES (\'\',\'$myusername1\',\'$mypassword1\',\'$mymail\',\'D1\',\'1000\',\'1\',\'0\',\'0\',\'0\',\'0\',\' 0 \',\'0\',\'0\',\'0\',\'20\',\'5000\')";
20 echo "<font face='Verdana' size='2' color=green>Welcome, You have successfully signed up<br><br><a href=index.php>Click here to login</a><br></font>";
21
22 echo "Your name and password have been submitted into our database :)";
23 ob_end_flush();
24 ?>

I dont get any errors but does show the "Welcome, You have successfully signed up"but doesnt add the data and i know it does connect successfully because i can login with data that is already on my db any help would be great.

SteveBach
08-10-2007, 01:29 AM
Looks like you're missing the function call to actually execute the query you constructed. Try:


mysql_query($mysql_query);

Also, you don't need to escape the single quotes in your query, since you've got double quotes around the entire text.

2y2d
08-10-2007, 02:59 AM
Looks like you're missing the function call to actually execute the query you constructed. Try:


mysql_query($mysql_query);

Also, you don't need to escape the single quotes in your query, since you've got double quotes around the entire text.

that goes in line 20 yer ? If so its still not working, would it be the single quotes ?

2y2d
08-10-2007, 09:12 PM
An Update - i added ("Add Error") so i would know if the error was before or after, I was wondering if it could be the data "D1" as this is a drop down menu and i dont think its coded right so this might be adding an invalid data type or wouldnt that matter ?



mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$myusername1 = $_POST['myusername'];
$mypassword1 = $_POST['mypassword'];
$mymail = $_POST['mymail'];
$D1 = $_POST['D1'];

<?php
$mysql_query = "INSERT INTO MainT VALUES = (\'\',\'$myusername\',\'$mypassword\',\'$mymail\',\'D1\',\'1000\',\'1\',\'0\',\'0\',\'0\',\'0\',\'0\ ',\'0\',\'0\',\'0\',\'20\',\'5000\',\'0\',\'0\',\'0\')";
mysql_query($mysql_query)or die("Add Error");
echo "<font face='Verdana' size='2' color=green>Welcome, You have successfully signed up<br><br><a href=index.php>Click here to login</a><br></font>";

echo "Your name and password have been submitted into our database :)";
ob_end_flush();
?>

anarchy3200
08-10-2007, 09:16 PM
Try changing your query so that you dont escape the single quotes as follows:


$mysql_query = "INSERT INTO MainT VALUES = ('',$myusername,$mypassword,$mymail,'D1','1000','1','0','0','0','0','0','0','0','0','20','5000','0', '0','0')";


Also is D1 meant to be a variable, if so in the insert you have missed the $ before it, as is it will just use D1 as the value which i assume you do not want therefore should be as follows:


$mysql_query = "INSERT INTO MainT VALUES = ('',$myusername,$mypassword,$mymail,$D1,'1000','1','0','0','0','0','0','0','0','0','20','5000','0',' 0','0')";


Last point, just wondering, are you using the object buffer for a reason?

2y2d
08-10-2007, 09:28 PM
Last point, just wondering, are you using the object buffer for a reason?

I used the Object Buffer because it said somewhere on another site that it was best to use it when using php5 (to be honest i dont know what the object buffer does) should i not use it ?

Still doesnt work :( lol

masterofollies
08-10-2007, 09:40 PM
You can try setting it up differently like this

$query = doquery("INSERT INTO {{table}} SET id='',regdate=NOW(),verify='1',username='$username',password='$password',mymail='$mymail',d1='$d1',n ame='$name',gender='$gender',country='$country',msn='$msn',aim='$aim',yim='$yim',icq='$icq'", "MainT") or die(mysql_error());

2y2d
08-10-2007, 09:49 PM
thats more confusing lol so in that one it defines as it adds ? :S
can i not change my $mysql_query to the doquery ? lol im totally lost and probably talking rubbish now :S lol
ill give it a go anyway ill just copy what ive got to a notepad first, anything is better than not rying lol ill keep you posted if it works

=
Fatal error: Call to undefined function: doquery()

masterofollies
08-10-2007, 09:56 PM
You will have to set it with your own strings and all. But that line updates the user in that table.

2y2d
08-10-2007, 09:58 PM
You will have to set it with your own strings and all. But that line updates the user in that table.

What do i define it as ? the error says - Fatal error: Call to undefined function: doquery()

argothian
08-10-2007, 11:33 PM
Try this:
$mysql_query = "INSERT INTO MainT VALUES = ('','$myusername','$mypassword','$mymail','$D1','1000','1','0','0','0','0','0','0','0','0','20','500 0','0','0','0')";
mysql_query($mysql_query);

2y2d
08-10-2007, 11:49 PM
Try this:
$mysql_query = "INSERT INTO MainT VALUES = ('','$myusername','$mypassword','$mymail','$D1','1000','1','0','0','0','0','0','0','0','0','20','500 0','0','0','0')";
mysql_query($mysql_query);

Nope didnt work either i cant see anything wrong with it though all my sql login details are fine, everything is defined that needs to be, ive got every column covered in the query :S its weird.
Is there any other way of adding data to my table ?

argothian
08-10-2007, 11:58 PM
Heh, I looked a bit closer at the statement, there's a stray =, try this:

$mysql_query = "INSERT INTO MainT VALUES ('','$myusername','$mypassword','$mymail','$D1','1000','1','0','0','0','0','0','0','0','0','20','500 0','0','0','0')";
mysql_query($mysql_query);If it still doesn't add the entry add this line to get the error:

echo mysql_error();

2y2d
08-11-2007, 12:15 AM
Heh, I looked a bit closer at the statement, there's a stray =, try this:

$mysql_query = "INSERT INTO MainT VALUES ('','$myusername','$mypassword','$mymail','$D1','1000','1','0','0','0','0','0','0','0','0','20','500 0','0','0','0')";
mysql_query($mysql_query);If it still doesn't add the entry add this line to get the error:

echo mysql_error();

After 4 long days of looking at the same little bit of code its now sorted lol :D thank you very much.
All help is greatly appreciated ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum