Jump to content

[SOLVED] simple script cannot work


sungpeng

Recommended Posts


<?php

if($_POST[action]=="Submit")
{




include ("".$_SERVER['DOCUMENT_ROOT']."/housing/includes/config.php"); 






$loginname=$_POST[loginname];
echo "$loginname";
$insert_student="insert into users ('llid','loginname') values ('3','$loginname')"; 
mysql_query($insert_student) or die ("cannot insert");

   





?>



<?php }else{ ?>



                 
<?php include ("".$_SERVER['DOCUMENT_ROOT']."/housing/includes/header.php");  ?>

<html>

<head>

<title>Agents Register</title>

</head>

<body>

                 

                     <table width="400" align="center">
                    <br> <form name="form" action="<?php print $PHP_SELF ?>" onSubmit="return validate(this);" method="post">
                      

                         
                        <tr> 
                          <td width="35%">Loginname</td>
                          <td><input type="text" name="loginname" size="25"></td>
                        </tr>
                        
                         

                        <tr> 
                          <td align="center" colspan="2"><input type="submit" name="action" value="Submit"></td>
                        </tr>
                      </table>
                    </form>




          
</body>

</html>
<?php 
}
?>
    

 

Can anyone help, I don't know why simple script why cannot work? always show cannot insert

Link to comment
Share on other sites

first...state your problem, what exactly is happening that you don't want...then state what you do want..

 

but try this...you have many unnecessary <?php and ?> tags

 

<?php

if($_POST[action]=="Submit")
{


   

include ("".$_SERVER['DOCUMENT_ROOT']."/housing/includes/config.php"); 
      
$loginname=$_POST[loginname];
echo "$loginname";
$insert_student="insert into users ('llid','loginname') values ('3','$loginname')"; 
mysql_query($insert_student) or die ("cannot insert");

   
}else{ 



                 
include ("".$_SERVER['DOCUMENT_ROOT']."/housing/includes/header.php")}  
?>

<html>

<head>

<title>Agents Register</title>

</head>

<body>

                 

                     <table width="400" align="center">
                    <br> <form name="form" action="<?php print $PHP_SELF ?>" onSubmit="return validate(this);" method="post">
                     

                         
                        <tr>
                          <td width="35%">Loginname</td>
                          <td><input type="text" name="loginname" size="25"></td>
                        </tr>
                       
                         

                        <tr>
                          <td align="center" colspan="2"><input type="submit" name="action" value="Submit"></td>
                        </tr>
                      </table>
                    </form>




         
</body>

</html>

   

Link to comment
Share on other sites

and i dont see where you're connecting to your db

 

try this

 

$cxn = mysqli_connect($host,$user,$passwd,$dbname) or die("Couldn't connect");  
    
      
    
   $sql = "INSERT INTO users (llid, loginname) VALUES ('3','{$loginname}')";
   $result = mysqli_query($cxn,$sql)
          or die (mysqli_error($result)); 

Link to comment
Share on other sites

$result=mysql_query("insert into users (loginname) values ('$loginname')") or die (mysql_error($result));

 

error is "Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in signup.php on line 21"  What is it means?

 

 

Link to comment
Share on other sites


<?php

if($_POST[action]=="Submit")
{




include ("".$_SERVER['DOCUMENT_ROOT']."/housing/includes/config.php"); 




$loginname=$_POST[loginname];

echo "$loginname";


$result=mysql_query("insert into users (loginname) values ('$loginname')") or die (mysqli_error($result)); 


   





}else{ ?>



<html>

<head>

<title>Agents Register</title>

</head>

<body>

                 

                     <table width="400" align="center">
                    <br> <form name="form" action="<?php echo"$PHP_SELF"; ?>" method="post">
                      

                         
                        <tr> 
                          <td width="35%">Loginname</td>
                          <td><input type="text" name="loginname" size="25"></td>
                        </tr>
                        
                         

                        <tr> 
                          <td align="center" colspan="2"><input type="submit" name="action" value="Submit"></td>
                        </tr>
                      </table>
                    </form>




          
</body>

</html>
<?php 
}
?>




Link to comment
Share on other sites

"Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in signup.php on line 21" What is it means?

 

It means that you are trying to connect to your database WITHOUT a proper connection variable......

$result = mysqli_query($cxn,$sql)

 

quickest solution: Switch the parameters!

also...you don't need mysqli

 

and you can't call mysql_error() on mysqli connections...if I'm not mistaken....seems pretty logical too

 

 

using mysqli you'd have to connect like this

$cxn = new mysqli("localhost", "my_user", "my_password", "world");

Link to comment
Share on other sites

<?

$hostname = "localhost";
$username = "sgfai_winning";
$password = "heally";
$dbName = "sgfai_property"; 
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); 
mysql_select_db("$dbName") or die("Unable to select database"); 

?>

 

Hi zanus, is the above connection wrong?

Link to comment
Share on other sites

do this

 

$host="localhost";
$user="sgfai_winning";
$passwd = "heally";
$dbname = "sgfai_property";

$cxn = mysqli_connect($host,$user,$passwd,$dbname) or die("Couldn't connect");   

 

thatll connect you to the right db with the right username, password and you use $cxn in all your mysqli_queries as the first parameter..

like

 

$result = mysqli_query($cxn,$sql)

          or die (mysqli_error($result));

$sql will be your mysql query

 

 

Link to comment
Share on other sites


<?php

if($_POST[action]=="Submit")
{



$hostname = "localhost";
$username = "sgfai_winning";
$password = "helly";
$dbName = "sgfai_property"; 
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); 
mysql_select_db("$dbName") or die("Unable to select database");


$loginname=$_POST[loginname];

echo "$loginname";

$result=mysql_query("insert into users (loginname) values ('$loginname')") or die (mysqli_error($result)); 



}


?>



<html>

<head>

<title>Agents Register</title>

</head>

<body>

                 

                     <table width="400" align="center">
                    <br> <form name="form" action="<?php echo"$PHP_SELF"; ?>" method="post">
                      

                         
                        <tr> 
                          <td width="35%">Loginname</td>
                          <td><input type="text" name="loginname" size="25"></td>
                        </tr>
                        
                         

                        <tr> 
                          <td align="center" colspan="2"><input type="submit" name="action" value="Submit"></td>
                        </tr>
                      </table>
                    </form>




          
</body>

</html>




 

 

 

Link to comment
Share on other sites

Now we're gettin somewhere....

 

you've got a table structure problem

apparently you're primary key in your table isn't incrementing...and it isnt even number based....which I don't think is possible, but it may be...never tried.

 

go find your primary key...set it to autoincrement....and check the datatype to make sure that it is INT or TINYINT of something along the lines of INT

Link to comment
Share on other sites

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.