Jump to content

Recommended Posts

i could connect to the database and i dod nothing but to go through privileges in phpmyadmin by selecting privileges of the data base i design and by using the icon (action) it gave me a page to edit user i selected all check boxes mentioned in the global privileges then pressed go and for resource limits i read a note that said  setting these options to zero removes the limit

i set then to 1

and by using the connection function i could connect to the data base

 

<?php
$connectdb = mysql_connect('localhost','root','') or die("not connected");
$selectdb = mysql_select_db("koora", $connectdb);

if($selectdb)
{

echo "ok you,re now connected to table   ";
}else die("couldn,t connect to the database");
when refreshing my page it showed a message that said 
ok you,re now connected to table

but i got another problem which is by using this form 


<form action="admins.php" method='post'>
<table align="center" valign="center">
<tr>
<td>
Admin,s name: </td>
<td><input type="text" name="adminname" /><br /></td></tr>
<td>Admin,s Password: </td>
<td><input type="password" name="adminpassword" /></td></tr>
<td><input type="submit" value="Add New Admin" /></td></tr>

</form> 
</tr>
</table> to enter user name and password and by using the following code to get the data to the page the form directs to 

$admin = $_POST['adminname'];    
$password = $_POST['adminpassword'];   

if($admin&&$password){
   
mysql_query("INSERT INTO 'admin'('','admin','password')
VALUES('','$admin','$password');");
echo "admin was added";
}else
die("not added");

 

every time i enter a name and password to the text box and press enter it shows the message that admin was added and by checking the table which data are entered and stored i find nothing was added and the table is empty

i guess that this problem is because of something wrong with the database may be something with settings or some like that

i need your help with this problem

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/224896-problem-with-mysql-need-your-help/
Share on other sites

Friends

i,m having something wrong with mysql database

first i tried to connect to the database but i couldn,t i posted such problem and someone advised me to go to privileges of the database and i did what he said then i succesfully connected to it and after connection i established a form

 

<form action="admins.php" method='post'>
<table align="center" valign="center">
<tr>
<td>
Admin,s name: </td>
<td><input type="text" name="adminname" /><br /></td></tr>
<td>Admin,s Password: </td>
<td><input type="password" name="adminpassword" /></td></tr>
<td><input type="submit" value="Add New Admin" /></td></tr>

</form> 
</tr>
</table>

 

then i established the page admins.php to direct the data to it

i tried to add obtained data to the table by this code

 

<?php
$admin = $_POST['adminname'];    
$password = $_POST['adminpassword'];   

if($admin&&$password){
   
mysql_query("INSERT INTO 'admin'('','admin','password')
VALUES('','$admin','$password');");
echo "admin was added";
}else
die("not added");

 

by entering the name and password to the form textboxes and press the form button it shows the message that admin was added  and by checking the table i find that there is nothing was added and it is as it was created include no data at all

how can i solve this problem

 

MOD Edit: code tags added.

mysql_query("INSERT INTO 'admin'('','admin','password')
VALUES('','$admin','$password');");

:o

 

OK, when using INSERT you need to use the following syntax :

 INSERT INTO [table name] (field_name_1, field_name_2...) VALUES (value1, value2...)

so:

1. you don't need to declare auto increment fields in the INSERT, and certainly don't declare them as an empty values

2. you don't need to use quotes or back ticks to enclose table names or field names that have no spaces in them.

3. always always have an or die statement when debugging sql queries that includes the mysql error as an output.

 

So, that said, you should end up with something like this :

$query = 'INSERT INTO admin (admin, password) VALUES (\''.$admin.'\', \''.$password.'\');
mysql_query($query) or die (mysql_error());

 

yes it is but that topic was about the database connection and it was solved but this topic here is about adding data to the database so i thought that it is because of the phpmyadmin settings or something like that this is why i posted this topic here and you see it is not the same one you told me about

You continued that thread to include this problem, then only 13 minutes later, you posted this one. The other thread has received at least one response, so I'm going to split it off that thread and add it here.

 

Also, when you post code, please enclose it in the forum's

 . . . 

BBCode tags for readability.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.