Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

please help me with my code.

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

please help me with my code.

Postby soloboi » Tue Jun 25, 2013 7:30 am

Hi. Im just learning database access with php and I would like to ask for help regarding my code. When I try to insert data into my mySQL database my code does not seem to work but I don't get any error messages when I try to run it. Here is my code:

Code: Select all
<?php
$host="localhost"; // Host name
$username="aleks"; // Mysql username
$password="09282009191"; // Mysql password
$db_name="User"; // Database name
$tbl_name="username"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

//username and password sent from form
If(isset($_POST['meusername'])){
   $myusername=$_POST['meusername'];
}
If(isset($_POST['mepassword'])){   
   $mypassword=$_POST['mepassword'];
}

//Update tables
$sql="INSERT $tbl_name VALUES ($myusername, $mypassword) ";
mysql_query($sql);

echo "Welcome, ";
echo $myusername;
echo ". You are now registerd!";
?>


after running the code I try to check my database tables but no records are added.
Hope someone could help me with this. Thanks.
soloboi
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Jun 25, 2013 7:17 am

Re: please help me with my code.

Postby soloboi » Thu Jun 27, 2013 7:31 pm

Hopefully someone can help me resolve this problem. Thanks in advance... :help:
soloboi
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Jun 25, 2013 7:17 am

Re: please help me with my code.

Postby johnj » Thu Jun 27, 2013 8:25 pm

change your mysql_connect statement to $link = $mysql_connect(...) and then after your mysql_query add this line , echo mysql_errno($link) . ": " . mysql_error($link). "\n";
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: please help me with my code.

Postby soloboi » Wed Jul 03, 2013 7:31 pm

Thanks for the reply. I solved the problem. :D
soloboi
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Jun 25, 2013 7:17 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron