Jump to content

Recommended Posts

I'm clueless...the data isn't inserting into the database and it's not showing any errors. Any ideas?

 

<?php
case 'new':
	if(isset($_POST['submit'])) {
		$newusername = $_POST['newusername'];
		$newpassword = $_POST['newpassword'];
		$createaccount = "INSERT INTO tbl_users values ('$newusername','$newpassword')" or die(mysql_error());
		$result = mysql_query($account);
		echo "<p>Go back to the account viewer by clicking <a href=\"show_ids.php\">here</a></p>";
	} else { 
		echo "<h1>New Account</h1>
		<form action=\"crud.php?action=new\" method=\"post\">
		<table>
			<tr>
				<td>Username:</td>
				<td><input type=\"text\" name=\"newusername\" size=\"20\"></td>
			</tr>
			<tr>
				<td>Password:</td>
				<td><input type=\"password\" name=\"newpassword\" size=\"20\"></td>
			</tr>
			<tr>
				<td><input type=\"submit\" name=\"submit\" value=\"Register\"></td>
			</tr>
			</form>
		</table>";
		}
	break;
?>

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/53493-data-not-being-inserted/
Share on other sites

I've edited your code a little. But it's mostly the same.

 

You're query variable was not the same name as the mysql_query() result.

 

<?php
  if(isset($_POST['submit']))
   {
    $newusername = $_POST['newusername'];
    $newpassword = $_POST['newpassword'];
    $createaccount = "INSERT INTO `tbl_users` VALUES('$newusername','$newpassword')" or die(mysql_error());
    $result = mysql_query($createaccount); //this was $account and not $createaccount
    echo "<p>Go back to the account viewer by clicking <a href=\"show_ids.php\">here</a></p>";
   }
  else
   { 
   echo "<h1>New Account</h1>
   <form action=\"crud.php\" method=\"post\">
   <table>
    <tr>
     <td>Username:</td>
     <td><input type=\"text\" name=\"newusername\" size=\"20\"></td>
    </tr>
    <tr>
     <td>Password:</td>
     <td><input type=\"password\" name=\"newpassword\" size=\"20\"></td>
    </tr>
    <tr>
     <td><input type=\"submit\" name=\"submit\" value=\"Register\"></td>
    </tr>
    </form>
   </table>";
    }
?>

I noticed this too, you are adding the mysql_error to the wrong line of your script. you want the error to appear when you do the mysql_query call.

 

change

    $createaccount = "INSERT INTO `tbl_users` VALUES('$newusername','$newpassword')" or die(mysql_error());
    $result = mysql_query($createaccount);

 

to

 

<?php
    $createaccount = "INSERT INTO `tbl_users` VALUES('$newusername','$newpassword')";
    $result = mysql_query($createaccount) or die(mysql_error());
?>

ok, now i'm getting the MySQL syntax error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''tbl_users' VALUES ('gensilver91','tennis')' at line 1

 

hmm?

your mysql syntax is wrong, you don't put the names of the columns in your database

 

http://www.tizag.com/mysqlTutorial/mysqlinsert.php

 

"INSERT INTO 'tbl_users' (username, password) VALUES('$username', '$password')"

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.