Jump to content

"DAY 2", "1 book read" and STILL showing ERROR, Please Help?


Modernvox

Recommended Posts

Hello Guyz,

 

I am almost through O'reilly's book on php and mysql.

VALUES will not enter DB?

 

First my form:

<form action="reg_success.php" method="POST">

<table>
<tr>    <td><font face= "tahoma" size= "2">Name</font></td>
<td><input type= "text" name= "regname" size= "35" /></td>
<td><br><br></td>
</tr>
<tr>   <td><font face= "tahoma" size= "2">State</font></td>
<td><input type= "text" name= "regstate" size= "35" /></td>
<td><br><br></td>
</tr>
</tr>   <td><font face= "tahoma" size= "2">City</font></td>
<td><input type="text" name= "regcity" size= "35" /></td>
<td><br><br></td>
</tr>
<tr>   <td><font face= "tahoma" size= "2">Email</font></td>
<td><input type="text" name= "regemail" size= "35" /></td>
</tr>
<tr>   <td><br></td>
</tr>
<tr>   <td><br></td>
</tr>
<tr>   <td><br></td>
</tr>
<tr>   <td><br></td>
</tr>
<tr>  <td><font face= "tahoma" size= "2">Choose a username</font></td>
<td><input type= "text" name= "username" size "35"/></td>  
</tr> 
<tr> <td><br></td> </tr>

<tr>   <td><font face= "tahoma" size= "2">Choose a password</font></td>
<td><input type= "pass" name= "password" size "35"/></td>  
</tr>
<tr>   <td><font face= "tahoma" size= "2">Confirm password</font></td>
<td><input type= "pass" name= "confirmpass" size "35"/></td>  
</tr>  
<tr> <td><br></td> </tr>
<tr> <td><br></td> </tr>
</table>


<center><input type="submit" name="submit" value= "register" /></center>
</form></font>

 

and now my process registration page script...

<php
if ((isset($_POST['submit'])) && (!empty($_POST['regname'])) 
&& (!empty($_POST['regstate'])) && (!empty($_POST['regcity'])) 
&& (!empty($_POST['regemail'])) && (!empty($_POST['username']))
&&  (!empty($_POST['password'])) && (!empty($_POST['confirmpass'])))
{
$reg_name= $_POST['regname'];
$reg_state= $_POST['regstate'];
$reg_city= $_POST['regcity'];
$reg_email= $_POST['regemail'];
$reg_username= $_POST['username'];
$reg_password= $_POST['password'];
$reg_confirmpass= $_POST['confirmpass'];
$database= register;

$dbx =mysql_connect('localhost', 'root', ""); 
if (!$dbx)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($database);
if (!mysql_select_db)
{
    die ("Could not select the database: <br />" . mysql_error());
}

      $insert_query = "INSERT INTO users ('regname', 
                                          'regstate', 
                                          'regcity', 
                                          'regemail', 
                                          'username', 
                                          'password', 
                                          ) 
                                          VALUES 
                                          ('$reg_name','$reg_state''$reg_city','$reg_email','$reg_username', '$reg_password')"; 
                                         
                                    
                                          
                                
                                     
                                          );

$result= mysql_query($insert_query);
if (!$result){
     die ("Could not query the database: <br />". mysql_error());
mysql_close)$connection)

?>

 

 

No matter what I do I keep getting this error:

" . mysql_error()); } $insert_query = "INSERT INTO users ('regname', 'regstate', 'regcity', 'regemail', 'username', 'password', ) VALUES ('$reg_name','$reg_state''$reg_city','$reg_email','$reg_username', '$reg_password')"; ); $result= mysql_query($insert_query); if (!$result){ die ("Could not query the database:
". mysql_error()); mysql_close)$connection)

 

YOUR HELP IS GREATLY APPRECIATED ON THIS MATTER..

 

Just looking at your code I can see multiple syntax errors

First is line 1

<php

That is an invalid tag, It should be <?php

 

Line 21 - 22 is incorrect

mysql_select_db($database);
if (!mysql_select_db)

 

It should be

$db_selected = mysql_select_db($database);

if (!$db_selected)

 

Line 41

                                          );

I don't know what that is? Delete it

 

You have a missing closing brace } after line 45

44. if (!$result){
45.     die ("Could not query the database: <br />". mysql_error());
46. }

 

Line 46 is incorrect

mysql_close)$connection)

It should be

mysql_close($dbx);

 

Maybe you should get some sleep? :P

 

lol... No what i did was mismatch the code from the book with mine and messed it up..Anyhow, I made all requested changes and now I get an unexpected unexpected $end.

 

updated code

<?php
if ((isset($_POST['submit'])) && (!empty($_POST['regname']))
&& (!empty($_POST['regstate'])) && (!empty($_POST['regcity']))
&& (!empty($_POST['regemail'])) && (!empty($_POST['username']))
&&  (!empty($_POST['password'])) && (!empty($_POST['confirmpass'])))
{
$reg_name= $_POST['regname'];
$reg_state= $_POST['regstate'];
$reg_city= $_POST['regcity'];
$reg_email= $_POST['regemail'];
$reg_username= $_POST['username'];
$reg_password= $_POST['password'];
$reg_confirmpass= $_POST['confirmpass'];
$database= register;

$dbx =mysql_connect('localhost', 'root', "");
if (!$dbx)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db($database);
if (!$db_selected)
{
    die ("Could not select the database: <br />" . mysql_error());
}

      $insert_query = "INSERT INTO users ('regname',
                                          'regstate',
                                          'regcity',
                                          'regemail',
                                          'username',
                                          'password',
                                          )
                                          VALUES
                                          ('$reg_name','$reg_state''$reg_city','$reg_email','$reg_username', '$reg_password')";
                         
$result= mysql_query($insert_query);
if (!$result){
     die ("Could not query the database: <br />". mysql_error());
}
mysql_close($dbx);


?>

 

Ok i left out the if's closing tab at the bottom noe I have:

Could not query the database:

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 ''regname', 'regstate', ' at line 1

The ID field doesn't count as a VALUE position , right?

In other words that field doesn't screw up the position the VALUES are inserted?

 

I'm positive I am using the wrong syntax to input this data because I'm using variables. Maybe quotes, double quotes, semicolons, etc.. Is there a good tutorial on these syntax characters?

When I change the INSERT INTO users from 'regname'  etc..  to "regname" (double quotes) I get this error now:

Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\IWannaJam\cool.php on line 27

 

What am I suppose to be using here for syntax?

 

Here's my DB order

Fields:

id

regname

regstate

regcity

regemail

username

password

They shouldn't be enclosed in ANY quotes. If anything you can use backticks ``, but they're optional.

 

Yeah..Took them all out a few minutes ago and it worked. Could U or someone direct me to a great tutorial on syntax, because I came across quite a few pages online showing DB queries with quotes around COLUMN keywords and this book I have been reading I (finally just found the proper example, because all the previous examples were just showing how to input values and not match COLUMNS with VALUES)

Where is a good place to learn all of PHP' syntax?

 

Thanks to everyone who posted on this topic.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.